Skip to content

fix: add missing metrics back and enhance typing - #40935

Open
wylswz wants to merge 23 commits into
langgenius:mainfrom
wylswz:refactor/telemetry-typed-events
Open

fix: add missing metrics back and enhance typing#40935
wylswz wants to merge 23 commits into
langgenius:mainfrom
wylswz:refactor/telemetry-typed-events

Conversation

@wylswz

@wylswz wylswz commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

  • dify_feedback_total
  • dify_prompt_generation_duration_seconds
  • dify_message_time_to_first_token_seconds

resolves ESQ1-209

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Aug 18, 2026
@wylswz
wylswz marked this pull request as draft August 18, 2026 10:18
@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-08-20 03:27:21.002725185 +0000
+++ /tmp/pyrefly_pr.txt	2026-08-20 03:27:07.538582645 +0000
@@ -1834,8 +1834,6 @@
   --> tests/unit_tests/configs/test_dify_config.py:38:32
 ERROR Unpacked keyword argument `object` is not assignable to parameter `ENTERPRISE_INCLUDE_CONTENT` with type `Decimal | bool | float | int | str` in function `_IsolatedDifyConfig.__init__` [bad-argument-type]
   --> tests/unit_tests/configs/test_dify_config.py:38:32
-ERROR Unpacked keyword argument `object` is not assignable to parameter `ENTERPRISE_SERVICE_NAME` with type `bytearray | bytes | str` in function `_IsolatedDifyConfig.__init__` [bad-argument-type]
-  --> tests/unit_tests/configs/test_dify_config.py:38:32
 ERROR Unpacked keyword argument `object` is not assignable to parameter `ENTERPRISE_OTEL_SAMPLING_RATE` with type `Decimal | bool | bytes | float | int | str` in function `_IsolatedDifyConfig.__init__` [bad-argument-type]
   --> tests/unit_tests/configs/test_dify_config.py:38:32
 ERROR Unpacked keyword argument `object` is not assignable to parameter `WEBAPP_PUBLIC_ACCESS_ENABLED` with type `Decimal | bool | float | int | str` in function `_IsolatedDifyConfig.__init__` [bad-argument-type]
@@ -4603,15 +4601,33 @@
 ERROR `SimpleNamespace` is not assignable to attribute `_application_generate_entity` with type `AdvancedChatAppGenerateEntity` [bad-assignment]
    --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:109:45
 ERROR Argument `SimpleNamespace` is not assignable to parameter `application_generate_entity` with type `AdvancedChatAppGenerateEntity` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
-   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:176:37
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:178:37
+ERROR Argument `SimpleNamespace` is not assignable to parameter `queue_manager` with type `AppQueueManager` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:180:23
+ERROR Argument `SimpleNamespace` is not assignable to parameter `draft_var_saver_factory` with type `DraftVariableSaverFactory` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:186:33
+ERROR Argument `SimpleNamespace` is not assignable to parameter `application_generate_entity` with type `AdvancedChatAppGenerateEntity` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:250:37
+ERROR Argument `SimpleNamespace` is not assignable to parameter `queue_manager` with type `AppQueueManager` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:252:23
+ERROR Argument `SimpleNamespace` is not assignable to parameter `draft_var_saver_factory` with type `DraftVariableSaverFactory` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:258:33
+ERROR Argument `SimpleNamespace` is not assignable to parameter `application_generate_entity` with type `AdvancedChatAppGenerateEntity` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:327:37
+ERROR Argument `SimpleNamespace` is not assignable to parameter `queue_manager` with type `AppQueueManager` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:329:23
+ERROR Argument `SimpleNamespace` is not assignable to parameter `draft_var_saver_factory` with type `DraftVariableSaverFactory` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:335:33
+ERROR Argument `SimpleNamespace` is not assignable to parameter `application_generate_entity` with type `AdvancedChatAppGenerateEntity` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:394:37
 ERROR Argument `SimpleNamespace` is not assignable to parameter `queue_manager` with type `AppQueueManager` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
-   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:178:23
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:396:23
 ERROR Argument `SimpleNamespace` is not assignable to parameter `draft_var_saver_factory` with type `DraftVariableSaverFactory` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
-   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:184:33
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:402:33
 ERROR `SimpleNamespace` is not assignable to attribute `_application_generate_entity` with type `AdvancedChatAppGenerateEntity` [bad-assignment]
-   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:218:45
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:434:45
 ERROR `SimpleNamespace` is not assignable to attribute `_application_generate_entity` with type `AdvancedChatAppGenerateEntity` [bad-assignment]
-   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:240:45
+   --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py:456:45
 ERROR Argument `SimpleNamespace` is not assignable to parameter `queue_manager` with type `AppQueueManager` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
    --> tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline_core.py:104:23
 ERROR Argument `(**kwargs: Unknown) -> None` is not assignable to parameter `draft_var_saver_factory` with type `DraftVariableSaverFactory` in function `core.app.apps.advanced_chat.generate_task_pipeline.AdvancedChatAppGenerateTaskPipeline.__init__` [bad-argument-type]
@@ -7951,17 +7967,55 @@
 ERROR Argument `TestWorkflowEntryNodeLayers.test_run_node_with_layers_reports_errors.FakeNode` is not assignable to parameter `node` with type `Node[Unknown]` in function `core.workflow.workflow_entry.WorkflowEntry._run_node_with_layers` [bad-argument-type]
    --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:818:73
 ERROR Missing argument `case` in function `enterprise.telemetry.contracts.TelemetryEnvelope.__init__` [missing-argument]
-   --> tests/unit_tests/enterprise/telemetry/test_contracts.py:111:30
+   --> tests/unit_tests/enterprise/telemetry/test_contracts.py:110:30
 ERROR Missing argument `tenant_id` in function `enterprise.telemetry.contracts.TelemetryEnvelope.__init__` [missing-argument]
-   --> tests/unit_tests/enterprise/telemetry/test_contracts.py:120:30
+   --> tests/unit_tests/enterprise/telemetry/test_contracts.py:119:30
 ERROR Missing argument `event_id` in function `enterprise.telemetry.contracts.TelemetryEnvelope.__init__` [missing-argument]
-   --> tests/unit_tests/enterprise/telemetry/test_contracts.py:129:30
+   --> tests/unit_tests/enterprise/telemetry/test_contracts.py:128:30
 ERROR Missing argument `payload` in function `enterprise.telemetry.contracts.TelemetryEnvelope.__init__` [missing-argument]
-   --> tests/unit_tests/enterprise/telemetry/test_contracts.py:138:30
+   --> tests/unit_tests/enterprise/telemetry/test_contracts.py:137:30
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+  --> tests/unit_tests/enterprise/telemetry/test_exporter.py:37:24
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+  --> tests/unit_tests/enterprise/telemetry/test_exporter.py:60:24
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+  --> tests/unit_tests/enterprise/telemetry/test_exporter.py:84:24
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:111:28
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:140:24
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:164:24
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:188:24
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:213:24
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:236:24
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:260:24
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:346:35
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:356:35
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:371:24
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:383:24
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:407:39
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:584:35
 ERROR Argument `dict[str, str]` is not assignable to parameter `labels` with type `dict[str, AttributeValue]` in function `enterprise.telemetry.exporter.EnterpriseExporter.increment_counter` [bad-argument-type]
-   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:582:71
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:590:71
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:599:35
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:617:35
 ERROR Argument `dict[str, str]` is not assignable to parameter `labels` with type `dict[str, AttributeValue]` in function `enterprise.telemetry.exporter.EnterpriseExporter.record_histogram` [bad-argument-type]
-   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:615:85
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:623:85
+ERROR Argument `SimpleNamespace` is not assignable to parameter `config` with type `DifyConfig` in function `enterprise.telemetry.exporter.EnterpriseExporter.__init__` [bad-argument-type]
+   --> tests/unit_tests/enterprise/telemetry/test_exporter.py:632:35
 ERROR Missing argument `session` in function `events.event_handlers.update_app_dataset_join_when_app_model_config_updated.handle` [missing-argument]
    --> tests/unit_tests/events/test_app_event_signals.py:229:19
 ERROR Object of class `Events` has no attribute `request_start` [missing-attribute]

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 59.75% 59.74% -0.01%
Strict coverage 59.33% 59.32% -0.01%
Typed symbols 39,818 39,807 -11
Untyped symbols 27,010 27,013 +3
Modules 3176 3176 0

@wylswz
wylswz force-pushed the refactor/telemetry-typed-events branch from e868862 to 333c861 Compare August 18, 2026 11:01
@wylswz
wylswz force-pushed the refactor/telemetry-typed-events branch from 9fd7ec2 to 7d26b30 Compare August 18, 2026 11:25
@wylswz
wylswz marked this pull request as ready for review August 18, 2026 11:57
@wylswz
wylswz requested a lite review from Copilot August 18, 2026 11:57
@wylswz
wylswz requested a review from GareArc August 18, 2026 11:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the telemetry gateway to emit typed TelemetryEvent objects (instead of TelemetryCase + context/payload dicts) and restores/extends enterprise metrics for feedback, prompt generation duration, and message TTFT.

Changes:

  • Introduces a TelemetryEvent protocol plus concrete typed event classes and updates core.telemetry.gateway.emit() to route based on event metadata.
  • Adds new telemetry emission points for feedback creation and prompt-generation operations (including duration/status labeling).
  • Enqueues MESSAGE_TRACE for Advanced Chat message persistence to restore message-level trace/metrics coverage; updates/expands unit tests accordingly.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
api/tests/unit_tests/enterprise/telemetry/test_gateway.py Updates gateway tests to use typed event objects and validates event routing metadata.
api/tests/unit_tests/enterprise/telemetry/test_event_handlers.py Updates handler tests to patch the facade core.telemetry.emit and validate event objects.
api/tests/unit_tests/enterprise/telemetry/test_enterprise_trace.py Adds assertions for required labels/status on TTFT and prompt duration histograms.
api/tests/unit_tests/enterprise/telemetry/test_draft_trace.py Updates draft trace tests to assert typed event fields (trace_task_name).
api/tests/unit_tests/enterprise/telemetry/test_contracts.py Replaces routing-table tests with event-class metadata assertions.
api/tests/unit_tests/core/telemetry/test_gateway_integration.py Adjusts integration tests for new emit(event, ...) signature and typed events.
api/tests/unit_tests/core/telemetry/test_facade.py Updates facade tests to use concrete typed trace events.
api/tests/unit_tests/core/llm_generator/test_llm_generator.py Updates assertions around error propagation after generator refactor/telemetry emission.
api/tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline.py Updates pipeline test scaffolding for newly accessed fields (extras).
api/services/message_service.py Emits FeedbackCreatedEvent during feedback writes.
api/enterprise/telemetry/event_handlers.py Switches enterprise signal handlers to emit typed events via core.telemetry.
api/enterprise/telemetry/enterprise_trace.py Ensures prompt generation duration histogram labels include status.
api/enterprise/telemetry/draft_trace.py Emits DraftNodeExecutionTraceEvent instead of generic TelemetryEvent.
api/enterprise/telemetry/contracts.py Expands SignalType documentation to clarify TRACE vs METRIC_LOG semantics.
api/core/telemetry/gateway.py Removes case-routing tables; routes directly using event metadata.
api/core/telemetry/events.py Adds protocol + typed payloads and concrete event classes (app lifecycle, feedback, prompt generation, draft node execution).
api/core/telemetry/init.py Re-exports new typed telemetry surface and makes emit the gateway entrypoint.
api/core/llm_generator/llm_generator.py Adds prompt generation telemetry emission and threads app_id through generator entrypoints.
api/core/app/apps/advanced_chat/generate_task_pipeline.py Enqueues MESSAGE_TRACE on message save to restore message trace metrics (TTFT, etc.).
api/controllers/console/app/generator.py Passes flow_id as app_id into LLM generator methods for telemetry context.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread api/services/message_service.py
Comment thread api/core/llm_generator/llm_generator.py
@wylswz wylswz added this to the 1.17.0 milestone Aug 19, 2026
@wylswz
wylswz force-pushed the refactor/telemetry-typed-events branch from 4962168 to bc601e6 Compare August 19, 2026 02:40
@wylswz
wylswz force-pushed the refactor/telemetry-typed-events branch from 4661dcc to d1cf67f Compare August 19, 2026 05:56
@dosubot dosubot Bot removed the size:XL This PR changes 500-999 lines, ignoring generated files. label Aug 19, 2026
@dosubot dosubot Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Aug 19, 2026
@wylswz
wylswz force-pushed the refactor/telemetry-typed-events branch from 0298267 to a00345a Compare August 19, 2026 06:52
@wylswz
wylswz requested a lite review from Copilot August 19, 2026 06:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 29 out of 29 changed files in this pull request and generated no new comments.

Suppressed comments (3)

api/core/llm_generator/llm_generator.py:556

  • generate_rule_config() returns early on the initial InvokeError (prefix prompt generation), which skips _emit_prompt_generation(). That means prompt-generation telemetry won’t fire on this failure path, even though other paths now always emit.
                except InvokeError as e:
                    error = str(e)
                    error_step = "generate prefix prompt"
                    rule_config["error"] = f"Failed to {error_step}. Error: {error}"
                    return rule_config

api/services/message_service.py:226

  • create_feedback() emits FeedbackCreatedEvent for any non-null rating, including updates to an existing feedback record. This can inflate dify_feedback_total (and the event name implies it should represent creation only). Consider emitting only when a new MessageFeedback is created.
        session.commit()
        if rating:
            cls._emit_feedback_telemetry(
                app_model=app_model, message=message, user=user, rating=rating, content=content
            )

api/enterprise/telemetry/exporter.py:116

  • ENTERPRISE_OTLP_PROTOCOL is now used without normalization. Previously the exporter lowercased and defaulted the value; with the current code, values like GRPC (or an empty string) will silently fall back to the HTTP exporter path.
    def __init__(self, config: DifyConfig) -> None:
        endpoint: str = config.ENTERPRISE_OTLP_ENDPOINT
        headers_raw: str = config.ENTERPRISE_OTLP_HEADERS
        protocol: str = config.ENTERPRISE_OTLP_PROTOCOL
        service_name: str = config.APPLICATION_NAME
        sampling_rate: float = config.ENTERPRISE_OTEL_SAMPLING_RATE

@wylswz

wylswz commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

dify.node.execution and dify.workflow.run do not share the same parent trace, need a fix

@wylswz
wylswz force-pushed the refactor/telemetry-typed-events branch from e91f27c to 4cb4bc5 Compare August 19, 2026 08:17
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Aug 19, 2026
@wylswz
wylswz force-pushed the refactor/telemetry-typed-events branch from cb9b0d0 to 6509bf0 Compare August 19, 2026 08:25
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Aug 19, 2026
@wylswz
wylswz force-pushed the refactor/telemetry-typed-events branch from 4aaf250 to 09a1426 Compare August 19, 2026 08:55
@wylswz
wylswz force-pushed the refactor/telemetry-typed-events branch from 5a0d17c to 321088b Compare August 19, 2026 09:58
tenant_id, app_id, user_id = self._context_ids(workflow_info, metadata)

try:
with Session(db.engine) as session:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not using a repository here mean the feature won't support LogStore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched to repo

)
session.add_all(message_files)

trace_manager = self._application_generate_entity.trace_manager

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This emits on every save, including pause and each resumed completion. This duplicates message, token, and TTFT metrics. Emit once at terminal completion or make emissions idempotent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved trace emission to invoker's side.

@wylswz
wylswz requested a review from laipz8200 August 20, 2026 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants