mirror of
https://github.com/langgenius/dify.git
synced 2026-03-01 12:55:13 +00:00
Add computed property to BaseTraceInfo that provides intelligent fallback: 1. External trace_id (from X-Trace-Id header) 2. workflow_run_id (for workflow-related traces) 3. message_id (as final fallback) This ensures attribute dify.trace_id always matches log-level trace_id, eliminating inconsistencies where attribute was null but log-level had value. Changes: - Add resolved_trace_id property to BaseTraceInfo (trace_entity.py) - Replace 4 direct trace_id attribute assignments with resolved_trace_id - Add trace_id_source parameter to 5 emit_metric_only_event calls Fixes trace_id inconsistency found in MESSAGE_RUN, TOOL_EXECUTION, MODERATION_CHECK, SUGGESTED_QUESTION_GENERATION, GENERATE_NAME_EXECUTION, DATASET_RETRIEVAL, and PROMPT_GENERATION_EXECUTION events. All 78 telemetry tests passing.