-
Notifications
You must be signed in to change notification settings - Fork 19k
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
Merged
crazywoola
merged 5 commits into
langgenius:main
from
qiaofenlin:feat/support-external-trace-id-propagation
Jul 22, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
05985f3
feat(trace): support external trace id propagation
qiaofenlin 87ec1d5
Merge remote-tracking branch 'origin/main' into feat/support-external…
qiaofenlin 418dced
remove badsmell
qiaofenlin 7df1268
Update api/core/ops/opik_trace/opik_trace.py
qiaofenlin b5d47e6
docs: add and unify trace_id field docs for chat/workflow APIs (zh/en…
qiaofenlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import re | ||
| from collections.abc import Mapping | ||
| from typing import Any, Optional | ||
|
|
||
|
|
||
| def is_valid_trace_id(trace_id: str) -> bool: | ||
| """ | ||
| Check if the trace_id is valid. | ||
|
|
||
| Requirements: 1-128 characters, only letters, numbers, '-', and '_'. | ||
| """ | ||
| return bool(re.match(r"^[a-zA-Z0-9\-_]{1,128}$", trace_id)) | ||
|
|
||
|
|
||
| def get_external_trace_id(request: Any) -> Optional[str]: | ||
| """ | ||
| Retrieve the trace_id from the request. | ||
|
|
||
| Priority: header ('X-Trace-Id'), then parameters, then JSON body. Returns None if not provided or invalid. | ||
| """ | ||
| trace_id = request.headers.get("X-Trace-Id") | ||
| if not trace_id: | ||
| trace_id = request.args.get("trace_id") | ||
| if not trace_id and getattr(request, "is_json", False): | ||
| json_data = getattr(request, "json", None) | ||
| if json_data: | ||
| trace_id = json_data.get("trace_id") | ||
| if isinstance(trace_id, str) and is_valid_trace_id(trace_id): | ||
| return trace_id | ||
| return None | ||
|
|
||
|
|
||
| def extract_external_trace_id_from_args(args: Mapping[str, Any]) -> dict: | ||
| """ | ||
| Extract 'external_trace_id' from args. | ||
|
|
||
| Returns a dict suitable for use in extras. Returns an empty dict if not found. | ||
| """ | ||
| trace_id = args.get("external_trace_id") | ||
| if trace_id: | ||
| return {"external_trace_id": trace_id} | ||
| return {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.