Skip to content

Commit

Permalink
chore: Fix legacy OTLP exporter initialization (#1891)
Browse files Browse the repository at this point in the history
When the legacy OTLP exporter is configured with the `tracing` block, we
need to create the exporter manually because the Otel library cannot
read our custom environment implementation to read the endpoint and
insecure configuration.

Signed-off-by: Charith Ellawala <charith@cerbos.dev>

Signed-off-by: Charith Ellawala <charith@cerbos.dev>
  • Loading branch information
charithe committed Nov 28, 2023
1 parent 23de714 commit 3dc5ff8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/observability/tracing/tracing.go
Expand Up @@ -13,6 +13,7 @@ import (
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
otelsdk "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/jaeger" //nolint:staticcheck
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/semconv/v1.13.0/httpconv"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
Expand Down Expand Up @@ -110,6 +111,11 @@ func configureOTLP(ctx context.Context) (func() error, error) {
}
}

exporter, err := otlptracegrpc.New(ctx, otlptracegrpc.WithEndpoint(conf.OTLP.CollectorEndpoint), otlptracegrpc.WithInsecure())
if err != nil {
return nil, fmt.Errorf("failed to create OTLP exporter: %w", err)
}

envMap := map[string]string{
otel.ServiceNameEV.Name: *svcName,
otel.TracesSamplerEV.Name: otel.ParentBasedTraceIDRatioSampler,
Expand All @@ -128,7 +134,7 @@ func configureOTLP(ctx context.Context) (func() error, error) {
return os.LookupEnv(key)
}

return otel.InitTraces(ctx, otel.Env(env))
return otel.InitTracesWithExporter(ctx, otel.Env(env), exporter)
}

func HTTPHandler(handler http.Handler, path string) http.Handler {
Expand Down

0 comments on commit 3dc5ff8

Please sign in to comment.