Documentation ¶
Index ¶
- Constants
- func AddGraphqlToSpan(ctx context.Context, op *graphql.OperationContext) context.Context
- func AddUserIDToSpan(ctx context.Context, userID string) context.Context
- func ClientStreamInterceptor() grpc.StreamClientInterceptor
- func ClientUnaryInterceptor() grpc.UnaryClientInterceptor
- func CopyToContext(src context.Context, dst context.Context) context.Context
- func GetTracer(name string) trace.Tracer
- func GraphqlInterceptor() graphql.HandlerExtension
- func HTTPClient(client *http.Client) *http.Client
- func HTTPMiddleware(h http.Handler) http.Handler
- func MarshalJSONFromContext(ctx context.Context) ([]byte, error)
- func PubSubAttributeValue(ctx context.Context) string
- func RecordError(ctx context.Context, err error, updateStatus bool, ...)
- func RegisterGoogleTracing()
- func ServerStreamInterceptor() grpc.StreamServerInterceptor
- func ServerUnaryInterceptor() grpc.UnaryServerInterceptor
- func SetupExporter(ctx context.Context) error
- func Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- func StartPubSubConsumer(ctx context.Context, sub *pubsub.Subscription, msg *pubsub.Message) (context.Context, trace.Span)
- func StartPubSubPublisher(ctx context.Context, topic *pubsub.Topic, msg *pubsub.Message) (context.Context, trace.Span)
- func StartSpannerTransaction(ctx context.Context, name string, client *spanner.Client, ...) (context.Context, trace.Span)
- func UnmarshalJSONToContext(ctx context.Context, data []byte) context.Context
- func WithCallMetadata() trace.SpanStartEventOption
- type HeaderMiddleware
- type Tracer
Constants ¶
const (
// PubSubAttributeKey is a Pub/Sub attribute key for span.
PubSubAttributeKey = "trace-context"
)
Variables ¶
This section is empty.
Functions ¶
func AddGraphqlToSpan ¶
AddGraphqlToSpan adds graphql context to span attributes and updates span name. https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/instrumentation/graphql/
func AddUserIDToSpan ¶
AddUserIDToSpan adds userID to current span's (got from context) attributes.
func ClientStreamInterceptor ¶
func ClientStreamInterceptor() grpc.StreamClientInterceptor
func ClientUnaryInterceptor ¶
func ClientUnaryInterceptor() grpc.UnaryClientInterceptor
func CopyToContext ¶
CopyToContext copies span from src context to dst context. Returns dst context with span.
func GraphqlInterceptor ¶
func GraphqlInterceptor() graphql.HandlerExtension
GraphqlInterceptor returns graphql extension that adds some graphql metadata to span attributes.
func HTTPClient ¶
HTTPClient adds middleware transport to given client and returns it. The middleware transport propagates tracing info to request HTTP headers. If client is nil default client is used.
func HTTPMiddleware ¶
HTTPMiddleware is an HTTP middleware that: 1. Checks if HTTP request has tracing (by checking B3 headers); 2. Starts new span (and sets parent span if any was in HTTP request) and stores it in context.
func MarshalJSONFromContext ¶
MarshalJSONFromContext gets current span from context and marshals it to JSON. It is useful to pass tracing through Pub/Sub. It also drops TraceState because Pub/Sub has limitation of 1024 bytes for attribute value.
func PubSubAttributeValue ¶
PubSubAttributeValue returns Pub/Sub attribute value with current span from context.
func RecordError ¶
RecordError is a wrapper to add an error to current span in context. It also sets span to error status if updateStatus is true.
func RegisterGoogleTracing ¶
func RegisterGoogleTracing()
RegisterGoogleTracing creates a bridge between google tracing (opencensus) and our tracing (opentelemetry). This function must be called after exporter is set up (SetupExporter).
func ServerStreamInterceptor ¶
func ServerStreamInterceptor() grpc.StreamServerInterceptor
func ServerUnaryInterceptor ¶
func ServerUnaryInterceptor() grpc.UnaryServerInterceptor
func SetupExporter ¶
SetupExporter prepares OpenTelemetry batch exporter that periodically sends batch of spans to OpenTelemetry collector.
func Start ¶
func Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
Start is a wrapper to start a new span. SetupExporter must be called before using this function.
func StartPubSubConsumer ¶
func StartPubSubConsumer(ctx context.Context, sub *pubsub.Subscription, msg *pubsub.Message) (context.Context, trace.Span)
StartPubSubConsumer extracts dumped span from Pub/Sub message attributes and injects it into context.
func StartPubSubPublisher ¶
func StartPubSubPublisher(ctx context.Context, topic *pubsub.Topic, msg *pubsub.Message) (context.Context, trace.Span)
StartPubSubPublisher is a helper to start Pub/Sub publisher span and automatically add tracing info to message attributes.
func StartSpannerTransaction ¶
func StartSpannerTransaction(ctx context.Context, name string, client *spanner.Client, statement *spanner.Statement) (context.Context, trace.Span)
StartSpannerTransaction is a helper to start span with some spanner attributes.
func UnmarshalJSONToContext ¶
UnmarshalJSONToContext unmarshals span from JSON and adds it to context.
func WithCallMetadata ¶
func WithCallMetadata() trace.SpanStartEventOption
WithCallMetadata adds caller file and line number to span or event attributes.
Types ¶
type HeaderMiddleware ¶
type HeaderMiddleware struct {
// contains filtered or unexported fields
}
HeaderMiddleware is an http.Handler middleware that exposes trace ID as X-Picnic-TraceID response header.
func (*HeaderMiddleware) ServeHTTP ¶
func (p *HeaderMiddleware) ServeHTTP(w http.ResponseWriter, req *http.Request)