mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 05:52:22 +08:00

* Use authlib repo. Use otel * Use interceptors on the provider level * Create a new wire set with otel * Lint * Fix test * make update-workflow * make update-workspace * make update-workspace. Try to add authlib as enterprise imports * make update-workspace
39 lines
977 B
Go
39 lines
977 B
Go
package interceptors
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.opentelemetry.io/otel"
|
|
"go.opentelemetry.io/otel/propagation"
|
|
"go.opentelemetry.io/otel/trace"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/metadata"
|
|
)
|
|
|
|
const tracingPrefix = "gRPC Server "
|
|
|
|
func TracingStreamInterceptor(tracer trace.Tracer) grpc.StreamServerInterceptor {
|
|
return func(srv any, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
|
|
ctx := stream.Context()
|
|
if md, ok := metadata.FromIncomingContext(ctx); ok {
|
|
ctx = otel.GetTextMapPropagator().Extract(ctx, propagation.HeaderCarrier(md))
|
|
}
|
|
ctx, span := tracer.Start(ctx, tracingPrefix+info.FullMethod)
|
|
defer span.End()
|
|
tracingStream := &tracingServerStream{
|
|
ServerStream: stream,
|
|
ctx: ctx,
|
|
}
|
|
return handler(srv, tracingStream)
|
|
}
|
|
}
|
|
|
|
type tracingServerStream struct {
|
|
grpc.ServerStream
|
|
ctx context.Context
|
|
}
|
|
|
|
func (s *tracingServerStream) Context() context.Context {
|
|
return s.ctx
|
|
}
|