Пример #1
0
func wrapStreamWithTracer(srv *grpc.ServiceDesc, desc grpc.StreamDesc) grpc.StreamDesc {
	name := "/" + srv.ServiceName + "/" + desc.StreamName + "/root"
	h := desc.Handler
	desc.Handler = func(srv interface{}, stream grpc.ServerStream) (err error) {
		span, ctx := trace.New(stream.Context(), name, trace.WithPanicGuard)
		defer func(errPtr *error) {
			if span.Failed && *errPtr == nil {
				*errPtr = grpc.Errorf(codes.Internal, "internal server error")
			}
		}(&err)
		defer span.Close()

		stream = wrapServerSteamWithContext(stream, ctx)
		return h(srv, stream)
	}
	return desc
}
Пример #2
-1
func wrapMethodWithTracer(srv *grpc.ServiceDesc, desc grpc.MethodDesc) grpc.MethodDesc {
	name := "/" + srv.ServiceName + "/" + desc.MethodName + "/root"
	h := desc.Handler
	desc.Handler = func(srv interface{}, ctx context.Context, dec func(interface{}) error, intc grpc.UnaryServerInterceptor) (out interface{}, err error) {
		span, ctx := trace.New(ctx, name, trace.WithPanicGuard)
		defer func(errPtr *error) {
			if span.Failed && *errPtr == nil {
				*errPtr = grpc.Errorf(codes.Internal, "internal server error")
			}
		}(&err)
		defer span.Close()

		return h(srv, ctx, dec, intc)
	}
	return desc
}