fix(tracing): avoid crash on non-hex trace_context IDs#1737
Open
wei-juncheng wants to merge 1 commit into
Open
fix(tracing): avoid crash on non-hex trace_context IDs#1737wei-juncheng wants to merge 1 commit into
wei-juncheng wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
When a
trace_contextis passed with atrace_id(orparent_span_id) that is notparseable as hexadecimal,
_create_remote_parent_spanraisedValueError: invalid literal for int() with base 16and the observation failed tostart — even though the preceding log line claimed the ID would be ignored.
The root cause is that the validity warning and the actual conversion were decoupled:
So any invalid ID hit one of two broken paths:
"my-trace-123") →int(trace_id, 16)throws, crashing span creation.the ID is used, but the log falsely says it was "ignored".
This PR makes the conversion authoritative:
int(..., 16)intry/except (ValueError, TypeError).RandomIdGeneratoronly when the ID is genuinely unparseable.parent_span_idwith the same behavior.CallbackHandlerdocstring example to use a valid 32-character lowercase hex trace ID.Type of change
Verification
List the main commands you ran:
Added regression coverage for non-hex trace_id, non-hex parent_span_id, and parseable non-standard trace_id behavior.
Also updated the LangChain callback docstring example so it no longer suggests a non-hex custom trace ID.
Checklist
code_review.md..env.templateif needed.Greptile Summary
Fixes a crash in
_create_remote_parent_spanwhere non-hexadecimaltrace_idorparent_span_idvalues caused an unhandledValueErrorfromint(..., 16)even though the preceding warning log claimed the ID would be ignored. The fix wraps both conversions intry/except (ValueError, TypeError)and falls back toRandomIdGeneratoronly for genuinely unparseable values, while preserving (and correctly warning about) parseable-but-non-standard IDs.langfuse/_client/client.py:_create_remote_parent_spannow catches parse failures for bothtrace_idandparent_span_id, falling back to randomly-generated IDs and emitting accurate warning messages.tests/unit/test_otel.py: Three regression tests added covering non-hex trace ID, non-hex parent span ID, and parseable non-standard trace ID scenarios.langfuse/langchain/CallbackHandler.py: The docstring update promised in the PR description (replacing"my-trace-id"with a valid 32-char hex example) was not included in the diff.Confidence Score: 4/5
The client.py fix is correct and well-tested; the only gap is that the LangChain CallbackHandler docstring still shows a non-hex example, which the PR description explicitly said would be updated.
The two-file change is a targeted, straightforward bug fix with solid regression tests. The CallbackHandler.py docstring at line 167 still uses "my-trace-id", meaning users who copy that example will now hit the new warning path and get a random trace ID instead — the exact misbehavior this PR was meant to prevent for that audience.
langfuse/langchain/CallbackHandler.py — the docstring example at line 167 was not updated as described.
Reviews (1): Last reviewed commit: "fix(tracing): avoid crash on non-hex tra..." | Re-trigger Greptile