Allow disabling tracing payload logging
package rpcutil
import (
+ "os"
+
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
opentracing "github.com/opentracing/opentracing-go"
+ "github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
"google.golang.org/grpc"
)
// OpenTracingServerInterceptor provides a default gRPC server
// interceptor for emitting tracing to the global OpenTracing tracer.
func OpenTracingServerInterceptor(parentSpan opentracing.Span, options ...otgrpc.Option) grpc.UnaryServerInterceptor {
- // Log full payloads along with trace spans
- options = append(options, otgrpc.LogPayloads())
+ options = append(options, logPayloads()...)
tracer := opentracing.GlobalTracer()
if parentSpan != nil {
@@ -38,8 +40,7 @@ func OpenTracingServerInterceptor(parentSpan opentracing.Span, options ...otgrpc
func OpenTracingStreamServerInterceptor(parentSpan opentracing.Span,
options ...otgrpc.Option) grpc.StreamServerInterceptor {
- // Log full payloads along with trace spans
- options = append(options, otgrpc.LogPayloads())
+ options = append(options, logPayloads()...)
tracer := opentracing.GlobalTracer()
if parentSpan != nil {
@@ -52,25 +53,21 @@ func OpenTracingStreamServerInterceptor(parentSpan opentracing.Span,
// OpenTracingClientInterceptor provides a default gRPC client interceptor for emitting tracing to the global
// OpenTracing tracer.
func OpenTracingClientInterceptor(options ...otgrpc.Option) grpc.UnaryClientInterceptor {
- options = append(options,
- // Log full payloads along with trace spans
- otgrpc.LogPayloads(),
+ options = append(append(options,
// Do not trace calls to the empty method
otgrpc.IncludingSpans(func(_ opentracing.SpanContext, method string, _, _ interface{}) bool {
return method != ""
- }))
+ })), logPayloads()...)
return otgrpc.OpenTracingClientInterceptor(opentracing.GlobalTracer(), options...)
}
// Like OpenTracingClientInterceptor but for streaming gRPC calls.
func OpenTracingStreamClientInterceptor(options ...otgrpc.Option) grpc.StreamClientInterceptor {
- options = append(options,
- // Log full payloads along with trace spans
- otgrpc.LogPayloads(),
+ options = append(append(options,
// Do not trace calls to the empty method
otgrpc.IncludingSpans(func(_ opentracing.SpanContext, method string, _, _ interface{}) bool {
return method != ""
- }))
+ })), logPayloads()...)
return otgrpc.OpenTracingStreamClientInterceptor(opentracing.GlobalTracer(), options...)
}
@@ -114,3 +111,13 @@ func (t *reparentingTracer) hasChildOf(opts ...opentracing.StartSpanOption) bool
}
var _ opentracing.Tracer = &reparentingTracer{}
+
+// Option to log payloads in trace spans. Defalut is on. Can be
+// disabled by setting an env var to reduce tracing overhead.
+func logPayloads() []otgrpc.Option {
+ res := []otgrpc.Option{}
+ if !cmdutil.IsTruthy(os.Getenv("PULUMI_TRACING_NO_PAYLOADS")) {
+ res = append(res, otgrpc.LogPayloads())
+ }
+ return res
+}
