Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

test: more caplog (#38452)

Asuka Minatoa278d2174165
diff --git a/api/tests/unit_tests/enterprise/telemetry/test_enterprise_trace.py b/api/tests/unit_tests/enterprise/telemetry/test_enterprise_trace.py
index 24c905c75c2..29ddf73e24d 100644
--- a/api/tests/unit_tests/enterprise/telemetry/test_enterprise_trace.py
+++ b/api/tests/unit_tests/enterprise/telemetry/test_enterprise_trace.py
@@ -3,8 +3,9 @@
from __future__ import annotations
import json
+import logging
from datetime import UTC, datetime
-from typing import Any
+from typing import Any, cast
from unittest.mock import MagicMock, patch
import pytest
@@ -475,13 +476,24 @@ class TestWorkflowTrace:
assert span_call[1]["start_time"] == _T0
assert span_call[1]["end_time"] == _T1
- def test_emits_companion_log_with_event_name(self, trace_handler: EnterpriseOtelTrace, mock_exporter):
- with patch("enterprise.telemetry.enterprise_trace.emit_telemetry_log") as mock_log:
+ def test_emits_companion_log_with_event_name(
+ self,
+ trace_handler: EnterpriseOtelTrace,
+ caplog: pytest.LogCaptureFixture,
+ ):
+ with caplog.at_level(logging.INFO, logger="dify.telemetry"):
trace_handler._workflow_trace(make_workflow_info())
- mock_log.assert_called_once()
- assert mock_log.call_args[1]["event_name"] == EnterpriseTelemetryEvent.WORKFLOW_RUN
- assert mock_log.call_args[1]["tenant_id"] == "tenant-abc"
+ records = [record for record in caplog.records if record.name == "dify.telemetry"]
+
+ assert len(records) == 1
+ record = records[0]
+
+ attrs = cast(dict[str, Any], record.__dict__["attributes"])
+
+ assert attrs["dify.event.name"] == EnterpriseTelemetryEvent.WORKFLOW_RUN
+ assert attrs["dify.event.signal"] == "span_detail"
+ assert record.__dict__["tenant_id"] == "tenant-abc"
def test_companion_log_includes_content_when_enabled(self, trace_handler: EnterpriseOtelTrace, mock_exporter):
mock_exporter.include_content = True