File tree 3 files changed +16
-1
lines changed
3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
- ` opentelemetry-distro ` & ` opentelemetry-sdk ` Moved Auto Instrumentation Configurator code to SDK
9
9
to let distros use its default implementation
10
10
([ #1937 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/1937 ) )
11
+ - Add Trace ID validation to meet [ TraceID spec] ( https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/overview.md#spancontext ) ([ #1992 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/1992 ) )
11
12
12
13
## [ 0.23.1] ( https://github.com/open-telemetry/opentelemetry-python/pull/1987 ) - 2021-07-26
13
14
Original file line number Diff line number Diff line change @@ -389,6 +389,7 @@ def values(self) -> typing.ValuesView[str]:
389
389
390
390
391
391
DEFAULT_TRACE_STATE = TraceState .get_default ()
392
+ _TRACE_ID_HEX_LENGTH = 2 ** 128 - 1
392
393
393
394
394
395
class SpanContext (
@@ -420,7 +421,11 @@ def __new__(
420
421
if trace_state is None :
421
422
trace_state = DEFAULT_TRACE_STATE
422
423
423
- is_valid = trace_id != INVALID_TRACE_ID and span_id != INVALID_SPAN_ID
424
+ is_valid = (
425
+ trace_id != INVALID_TRACE_ID
426
+ and span_id != INVALID_SPAN_ID
427
+ and trace_id < _TRACE_ID_HEX_LENGTH
428
+ )
424
429
425
430
return tuple .__new__ (
426
431
cls ,
Original file line number Diff line number Diff line change @@ -34,3 +34,12 @@ def test_span_context_pickle(self):
34
34
pickle_sc = pickle .loads (pickle .dumps (sc ))
35
35
self .assertEqual (sc .trace_id , pickle_sc .trace_id )
36
36
self .assertEqual (sc .span_id , pickle_sc .span_id )
37
+
38
+ invalid_sc = trace .SpanContext (
39
+ 9999999999999999999999999999999999999999999999999999999999999999999999999999 ,
40
+ 9 ,
41
+ is_remote = False ,
42
+ trace_flags = trace .DEFAULT_TRACE_OPTIONS ,
43
+ trace_state = trace .DEFAULT_TRACE_STATE ,
44
+ )
45
+ self .assertFalse (invalid_sc .is_valid )
You can’t perform that action at this time.
0 commit comments