Skip to content

Commit

Permalink
add b3singleheader injection
Browse files Browse the repository at this point in the history
Signed-off-by: Praneeth Talishetti <47842333+be-a-bee@users.noreply.github.com>
  • Loading branch information
be-a-bee authored and ashutosh-narkar committed Feb 12, 2024
1 parent 6cf8de2 commit 9436014
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)),
Expand Down
10 changes: 6 additions & 4 deletions test/e2e/distributedtracing/distributedtracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := `
Expand All @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit 9436014

Please sign in to comment.