Skip to content

Commit

Permalink
w3c: ensure tracecontext headers always take precedence for conflicti…
Browse files Browse the repository at this point in the history
…ng spans

fix condition

Update ext/distributed_tracing_headers.c
  • Loading branch information
mabdinur committed May 20, 2024
1 parent 48190be commit cc73685
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ext/distributed_tracing_headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,18 @@ ddtrace_distributed_tracing_result ddtrace_read_distributed_tracing_ids(ddtrace_
zend_hash_destroy(&result.tracestate_unknown_dd_keys);
result.tracestate_unknown_dd_keys = new_result.tracestate_unknown_dd_keys;
zend_hash_init(&new_result.tracestate_unknown_dd_keys, 0, NULL, NULL, 0);
if (result.parent_id != new_result.parent_id) {
// The span id from tracecontext takes precendence over all other headers
result.parent_id = new_result.parent_id;
// set last datadog span_id tag
zval lp_id;
ddtrace_distributed_tracing_result result_dd = dd_init_empty_result();
if (lp_id = zend_hash_index_find(new_result.propagated_tags, ZEND_STRL("_dd.parent_id")) && lp_id != ZEND_STRL("0000000000000000")) {
zend_hash_str_update(result.propagated_tags, ZEND_STRL("_dd.parent_id"), &lp_id);
} else if (result_dd = ddtrace_read_distributed_tracing_ids_datadog(read_header, data) && result_dd.parent_id != 0) {
zend_hash_str_update(result.propagated_tags, ZEND_STRL("_dd.parent_id"), ZEND_STRL(sprintf("%016" PRIx64, result_dd.parent_id)));
}
}
}
}

Expand Down

0 comments on commit cc73685

Please sign in to comment.