Skip to content

Commit edc24ae

Browse files
committed
Zero pad the tid and exclude it from OTel tracestate
As per our specification. Signed-off-by: Bob Weinand <[email protected]>
1 parent 05eaba2 commit edc24ae

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

ext/handlers_http.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ static inline zend_string *ddtrace_format_tracestate(zend_string *tracestate, ze
4040
if (last_separator) {
4141
next_equals = ':';
4242
cur += strlen("_dd.p");
43+
// drop the tid from otel tracestate
44+
if (cur + strlen(".tid=") + 16 /* 16 byte tid */ <= end && memcmp(cur, ".tid=", strlen(".tid=")) == 0) {
45+
cur += strlen(".tid=") + 16;
46+
continue;
47+
}
4348
smart_str_appendc(&str, 't');
4449
}
4550
signed char chr = *cur;

ext/tracer_tag_propagation/tracer_tag_propagation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ zend_string *ddtrace_format_propagated_tags(zend_array *propagated, zend_array *
122122

123123
ddtrace_trace_id trace_id = ddtrace_peek_trace_id();
124124
if (trace_id.high) {
125-
smart_str_append_printf(&taglist, "_dd.p.tid=%" PRIx64, trace_id.high);
125+
smart_str_append_printf(&taglist, "_dd.p.tid=%016" PRIx64, trace_id.high);
126126
}
127127

128128
zend_string *tagname;

tests/ext/distributed_tracestate_consumption.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ array(2) {
2828
["traceparent"]=>
2929
string(55) "00-%sc151df7d6ee5e2d6-a3978fb9b92502a8-01"
3030
["tracestate"]=>
31-
string(75) "dd=t.tid:%s;t.dm:-1;t.congo:t61rcWkgMzE,rojo=00f067aa0ba902b7"
31+
string(52) "dd=t.dm:-1;t.congo:t61rcWkgMzE,rojo=00f067aa0ba902b7"
3232
}

tests/ext/integrations/curl/distributed_tracing_curl_drop_dm.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ddtrace.request_init_hook={PWD}/distributed_tracing_curl_inject.inc
88
--ENV--
99
DD_TRACE_DEBUG=1
1010
DD_TRACE_GENERATE_ROOT_SPAN=0
11-
HTTP_TRACEPARENT=00-12345678901234567890123456789012-1234567890123456-00
11+
HTTP_TRACEPARENT=00-00000012345678907890123456789012-1234567890123456-00
1212
HTTP_TRACESTATE=foo=1,dd=s:1;t.dm:-0;t.usr.id:baz64~~;t.url:http://localhost
1313
DD_PROPAGATION_STYLE=tracecontext,Datadog
1414
--FILE--
@@ -43,10 +43,10 @@ echo 'Done.' . PHP_EOL;
4343

4444
?>
4545
--EXPECTF--
46-
traceparent: 00-12345678901234567890123456789012-1234567890123456-00
47-
tracestate: dd=t.tid:1234567890123456;t.usr.id:baz64~~;t.url:http://localhost,foo=1
46+
traceparent: 00-00000012345678907890123456789012-1234567890123456-00
47+
tracestate: dd=t.usr.id:baz64~~;t.url:http://localhost,foo=1
4848
x-datadog-parent-id: 1311768467284833366
49-
x-datadog-tags: _dd.p.tid=1234567890123456,_dd.p.usr.id=baz64==,_dd.p.url=http://localhost
49+
x-datadog-tags: _dd.p.tid=0000001234567890,_dd.p.usr.id=baz64==,_dd.p.url=http://localhost
5050
x-datadog-trace-id: 8687463697196027922
5151
bool(false)
5252
Done.

tests/ext/integrations/curl/distributed_tracing_curl_invalid_tags.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ echo 'Done.' . PHP_EOL;
4444
--EXPECTF--
4545
b3: %s248869c998246a2e-248869c998246a2e-1
4646
traceparent: 00-%s248869c998246a2e-248869c998246a2e-01
47-
tracestate: dd=o:_______~_: ;t.tid:%s;t.escaped:_~_: ;t.dm:-0
47+
tracestate: dd=o:_______~_: ;t.escaped:_~_: ;t.dm:-0
4848
x-datadog-origin: ∂~,=;:
4949
x-datadog-tags: _dd.p.tid=%s,_dd.p.escaped=_=;: ,_dd.p.dm=-0
5050
bool(false)

tests/ext/integrations/curl/distributed_tracing_curl_tracestate.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ echo 'Done.' . PHP_EOL;
4545
--EXPECTF--
4646
b3: 12345678901234567890123456789012-6543210987654321-d
4747
traceparent: 00-12345678901234567890123456789012-6543210987654321-01
48-
tracestate: dd=o:phpt-test;s:2;t.tid:1234567890123456;t.test:qvalue;t.dm:-0;unknown1:val;unknown2:1,foo=bar:;=,baz=qux
48+
tracestate: dd=o:phpt-test;s:2;t.test:qvalue;t.dm:-0;unknown1:val;unknown2:1,foo=bar:;=,baz=qux
4949
x-datadog-origin: phpt-test
5050
x-datadog-tags: _dd.p.tid=1234567890123456,_dd.p.test=qvalue,_dd.p.dm=-0
5151
bool(false)

0 commit comments

Comments
 (0)