Skip to content

Commit

Permalink
feat: use autoprop to set up tracing text map propagators
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Aguilar <pablo.aguilar@outlook.com.br>
  • Loading branch information
thepabloaguilar committed Apr 14, 2024
1 parent 408ac24 commit eb114fe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ require (
go.flipt.io/flipt/rpc/flipt v1.38.0
go.flipt.io/flipt/sdk/go v0.11.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0
go.opentelemetry.io/contrib/propagators/autoprop v0.50.0
go.opentelemetry.io/otel v1.25.0
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.25.0
Expand Down Expand Up @@ -235,6 +236,10 @@ require (
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/contrib/propagators/aws v1.25.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.25.0 // indirect
go.opentelemetry.io/contrib/propagators/jaeger v1.25.0 // indirect
go.opentelemetry.io/contrib/propagators/ot v1.25.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,16 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.4
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0/go.mod h1:Mjt1i1INqiaoZOMGR1RIUJN+i3ChKoFRqzrRQhlkbs0=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw=
go.opentelemetry.io/contrib/propagators/autoprop v0.50.0 h1:tK1hZrY9rV784YPGAUACvqBjvFCim2rrJZR/09giyrA=
go.opentelemetry.io/contrib/propagators/autoprop v0.50.0/go.mod h1:oTzb+geTS8mHaeIOYd/1AShfxdovU3AA1/m+IrheAvc=
go.opentelemetry.io/contrib/propagators/aws v1.25.0 h1:LYKyPhf1q+1ok4UUxcmQ2sERvWcUylg4v8MK+h8nCcA=
go.opentelemetry.io/contrib/propagators/aws v1.25.0/go.mod h1:HMRyfyD8oIZLpKSXC0zGmZZTuG4qGo6OtZOEu8IQPJc=
go.opentelemetry.io/contrib/propagators/b3 v1.25.0 h1:QU8UEKyPqgr/8vCC9LlDmkPnfFmiWAUF9GtJdcLz+BU=
go.opentelemetry.io/contrib/propagators/b3 v1.25.0/go.mod h1:qonC7wyvtX1E6cEpAR+bJmhcGr6IVRGc/f6ZTpvi7jA=
go.opentelemetry.io/contrib/propagators/jaeger v1.25.0 h1:GPnu8mDgqHlISYc0Ub0EbYlPWCOJE0biicGrE7vcE/M=
go.opentelemetry.io/contrib/propagators/jaeger v1.25.0/go.mod h1:WWa6gdfrRy23dFALEkiT+ynOI5Ke2g+fUa5Q2v0VGyg=
go.opentelemetry.io/contrib/propagators/ot v1.25.0 h1:9+54ye9caWA5XplhJoN6E8ECDKGeEsw/mqR4BIuZUfg=
go.opentelemetry.io/contrib/propagators/ot v1.25.0/go.mod h1:Fn0a9xFTClSSwNLpS1l0l55PkLHzr70RYlu+gUsPhHo=
go.opentelemetry.io/otel v1.25.0 h1:gldB5FfhRl7OJQbUHt/8s0a7cE8fbsPAtdpRaApKy4k=
go.opentelemetry.io/otel v1.25.0/go.mod h1:Wa2ds5NOXEMkCmUou1WA7ZBfLTHWIsp034OVD7AO+Vg=
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4=
Expand Down
22 changes: 20 additions & 2 deletions internal/cmd/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"sync"
"time"

"go.opentelemetry.io/contrib/propagators/autoprop"

sq "github.com/Masterminds/squirrel"
"go.flipt.io/flipt/internal/cache"
"go.flipt.io/flipt/internal/cache/memory"
Expand Down Expand Up @@ -39,7 +41,6 @@ import (
"go.flipt.io/flipt/internal/tracing"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -373,7 +374,12 @@ func NewGRPCServer(
})

otel.SetTracerProvider(tracingProvider)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))

textMapPropagator, err := autoprop.TextMapPropagator(getStringSlice(cfg.Tracing.Propagators)...)
if err != nil {
return nil, fmt.Errorf("error constructing tracing text map propagator: %w", err)
}
otel.SetTextMapPropagator(textMapPropagator)

grpcOpts := []grpc.ServerOption{
grpc.ChainUnaryInterceptor(interceptors...),
Expand Down Expand Up @@ -551,3 +557,15 @@ func getDB(ctx context.Context, logger *zap.Logger, cfg *config.Config, forceMig

return db, builder, driver, dbFunc, dbErr
}

// getStringSlice receives any slice which the underline member type is "string"
// and return a new slice with the same members but transformed to "string" type.
// This is useful when we want to convert an enum slice of strings.
func getStringSlice[AnyString ~string, Slice []AnyString](slice Slice) []string {
strSlice := make([]string, 0, len(slice))
for _, anyString := range slice {
strSlice = append(strSlice, string(anyString))
}

return strSlice
}

0 comments on commit eb114fe

Please sign in to comment.