mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-28 03:57:09 +02:00
Allow additional context to be added when WithHeaders is used in OTLP gRPC traces exporter (#5915)
Fix https://github.com/open-telemetry/opentelemetry-go/issues/5904
This commit is contained in:
parent
3429e15b9a
commit
30c4a9a330
@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
|
||||
- `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5892)
|
||||
- `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5911)
|
||||
- `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5915)
|
||||
|
||||
<!-- Released section -->
|
||||
<!-- Don't change this section unless doing release -->
|
||||
|
@ -229,7 +229,12 @@ func (c *client) exportContext(parent context.Context) (context.Context, context
|
||||
}
|
||||
|
||||
if c.metadata.Len() > 0 {
|
||||
ctx = metadata.NewOutgoingContext(ctx, c.metadata)
|
||||
md := c.metadata
|
||||
if outMD, ok := metadata.FromOutgoingContext(ctx); ok {
|
||||
md = metadata.Join(md, outMD)
|
||||
}
|
||||
|
||||
ctx = metadata.NewOutgoingContext(ctx, md)
|
||||
}
|
||||
|
||||
// Unify the client stopCtx with the parent.
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"google.golang.org/grpc/backoff"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/encoding/gzip"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
@ -216,6 +217,8 @@ func TestNewWithHeaders(t *testing.T) {
|
||||
t.Cleanup(func() { require.NoError(t, mc.stop()) })
|
||||
|
||||
ctx := context.Background()
|
||||
additionalKey := "additional-custom-header"
|
||||
ctx = metadata.AppendToOutgoingContext(ctx, additionalKey, "additional-value")
|
||||
exp := newGRPCExporter(t, ctx, mc.endpoint,
|
||||
otlptracegrpc.WithHeaders(map[string]string{"header1": "value1"}))
|
||||
t.Cleanup(func() { require.NoError(t, exp.Shutdown(ctx)) })
|
||||
@ -224,6 +227,7 @@ func TestNewWithHeaders(t *testing.T) {
|
||||
headers := mc.getHeaders()
|
||||
require.Regexp(t, "OTel OTLP Exporter Go/1\\..*", headers.Get("user-agent"))
|
||||
require.Len(t, headers.Get("header1"), 1)
|
||||
require.Len(t, headers.Get(additionalKey), 1)
|
||||
assert.Equal(t, "value1", headers.Get("header1")[0])
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user