Skip to content

Commit ffd20b7

Browse files
authored
Merge pull request #15 from joaopenteado/otelcfg-shutdown-simplification
Refactor SetupTracerProvider
2 parents 8f29d03 + a1ecea7 commit ffd20b7

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

otelcfg/trace.go

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package otelcfg
22

33
import (
44
"context"
5-
"errors"
6-
"slices"
75

86
"go.opentelemetry.io/contrib/exporters/autoexport"
97
"go.opentelemetry.io/contrib/propagators/autoprop"
@@ -47,28 +45,12 @@ func WithTracerProviderOptions(opts ...trace.TracerProviderOption) TracerProvide
4745
})
4846
}
4947

50-
func SetupTracerProvider(ctx context.Context, opts ...TracerProviderOption) (shutdown func(context.Context) error, err error) {
48+
func SetupTracerProvider(ctx context.Context, opts ...TracerProviderOption) (*trace.TracerProvider, error) {
5149
var cfg traceProviderConfig
5250
for _, opt := range opts {
5351
opt.apply(&cfg)
5452
}
5553

56-
// This code is largely taken from Cloud Trace's documentation:
57-
// https://cloud.google.com/trace/docs/setup/go-ot#config-otel
58-
59-
var shutdownFuncs []func(context.Context) error
60-
61-
// shutdown combines shutdown functions from multiple OpenTelemetry
62-
// components into a single function.
63-
shutdown = func(ctx context.Context) error {
64-
var err error
65-
for _, fn := range slices.Backward(shutdownFuncs) {
66-
err = errors.Join(err, fn(ctx))
67-
}
68-
shutdownFuncs = nil
69-
return err
70-
}
71-
7254
if cfg.textMapPropagator == nil {
7355
// Configure Context Propagation to use the default W3C traceparent
7456
// format. This can be overriden by the OTEL_PROPAGATORS environment
@@ -98,12 +80,11 @@ func SetupTracerProvider(ctx context.Context, opts ...TracerProviderOption) (shu
9880
tpOpts = append(tpOpts, cfg.tracerProviderOpts...)
9981

10082
tp := trace.NewTracerProvider(tpOpts...)
101-
shutdownFuncs = append(shutdownFuncs, tp.Shutdown)
10283

10384
// Set the tracer provider as the global tracer provider.
10485
otel.SetTracerProvider(tp)
10586

106-
return shutdown, nil
87+
return tp, nil
10788
}
10889

10990
// CloudTraceOLTPExporter creates a new span exporter for the Cloud Trace

0 commit comments

Comments
 (0)