mirror of
https://github.com/fosrl/newt.git
synced 2026-03-26 20:46:41 +00:00
fix(build): use Registration.Unregister() without context; return tracer shutdown func from setupTracing
This commit is contained in:
@@ -177,7 +177,7 @@ func registerBuildWSProxyInstruments() error {
|
|||||||
otel.Handle(e)
|
otel.Handle(e)
|
||||||
} else {
|
} else {
|
||||||
// Provide a functional stopper that unregisters the callback
|
// Provide a functional stopper that unregisters the callback
|
||||||
obsStopper = func() { _ = reg.Unregister(context.Background()) }
|
obsStopper = func() { _ = reg.Unregister() }
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -224,7 +224,7 @@ func SetProxyObservableCallback(cb func(context.Context, metric.Observer) error)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Provide a functional stopper to unregister later if needed
|
// Provide a functional stopper to unregister later if needed
|
||||||
proxyStopper = func() { _ = reg.Unregister(context.Background()) }
|
proxyStopper = func() { _ = reg.Unregister() }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,11 +132,11 @@ func Init(ctx context.Context, cfg Config) (*Setup, error) {
|
|||||||
s.shutdowns = append(s.shutdowns, mp.Shutdown)
|
s.shutdowns = append(s.shutdowns, mp.Shutdown)
|
||||||
// Optional tracing
|
// Optional tracing
|
||||||
if cfg.OTLPEnabled {
|
if cfg.OTLPEnabled {
|
||||||
if tp, exp := setupTracing(ctx, cfg, res); tp != nil {
|
if tp, shutdown := setupTracing(ctx, cfg, res); tp != nil {
|
||||||
otel.SetTracerProvider(tp)
|
otel.SetTracerProvider(tp)
|
||||||
s.TracerProvider = tp
|
s.TracerProvider = tp
|
||||||
s.shutdowns = append(s.shutdowns, func(c context.Context) error {
|
s.shutdowns = append(s.shutdowns, func(c context.Context) error {
|
||||||
return errors.Join(exp.Shutdown(c), tp.Shutdown(c))
|
return errors.Join(shutdown(c), tp.Shutdown(c))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,7 +209,7 @@ func buildMeterProvider(res *resource.Resource, readers []sdkmetric.Reader) *sdk
|
|||||||
return sdkmetric.NewMeterProvider(mpOpts...)
|
return sdkmetric.NewMeterProvider(mpOpts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupTracing(ctx context.Context, cfg Config, res *resource.Resource) (*sdktrace.TracerProvider, *otlptracegrpc.Exporter) {
|
func setupTracing(ctx context.Context, cfg Config, res *resource.Resource) (*sdktrace.TracerProvider, func(context.Context) error) {
|
||||||
topts := []otlptracegrpc.Option{otlptracegrpc.WithEndpoint(cfg.OTLPEndpoint)}
|
topts := []otlptracegrpc.Option{otlptracegrpc.WithEndpoint(cfg.OTLPEndpoint)}
|
||||||
if hdrs := parseOTLPHeaders(os.Getenv("OTEL_EXPORTER_OTLP_HEADERS")); len(hdrs) > 0 { topts = append(topts, otlptracegrpc.WithHeaders(hdrs)) }
|
if hdrs := parseOTLPHeaders(os.Getenv("OTEL_EXPORTER_OTLP_HEADERS")); len(hdrs) > 0 { topts = append(topts, otlptracegrpc.WithHeaders(hdrs)) }
|
||||||
if cfg.OTLPInsecure { topts = append(topts, otlptracegrpc.WithInsecure()) } else if certFile := os.Getenv("OTEL_EXPORTER_OTLP_CERTIFICATE"); certFile != "" {
|
if cfg.OTLPInsecure { topts = append(topts, otlptracegrpc.WithInsecure()) } else if certFile := os.Getenv("OTEL_EXPORTER_OTLP_CERTIFICATE"); certFile != "" {
|
||||||
@@ -218,7 +218,7 @@ func setupTracing(ctx context.Context, cfg Config, res *resource.Resource) (*sdk
|
|||||||
exp, err := otlptracegrpc.New(ctx, topts...)
|
exp, err := otlptracegrpc.New(ctx, topts...)
|
||||||
if err != nil { return nil, nil }
|
if err != nil { return nil, nil }
|
||||||
tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exp), sdktrace.WithResource(res))
|
tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exp), sdktrace.WithResource(res))
|
||||||
return tp, exp
|
return tp, exp.Shutdown
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown flushes exporters and providers in reverse init order.
|
// Shutdown flushes exporters and providers in reverse init order.
|
||||||
|
|||||||
Reference in New Issue
Block a user