Tracing: Enable traces to profiles (#88896)

This commit is contained in:
Marcus Efraimsson
2024-06-07 16:58:24 +02:00
committed by GitHub
parent c9271edfa1
commit 40931b6da6
6 changed files with 47 additions and 6 deletions
+2
View File
@@ -272,6 +272,8 @@ func (ots *TracingService) initOpentelemetryTracer() error {
}
}
tp = NewProfilingTracerProvider(tp)
// Register our TracerProvider as the global so any imported
// instrumentation in the future will default to using it
// only if tracing is enabled
+27
View File
@@ -0,0 +1,27 @@
package tracing
import (
"context"
otelpyroscope "github.com/grafana/otel-profiling-go"
trace "go.opentelemetry.io/otel/trace"
)
type profilingTracerProvider struct {
trace.TracerProvider
wrappedTp tracerProvider
}
// NewProfilingTracerProvider creates a new tracer provider that annotates pprof
// samples with span_id label. This allows to establish a relationship
// between pprof profiles and reported tracing spans.
func NewProfilingTracerProvider(tp tracerProvider) tracerProvider {
return &profilingTracerProvider{
TracerProvider: otelpyroscope.NewTracerProvider(tp),
wrappedTp: tp,
}
}
func (tp *profilingTracerProvider) Shutdown(ctx context.Context) error {
return tp.wrappedTp.Shutdown(ctx)
}