Skip to content

Commit

Permalink
add b3 propagators v1.21 module and use it
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 8, 2024
1 parent 543adde commit 0d06ee7
Show file tree
Hide file tree
Showing 11 changed files with 759 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ require (
)

require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
Expand Down Expand Up @@ -75,6 +74,7 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yashtewari/glob-intersection v0.2.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.21.1
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ cloud.google.com/go v0.26.0 h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiVlk=
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand Down Expand Up @@ -231,6 +230,8 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.4
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1/go.mod h1:4UoMYEZOC0yN/sPGH76KPkkU7zgiEWYWL9vwmbnTJPE=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 h1:aFJWCqJMNjENlcleuuOkGAPH82y0yULBScfXcIEdS24=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1/go.mod h1:sEGXWArGqc3tVa+ekntsN65DmVbVeW+7lTKTjZF3/Fo=
go.opentelemetry.io/contrib/propagators/b3 v1.21.1 h1:WPYiUgmw3+b7b3sQ1bFBFAf0q+Di9dvNc3AtYfnT4RQ=
go.opentelemetry.io/contrib/propagators/b3 v1.21.1/go.mod h1:EmzokPoSqsYMBVK4nRnhsfm5mbn8J1eDuz/U1UaQaWg=
go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc=
go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 h1:cl5P5/GIfFh4t6xyruOgJP5QiA1pw4fYYdv6nc6CBWw=
Expand Down
6 changes: 4 additions & 2 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/contrib/propagators/b3"
"go.opentelemetry.io/otel/propagation"
"google.golang.org/genproto/googleapis/rpc/code"
rpc_status "google.golang.org/genproto/googleapis/rpc/status"
Expand Down Expand Up @@ -134,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{})),
otelgrpc.WithPropagators(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}, b3.New(b3.WithInjectEncoding(b3.B3MultipleHeader)))),
}
distributedTracingOpts = tracing.NewOptions(
otelhttp.WithTracerProvider(m.TracerProvider()),
otelhttp.WithPropagators(propagation.TraceContext{}),
otelhttp.WithPropagators(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}, b3.New(b3.WithInjectEncoding(b3.B3MultipleHeader)))),
)
grpcOpts = append(grpcOpts,
grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor(grpcTracingOption...)),
Expand Down Expand Up @@ -476,6 +477,7 @@ func (p *envoyExtAuthzGrpcServer) check(ctx context.Context, req interface{}) (*
resp.DynamicMetadata = dynamicMetadata

if status == int32(code.Code_OK) {

var headersToRemove []string
headersToRemove, err = result.GetRequestHTTPHeadersToRemove()
if err != nil {
Expand Down
27 changes: 22 additions & 5 deletions test/e2e/distributedtracing/distributedtracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import (
"google.golang.org/genproto/googleapis/rpc/code"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
)

var spanExporter *tracetest.InMemoryExporter
var consoleLogger *test.Logger

const exampleTraceID = "8a3c416a54a04ae6830de2f4f6dd4aef"
const exampleRequest = `{
"attributes": {
"request": {
Expand Down Expand Up @@ -115,7 +117,18 @@ func TestServerSpanAndTraceIdInDecisionLog(t *testing.T) {
t.Fatalf("did not connect: %v", err)
}
client := ext_authz.NewAuthorizationClient(conn)
resp, err := client.Check(context.Background(), &req)
ctx := context.Background()

// mimicking how a grpc client would append the headers to the outgoing context
ctx = metadata.AppendToOutgoingContext(ctx, "x-b3-parentspanid", "2a2b3c4d5e6f7a8b")
ctx = metadata.AppendToOutgoingContext(ctx, "x-b3-traceid", exampleTraceID)
ctx = metadata.AppendToOutgoingContext(ctx, "x-b3-spanid", "3f6a0b6d9d5f4b45")
ctx = metadata.AppendToOutgoingContext(ctx, "x-b3-sampled", "1")
ctx = metadata.AppendToOutgoingContext(ctx, "X-B3-Flags", "1")
ctx = metadata.AppendToOutgoingContext(ctx, "X-B3-Baggage-User", "alice")
ctx = metadata.AppendToOutgoingContext(ctx, "X-B3-Baggage-Transaction", "12345")

resp, err := client.Check(ctx, &req)
if err != nil {
t.Fatalf("error when send request %v", err)
}
Expand Down Expand Up @@ -168,10 +181,14 @@ func TestServerSpanAndTraceIdInDecisionLog(t *testing.T) {
}{
"labels": {},
"decision_id": {},
"trace_id": {},
"span_id": {},
"result": {},
"timestamp": {},
"trace_id": {match: func(t *testing.T, actual string) {
if actual != exampleTraceID {
t.Fatalf("Expected field 'trace_id' to be " + exampleTraceID)
}
}},
"span_id": {},
"result": {},
"timestamp": {},
"type": {match: func(t *testing.T, actual string) {
if actual != "openpolicyagent.org/decision_logs" {
t.Fatalf("Expected field 'type' to be 'openpolicyagent.org/decision_logs'")
Expand Down
201 changes: 201 additions & 0 deletions vendor/go.opentelemetry.io/contrib/propagators/b3/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions vendor/go.opentelemetry.io/contrib/propagators/b3/b3_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0d06ee7

Please sign in to comment.