Type-check trace_context.rb (remove Steepfile ignore) - #6125
Conversation
Removes the Steepfile ignore for the W3C trace-context propagator and resolves all resulting steep errors: - Declare @fetcher/@traceparent_key/@tracestate_key in the RBS. - Declare the Distributed constants TAG_DD_PARENT_ID/DD_PARENT_ID_DEFAULT/TID/ TAG_TID in metadata/ext.rbs. - Guard the extract_traceparent tuple before destructuring so span/trace ids and flags are non-nil Integer. - Guard build_traceparent when digest.trace_id is nil (Integer? from #6124). - Normalize extract_tracestate to always return the 6-tuple. - Annotate the extract_datadog_fields accumulators and narrow t.-tag key/value. Behavior refinements (all specs pass): a malformed `t.` tag with no value is skipped instead of raising and discarding the whole tracestate; a digest with nil trace_id produces no traceparent header without logging an error.
BenchmarksBenchmark execution time: 2026-07-29 22:02:05 Comparing candidate commit 789fa03 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 48 metrics, 1 unstable metrics.
|
What does this PR do?
Removes the
Steepfileignore forlib/datadog/tracing/distributed/trace_context.rb(the W3C trace-context propagator) and resolves all 32 resulting steep errors so the
file is type-checked.
rake steep:checkis clean.Stacked on #6124 (branch
type-trace-span-id): that PR typesTraceDigest#trace_idas
Integer?, which is what forces the one id-related fix here(
build_traceparentguarding a niltrace_id).Signature changes:
@fetcher/@traceparent_key/@tracestate_keyand concreteinitializeparam types intrace_context.rbs.DistributedconstantsTAG_DD_PARENT_ID,DD_PARENT_ID_DEFAULT,TID,TAG_TIDinsig/datadog/tracing/metadata/ext.rbs(present in the.rb,missing from the
.rbs).build_traceparentreturnsString?;extract_tracestatereturns the 6-tupleuniformly (drops the
String |alternative).Code changes (type-narrowing; no behavior change for well-formed input):
extract_traceparenttuple before destructuring sotrace_id/parent_id/sampled/trace_flagsare non-nilInteger.version[0]/version[1]into locals with a nil check (guaranteednon-nil by the preceding
version.size == 2).extract_tracestatereturns[tracestate, nil, nil, nil, nil, nil]instead of abare
Stringwhen there is nodd=entry (destructures identically at the call site).extract_datadog_fieldsaccumulators and narrow thet.-tagkey/value.Two behavior refinements (covered by the existing 478 distributed specs, all green):
t.tracestate tag with no value is skipped instead of raising anddiscarding the entire tracestate for that propagator.
trace_idproduces notraceparentheader, without logging anerror (previously it raised and was swallowed upstream — same header output).
Motivation:
trace_context.rbwas ignored by steep purely due to accumulated type debt; thesignatures were otherwise already written. Un-ignoring it removes a checking gap on a
security/correctness-sensitive propagator.
Change log entry
None.
Additional Notes:
Signature/type-checking change plus small type-narrowing refactors. No public API change.
How to test the change?
bundle exec rake steep:check(clean) andbundle exec rspec spec/datadog/tracing/distributed/(478 examples, 0 failures, 1 pre-existing pending).