-
Notifications
You must be signed in to change notification settings - Fork 18.9k
feat(trace): support external trace id propagation #22623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(trace): support external trace id propagation #22623
Conversation
84060fc to
05985f3
Compare
…-trace-id-propagation
4a5b780 to
418dced
Compare
There was a problem hiding this comment.
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 introduces support for external trace ID propagation in Dify's workflow and chatflow systems, enabling enterprise-grade observability by allowing external tracing systems to pass trace IDs through the request lifecycle. The implementation extracts trace IDs from HTTP headers, query parameters, or JSON body with priority order, and propagates them through all internal tracing components.
Key changes:
- Added trace ID extraction and validation logic with priority-based selection
- Updated workflow and chatflow generators to accept and propagate external trace IDs
- Modified all tracing implementations to use external trace IDs when available
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
web/app/components/base/chat/chat/question.tsx |
CSS class reordering for styling consistency |
api/core/helper/trace_id_helper.py |
New utility module for trace ID validation and extraction |
api/tests/unit_tests/core/helper/test_trace_id_helper.py |
Comprehensive test coverage for trace ID helper functions |
api/controllers/service_api/app/workflow.py |
Workflow endpoint integration for external trace ID extraction |
api/controllers/service_api/app/completion.py |
Completion endpoint integration for external trace ID extraction |
api/core/app/apps/workflow/app_generator.py |
Workflow app generator updated to handle external trace IDs |
api/core/app/apps/advanced_chat/app_generator.py |
Advanced chat generator updated to handle external trace IDs |
| Multiple tracing files | Updated all tracing implementations to use external trace IDs |
Co-authored-by: Copilot <[email protected]>
9c4028c to
8d3f2ae
Compare
6167498 to
b5d47e6
Compare
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
@qiaofenlin curl -X POST 'http://localhost/v1/chat-messages' |
Important
Fixes [#<issue 22114>](https://github.com/langgenius/dify/issues/22114).Summary
/v1/chat-messagesendpoint./v1/workflows/runendpoint.The first valid trace id found in this order will be used throughout the request lifecycle.
Motivation
trace_ids (via HTTP header or request parameter) throughout its internal workflow. When an externaltrace_idis not provided, Dify will gracefully generate a new one to ensure trace continuity.trace_idwith unique business system identifiers, Dify further enables comprehensive full-link tracing from a business perspective, allowing for precise correlation of requests and logs across the entire business chain and significantly improving both troubleshooting and business-level analytics.Fixes #22098
Screenshots
External trace_id with no backend tracing configured
Checklist
dev/reformat(backend) andcd web && npx lint-staged(frontend) to appease the lint gods