Documentation ¶
Overview ¶
Package otgrpc provides OpenTracing support for any gRPC client or server.
See the README for simple usage examples: https://github.com/grpc-ecosystem/grpc-opentracing/blob/master/go/otgrpc/README.md
Index ¶
- func OpenTracingClientInterceptor(tracer opentracing.Tracer, optFuncs ...Option) grpc.UnaryClientInterceptor
- func OpenTracingServerInterceptor(tracer opentracing.Tracer, optFuncs ...Option) grpc.UnaryServerInterceptor
- func SetSpanTags(span opentracing.Span, err error, client bool)
- type Class
- type Option
- type SpanDecoratorFunc
- type SpanInclusionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OpenTracingClientInterceptor ¶
func OpenTracingClientInterceptor(tracer opentracing.Tracer, optFuncs ...Option) grpc.UnaryClientInterceptor
OpenTracingClientInterceptor returns a grpc.UnaryClientInterceptor suitable for use in a grpc.Dial call.
For example:
conn, err := grpc.Dial( address, ..., // (existing DialOptions) grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(tracer)))
All gRPC client spans will inject the OpenTracing SpanContext into the gRPC metadata; they will also look in the context.Context for an active in-process parent Span and establish a ChildOf reference if such a parent Span could be found.
func OpenTracingServerInterceptor ¶
func OpenTracingServerInterceptor(tracer opentracing.Tracer, optFuncs ...Option) grpc.UnaryServerInterceptor
OpenTracingServerInterceptor returns a grpc.UnaryServerInterceptor suitable for use in a grpc.NewServer call.
For example:
s := grpc.NewServer( ..., // (existing ServerOptions) grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)))
All gRPC server spans will look for an OpenTracing SpanContext in the gRPC metadata; if found, the server span will act as the ChildOf that RPC SpanContext.
Root or not, the server Span will be embedded in the context.Context for the application-specific gRPC handler(s) to access.
func SetSpanTags ¶
SetSpanTags sets one or more tags on the given span according to the error.
Types ¶
type Class ¶
type Class string
A Class is a set of types of outcomes (including errors) that will often be handled in the same way.
type Option ¶
type Option func(o *options)
Option instances may be used in OpenTracing(Server|Client)Interceptor initialization.
See this post about the "functional options" pattern: http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
func IncludingSpans ¶
func IncludingSpans(inclusionFunc SpanInclusionFunc) Option
IncludingSpans binds a IncludeSpanFunc to the options
func LogPayloads ¶
func LogPayloads() Option
LogPayloads returns an Option that tells the OpenTracing instrumentation to try to log application payloads in both directions.
func SpanDecorator ¶
func SpanDecorator(decorator SpanDecoratorFunc) Option
SpanDecorator binds a function that decorates gRPC Spans.
type SpanDecoratorFunc ¶
type SpanDecoratorFunc func( span opentracing.Span, method string, req, resp interface{}, grpcError error)
SpanDecoratorFunc provides an (optional) mechanism for otgrpc users to add arbitrary tags/logs/etc to the opentracing.Span associated with client and/or server RPCs.
type SpanInclusionFunc ¶
type SpanInclusionFunc func( parentSpanCtx opentracing.SpanContext, method string, req, resp interface{}) bool
SpanInclusionFunc provides an optional mechanism to decide whether or not to trace a given gRPC call. Return true to create a Span and initiate tracing, false to not create a Span and not trace.
parentSpanCtx may be nil if no parent could be extraction from either the Go context.Context (on the client) or the RPC (on the server).