Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
otlpmetricgrpc: Keep metadata for gRPC in context (#5892)
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 ```go 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 ```go 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. --------- Co-authored-by: Tyler Yahn <[email protected]>
- Loading branch information