tracing

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const CorrelationIDCtxKey = "CorrelationIDCtxKey"

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.

Variables

This section is empty.

Functions

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 http.Requests which have passed through tracing/HTTPMiddleware.

func HTTPMiddleware added in v0.3.0

func HTTPMiddleware(next http.Handler) http.Handler

HTTPMiddleware extracts the OpenTracing 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 OpenTracing 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, args ...interface{}) (context.Context, sql.MiddlewareEnd, 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 StreamServerInterceptor added in v0.16.1

func StreamServerInterceptor(srv interface{}, stream grpc.ServerStream, info *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 middleware should *always* be placed after the opentracing middleware to ensure that an opentracing context is present on the context. Additionally, this middleware should always appear *before* the logging middleware to ensure that the correlation_id is properly logged.

func TraceOutbound

func TraceOutbound(r *http.Request, span opentracing.Span) error

TraceOutbound injects outbound HTTP requests with OpenTracing headers

func UnaryServerInterceptor added in v0.16.1

func UnaryServerInterceptor(ctx context.Context, req interface{}, info *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 middleware should *always* be placed after the opentracing middleware to ensure that an opentracing context is present on the context. Additionally, this middleware should always appear *before* the logging middleware to ensure that the correlation_id is properly logged.

Types

type Config

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

Config defines the necessary configuration for instantiating a Tracer

func (Config) ConfigureTracer

func (c Config) ConfigureTracer() io.Closer

ConfigureTracer instantiates and configures the OpenTracer and returns the tracer closer

func (*Config) RegisterFlags

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

RegisterFlags registers Tracer flags with pflags

Jump to

Keyboard shortcuts

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