-
Notifications
You must be signed in to change notification settings - Fork 55
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
fix: 16-bit hexadecimal formatting for XCTC span IDs #946
Conversation
if span_id_int > 0 and span_id_int < 2**64: | ||
span_id = f"{span_id_int:016x}" | ||
else: | ||
span_id = None |
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.
nit: maybe raise an exception here, since we already have the try/catch?
try:
span_id_int = int(span_id)
if span_id_int < 0 or span_id_int > 2**64:
raise ValueError("span_id outside valid range")
span_id = f"{span_id_int:016x}"
except ValueError:
span_id = None
|
||
# Convert the span ID to 16-bit hexadecimal instead of decimal | ||
if span_id is not None: | ||
try: |
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.
You have a lot of layers of nesting here... consider splitting this up into multiple smaller helper functions. For example:
xctc_trace_id, xctc_span_id, xctc_options = _parse_xct_header(header)
trace_id = _validate_and_normalize_xctc_trace_id(xctc_trace_id)
span_id = _validate_and_normalize_xctc_span_id(xctc_span_id)
sampled = _extract_should_sample_from_xctc_option(xctc_options)
if span_id_int > 0 and span_id_int < 2**64: | ||
span_id = f"{span_id_int:016x}" | ||
else: | ||
span_id = None |
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.
If parts of the header fail to validate, you may want to consider making it more obvious that this has happened. Consider some form of debug logging or other tracking if not propagated an error to the caller.
tests/unit/handlers/test__helpers.py
Outdated
for input_span in input_spans: | ||
expected_trace = "12345" | ||
input_span = "67890" | ||
expected_span = "10932".zfill(16) |
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.
Why is this the expected span when the input span is invalid? Shouldn't the expected span be None?
Fixes #942
Also updated link to comment for XCTC formatting, as that seems to have been moved prior.