tracing

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2024 License: AGPL-3.0 Imports: 22 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// PubSubAttributeKey is a Pub/Sub attribute key for span.
	PubSubAttributeKey = "trace-context"
)

Variables

This section is empty.

Functions

func AddGraphqlToSpan

func AddGraphqlToSpan(ctx context.Context, op *graphql.OperationContext) context.Context

AddGraphqlToSpan adds graphql context to span attributes and updates span name. https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/instrumentation/graphql/

func AddUserIDToSpan

func AddUserIDToSpan(ctx context.Context, userID string) context.Context

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

func CopyToContext(src context.Context, dst context.Context) context.Context

CopyToContext copies span from src context to dst context. Returns dst context with span.

func GetTracer

func GetTracer(name string) trace.Tracer

GetTracer returns tracer instance.

func GraphqlInterceptor

func GraphqlInterceptor() graphql.HandlerExtension

GraphqlInterceptor returns graphql extension that adds some graphql metadata to span attributes.

func HTTPClient

func HTTPClient(client *http.Client) *http.Client

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

func HTTPMiddleware(h http.Handler) http.Handler

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

func MarshalJSONFromContext(ctx context.Context) ([]byte, error)

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

func PubSubAttributeValue(ctx context.Context) string

PubSubAttributeValue returns Pub/Sub attribute value with current span from context.

func RecordError

func RecordError(ctx context.Context, err error, updateStatus bool, options ...trace.EventOption)

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

func SetupExporter(ctx context.Context) error

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

func UnmarshalJSONToContext(ctx context.Context, data []byte) context.Context

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)

type Tracer

type Tracer interface {
	trace.Tracer
}

Tracer is a wrapper for OpenTelemetry Tracer.

var (
	// DefaultTracer is configured by SetupExporter tracer instance.
	DefaultTracer Tracer
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL