Skip to content

fix(otel): fix metadataSupplier Get/Set type mismatch breaking trace propagation#3433

Open
Aias00 wants to merge 4 commits into
apache:developfrom
Aias00:worktree-fix-otel-trace-type-mismatch
Open

fix(otel): fix metadataSupplier Get/Set type mismatch breaking trace propagation#3433
Aias00 wants to merge 4 commits into
apache:developfrom
Aias00:worktree-fix-otel-trace-type-mismatch

Conversation

@Aias00

@Aias00 Aias00 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Problem

metadataSupplier in filter/otel/trace/attachment.go has a type mismatch between Get and Set:

  • Set stores values as string: s.metadata[key] = value
  • Get reads values as []string: s.metadata[key].([]string)

When the OTel propagator calls Inject (which uses Set) followed by Extract (which uses Get), the type assertion in Get fails and returns an empty string. This breaks trace context propagation — traceparent and other W3C trace headers are silently lost.

This is also a partial root cause of #3240 (traceparent being broken by triple_invoker).

Fix

Set — store []string{value} instead of string

This aligns with how triple's generateAttachments stores http.Header values (as []string), which is the data source on the Extract (server) side.

Get — add defensive string type handling

In addition to []string, Get now also handles plain string values. This matches the pattern used by RPCInvocation.GetAttachment and provides robustness against externally-set string values.

Test Coverage

  • Added string value (defensive read) test case — verifies Get reads string type
  • Added non-string non-slice value test case — verifies safe fallback
  • Added Test_metadataSupplier_SetGetRoundTrip — the core bug scenario: Set then Get must succeed, and stored type must be []string

🤖 Generated with Claude Code

…propagation

Set stored values as string but Get expected []string, causing type
assertion failure when OTel propagator Inject followed by Extract.
Trace context (traceparent etc.) was lost during propagation.

- Set: store []string{value} instead of string, consistent with
  triple's generateAttachments which stores http.Header values as
  []string
- Get: add defensive string type handling alongside []string, matching
  RPCInvocation.GetAttachment's pattern for robustness

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 17, 2026 06:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes metadataSupplier so Set() stores values in the same shape that Get() expects (and that upstream attachment generation produces), preventing trace context values (e.g., traceparent) from being lost during round-trip usage.

Changes:

  • Update metadataSupplier.Get to handle both []string and string values safely.
  • Update metadataSupplier.Set to store values as []string{value}.
  • Expand unit tests to cover additional metadata value types and a Set/Get round-trip.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
filter/otel/trace/attachment.go Aligns Set() storage format with Get() expectations; adds defensive reads for string values.
filter/otel/trace/attachment_test.go Adds coverage for slice/string/non-string values and validates Set/Get round-trip behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter

codecov-commenter commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.57%. Comparing base (60d1c2a) to head (42893f8).
⚠️ Report is 859 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3433      +/-   ##
===========================================
+ Coverage    46.76%   53.57%   +6.80%     
===========================================
  Files          295      493     +198     
  Lines        17172    38392   +21220     
===========================================
+ Hits          8031    20569   +12538     
- Misses        8287    16171    +7884     
- Partials       854     1652     +798     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants