Skip to content

Commit

Permalink
Add baggage propagation test (#61)
Browse files Browse the repository at this point in the history
Adds a test to make sure that propagation of baggage works correctly 

Related: https://github.com/bufbuild/connect-opentelemetry-go/issues/55
  • Loading branch information
joshcarp committed Jan 18, 2023
1 parent 5cbb0ac commit 05f1961
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/metric/unit"
"go.opentelemetry.io/otel/propagation"
Expand Down Expand Up @@ -1276,6 +1277,41 @@ func TestStreamingHandlerNoTraceParent(t *testing.T) {
assert.Equal(t, int64(1), resp.Sum)
}

func TestPropagationBaggage(t *testing.T) {
t.Parallel()
propagator := propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{})
spanRecorder := tracetest.NewSpanRecorder()
traceProvider := trace.NewTracerProvider(trace.WithSpanProcessor(spanRecorder))
assertBaggage := connect.WithInterceptors(connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {
return func(ctx context.Context, request connect.AnyRequest) (connect.AnyResponse, error) {
assert.Equal(t, "foo=bar", request.Header().Get("Baggage"))
return next(ctx, request)
}
}))
client, _, _ := startServer(
[]connect.HandlerOption{
connect.WithInterceptors(
NewInterceptor(
WithPropagator(propagator),
WithTracerProvider(traceProvider),
WithTrustRemote()),
),
assertBaggage,
}, []connect.ClientOption{
connect.WithInterceptors(
NewInterceptor(
WithPropagator(propagator),
WithTracerProvider(traceProvider),
),
),
assertBaggage,
}, happyPingServer())
bag, _ := baggage.Parse("foo=bar")
ctx := baggage.ContextWithBaggage(context.Background(), bag)
_, err := client.Ping(ctx, connect.NewRequest(&pingv1.PingRequest{Id: 1}))
assert.NoError(t, err)
}

func TestUnaryPropagation(t *testing.T) {
t.Parallel()
var propagator propagation.TraceContext
Expand Down

0 comments on commit 05f1961

Please sign in to comment.