tracing

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmbedCorrelationID added in v0.21.0

func EmbedCorrelationID(ctx context.Context) context.Context

EmbedCorrelationID embeds the current Trace ID as the correlation ID in the context logger Continuing this function for backward compatibility.

func GetCorrelationID added in v0.14.0

func GetCorrelationID(ctx context.Context) string

GetCorrelationID returns the correlation ID associated with the given Context. This function only produces meaningful results for Contexts associated with gRPC or HTTP Requests which have passed through their associated tracing middleware.

func HTTPServerMiddleware added in v0.22.0

func HTTPServerMiddleware(next http.Handler) http.Handler

HTTPServerMiddleware extracts the OpenTelemetry context on all incoming HTTP requests, if present. if no trace ID is present in the headers, a trace is initiated.

The following tags are placed on all incoming HTTP requests: * http.method * http.url

Outbound responses will be tagged with the following tags, if applicable: * http.status_code * error (if the status code is >= 500)

The returned HTTP Request includes the wrapped OpenTelemetry Span Context. Note that this middleware must be attached after writer.StatusRecorderMiddleware for HTTP response span tagging to function.

func SQLMiddleware added in v0.3.0

func SQLMiddleware(ctx context.Context, queryName, query string, _ ...interface{}) (context.Context, sql.End, error)

SQLMiddleware traces requests made against SQL databases.

Span names always start with "db". If a queryName is provided (highly recommended), the span name will include the queryname in the format "db_<queryName>"

The following tags are placed on all SQL traces: * component - Always set to "tracing" * db.type - Always set to "sql" * db.statement - Always set to the query statement * error - Set to true only if an error was encountered with the query

func StartSpanFromContext added in v1.0.0

func StartSpanFromContext(ctx context.Context, operationName string, opts ...trace.SpanStartOption) (trace.Span, context.Context)

StartSpanFromContext Start the span from the provided context with provided options

func StreamClientInterceptor added in v0.21.0

func StreamClientInterceptor(
	parentCtx context.Context,
	desc *grpc.StreamDesc,
	cc *grpc.ClientConn,
	method string,
	streamer grpc.Streamer,
	opts ...grpc.CallOption,
) (grpc.ClientStream, error)

StreamClientInterceptor returns a new unary client interceptor that adds the correlation_id to the logger context. Note that this interceptor should *always* be placed after the opentelemetry interceptor to ensure that an opentelemetry context is present on the context. Additionally, this interceptor should always appear *before* the logging interceptor to ensure that the correlation_id is properly logged.

func StreamServerInterceptor added in v0.16.1

func StreamServerInterceptor(srv interface{}, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error

StreamServerInterceptor returns a new unary server interceptor that adds the correlation_id to the logger context. Note that this interceptor should *always* be placed after the opentelemetry interceptor to ensure that an opentelemetry context is present on the context. Additionally, this interceptor should always appear *before* the logging interceptor to ensure that the correlation_id is properly logged.

func UnaryClientInterceptor added in v0.21.0

func UnaryClientInterceptor(
	parentCtx context.Context,
	method string,
	req, reply interface{},
	cc *grpc.ClientConn,
	invoker grpc.UnaryInvoker,
	opts ...grpc.CallOption,
) error

UnaryClientInterceptor returns a new unary client interceptor that adds the correlation_id to the logger context. Note that this interceptor should *always* be placed after the opentelemetry interceptor to ensure that an opentelemetry context is present on the context. Additionally, this interceptor should always appear *before* the logging interceptor to ensure that the correlation_id is properly logged.

func UnaryServerInterceptor added in v0.16.1

func UnaryServerInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

UnaryServerInterceptor returns a new unary server interceptor that adds the correlation_id to the logger context. Note that this interceptor should *always* be placed after the opentelemetry interceptor to ensure that an opentelemetry context is present on the context. Additionally, this interceptor should always appear *before* the logging interceptor to ensure that the correlation_id is properly logged.

Types

type Config

type Config struct {
	SamplerType           string
	AgentHost             string
	ServiceName           string
	ServiceNamespace      string
	SamplerParam          float64
	ReporterMaxQueueSize  int
	ReporterFlushInterval time.Duration
	AgentPort             int
	Enabled               bool
	ReporterLogSpans      bool
}

Config defines the necessary configuration for instantiating a Tracer

func (*Config) RegisterFlags

func (c *Config) RegisterFlags(flags *pflag.FlagSet)

RegisterFlags registers Tracer flags with pflags

func (Config) TracerProvider added in v1.0.0

func (c Config) TracerProvider() (func(context.Context) error, error)

TracerProvider returns an OpenTelemetry TracerProvider configured to use the Jaeger exporter that will send spans to the provided url. The returned TracerProvider will also use a Resource configured with all the information about the application.

type CorrelationIDCtxKeyType added in v0.33.1

type CorrelationIDCtxKeyType int

CorrelationIDCtxKeyType is the type used to uniquely place the trace header in contexts

const CorrelationIDCtxKey CorrelationIDCtxKeyType = iota

CorrelationIDCtxKey is the key into any context.Context which maps to the correlation id of the given context. This correlation ID can be conveyed to external clients in order to correlate external systems with SpotHero tracing and logging.

type RoundTripper added in v0.24.0

type RoundTripper struct {
	RoundTripper http.RoundTripper
}

RoundTripper provides a proxied HTTP RoundTripper which traces client HTTP request details

func (RoundTripper) RoundTrip added in v0.24.0

func (rt RoundTripper) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip completes HTTP roundtrips while tracing HTTP request details

Jump to

Keyboard shortcuts

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