From 9436014ba661285ba1f70a0a75ab81f191495bd3 Mon Sep 17 00:00:00 2001 From: Praneeth Talishetti <47842333+be-a-bee@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:51:11 +0530 Subject: [PATCH] add b3singleheader injection Signed-off-by: Praneeth Talishetti <47842333+be-a-bee@users.noreply.github.com> --- internal/internal.go | 4 ++-- test/e2e/distributedtracing/distributedtracing_test.go | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/internal.go b/internal/internal.go index fa7c0ab95..5c7d312df 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -135,11 +135,11 @@ func New(m *plugins.Manager, cfg *Config) plugins.Plugin { if m.TracerProvider() != nil { grpcTracingOption := []otelgrpc.Option{ otelgrpc.WithTracerProvider(m.TracerProvider()), - otelgrpc.WithPropagators(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}, b3.New(b3.WithInjectEncoding(b3.B3MultipleHeader)))), + otelgrpc.WithPropagators(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}, b3.New(b3.WithInjectEncoding(b3.B3MultipleHeader|b3.B3SingleHeader)))), } distributedTracingOpts = tracing.NewOptions( otelhttp.WithTracerProvider(m.TracerProvider()), - otelhttp.WithPropagators(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}, b3.New(b3.WithInjectEncoding(b3.B3MultipleHeader)))), + otelhttp.WithPropagators(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}, b3.New(b3.WithInjectEncoding(b3.B3MultipleHeader|b3.B3SingleHeader)))), ) grpcOpts = append(grpcOpts, grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor(grpcTracingOption...)), diff --git a/test/e2e/distributedtracing/distributedtracing_test.go b/test/e2e/distributedtracing/distributedtracing_test.go index d0ee77578..736be102d 100644 --- a/test/e2e/distributedtracing/distributedtracing_test.go +++ b/test/e2e/distributedtracing/distributedtracing_test.go @@ -78,12 +78,12 @@ func TestMain(m *testing.M) { count := 0 countMutex := sync.Mutex{} - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { w.Header().Set("content-type", "application/json") countMutex.Lock() count = count + 1 countMutex.Unlock() - fmt.Fprintf(w, `{"count": %d}`, count) + fmt.Fprintf(w, `{"count": %d, "b3multiheader": "%s", "b3singleheader": "%s"}`, count, req.Header.Get("X-B3-Traceid"), req.Header.Get("B3")) })) defer ts.Close() moduleFmt := ` @@ -92,8 +92,10 @@ func TestMain(m *testing.M) { allow { resp := http.send({"url": "%s", "method":"GET"}) resp.body.count == 1 + resp.body.b3multiheader == "%s" + contains(resp.body.b3singleheader, "%s") }` - module := fmt.Sprintf(moduleFmt, ts.URL) + module := fmt.Sprintf(moduleFmt, ts.URL, exampleTraceID, exampleTraceID) pluginsManager, err := e2e.TestAuthzServerWithWithOpts(module, "envoy/authz/allow", ":9191", plugins.WithTracerProvider(tracerProvider), plugins.ConsoleLogger(consoleLogger)) if err != nil { log.Fatal(err) @@ -104,7 +106,7 @@ func TestMain(m *testing.M) { os.Exit(m.Run()) } -func TestServerSpanAndTraceIdInDecisionLog(t *testing.T) { +func TestServerSpanAndTraceIdInDecisionLogAndB3TraceHeadersPropagation(t *testing.T) { spanExporter.Reset() t.Run("envoy.service.auth.v3.Authorization Check", func(t *testing.T) {