Skip to content

Commit 54ddfb5

Browse files
committed
Change to simplify the Trace ID validation
1 parent 8ec5d80 commit 54ddfb5

File tree

1 file changed

+1
-21
lines changed
  • opentelemetry-api/src/opentelemetry/trace

1 file changed

+1
-21
lines changed

opentelemetry-api/src/opentelemetry/trace/span.py

+1-21
Original file line numberDiff line numberDiff line change
@@ -390,26 +390,6 @@ def values(self) -> typing.ValuesView[str]:
390390

391391
DEFAULT_TRACE_STATE = TraceState.get_default()
392392

393-
_TRACE_ID_BYTES = 16
394-
_TRACE_ID_HEX_LENGTH = 2 * _TRACE_ID_BYTES
395-
396-
397-
def _validate_trace_id(trace_id: int) -> bool:
398-
"""Validates a trace_id.
399-
400-
Args:
401-
trace_id: An int that is expected to corresponds to 16-bytes hexdecimal value
402-
403-
Returns:
404-
True if trace_id is valid, False otherwise.
405-
"""
406-
if not trace_id:
407-
return False
408-
if len(format(trace_id, "032x")) != _TRACE_ID_HEX_LENGTH:
409-
return False
410-
411-
return True
412-
413393

414394
class SpanContext(
415395
typing.Tuple[int, int, bool, "TraceFlags", "TraceState", bool]
@@ -443,7 +423,7 @@ def __new__(
443423
is_valid = (
444424
trace_id != INVALID_TRACE_ID
445425
and span_id != INVALID_SPAN_ID
446-
and _validate_trace_id(trace_id)
426+
and trace_id < 2 ** 128 - 1
447427
)
448428

449429
return tuple.__new__(

0 commit comments

Comments
 (0)