Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otlpmetricgrpc: Keep metadata for gRPC in context #5892

Merged
merged 4 commits into from
Oct 21, 2024

Conversation

mrasu
Copy link
Contributor

@mrasu mrasu commented Oct 17, 2024

When using otlpmetricgrpc, we can inject metadata dynamically with metadata.AppendToOutgoingContext. However when specifying headers with WithHeaders, it becomes impossible to add additional metadata.

For example, the code below sends additional metadata in the header

exp := otlpmetricgrpc.New(context.Background())

ctx := context.Background()
ctx = metadata.AppendToOutgoingContext(ctx, "dynamic-key", "value")
exp.Export(ctx, &metricdata.ResourceMetrics{}))

But when using WithHeader like below, no additional metadata will be sent

exp := otlpmetricgrpc.New(context.Background(), otlpmetricgrpc.WithHeaders("custom-key", "value"))

ctx := context.Background()
ctx = metadata.AppendToOutgoingContext(ctx, "dynamic-key", "value")
exp.Export(ctx, &metricdata.ResourceMetrics{}))

To eliminate this inconsistency, keep the metadata in the context and send them in the header.

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.6%. Comparing base (bd88af9) to head (354ae01).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #5892     +/-   ##
=======================================
- Coverage   84.6%   84.6%   -0.1%     
=======================================
  Files        272     272             
  Lines      22861   22864      +3     
=======================================
+ Hits       19344   19346      +2     
- Misses      3172    3173      +1     
  Partials     345     345             

see 2 files with indirect coverage changes

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@dmathieu dmathieu left a comment

Choose a reason for hiding this comment

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

We should do the same for the trace and log signals (in other PRs).

mrasu and others added 2 commits October 18, 2024 00:41
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
@MrAlias MrAlias merged commit bf6a7e1 into open-telemetry:main Oct 21, 2024
32 checks passed
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