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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mrasu
Copy link

@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.5%. Comparing base (cd754a6) to head (0486b17).

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #5892   +/-   ##
=====================================
  Coverage   84.5%   84.5%           
=====================================
  Files        272     272           
  Lines      22840   22843    +3     
=====================================
+ Hits       19313   19317    +4     
+ Misses      3178    3177    -1     
  Partials     349     349           

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).

Co-authored-by: Tyler Yahn <[email protected]>
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