trace

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: Apache-2.0 Imports: 25 Imported by: 2

Documentation

Index

Constants

View Source
const (
	UserIDAttribute = "LogUserId"

	FlightID = "x-flight-id"

	HTTPMethodKey     = attribute.Key("http.method")
	HTTPStatusCodeKey = attribute.Key("http.status_code")
	HTTPFlavorKey     = attribute.Key("http.flavor")
	HTTPUserAgentKey  = attribute.Key("http.user_agent")
	HTTPSchemeKey     = attribute.Key("http.scheme")
	HTTPClientIPKey   = attribute.Key("http.client_ip")

	EnduserIDKey = attribute.Key("enduser.id")

	NetHostNameKey     = attribute.Key("net.host.name")
	NetHostPortKey     = attribute.Key("net.host.port")
	NetSockPeerAddrKey = attribute.Key("net.sock.peer.addr")
	NetSockPeerPortKey = attribute.Key("net.sock.peer.port")
)
View Source
const (
	LogFieldTraceID = "trace_id"
)

Variables

View Source
var (
	HTTPSchemeHTTP  = HTTPSchemeKey.String("http")
	HTTPSchemeHTTPS = HTTPSchemeKey.String("https")
)

Functions

func ContextWithLogger

func ContextWithLogger(ctx context.Context, l *logrus.Logger) context.Context

ContextWithLogger inserts a log entry from l into ctx and returns the updated context. Note that this will over-ride any existing log entry in the context. For go-restful endpoints, consider using the Logger function instead

func HTTPServerRequest added in v1.1.2

func HTTPServerRequest(req *http.Request) []attribute.KeyValue

func HTTPServerStatus added in v1.1.2

func HTTPServerStatus(code int) (codes.Code, string)

func Initialize

func Initialize(traceProvider, service string)

func InstrumentCommonAttributes

func InstrumentCommonAttributes(tracerName string, excludeEndpoints map[string]map[string]bool) (filterFunc restful.FilterFunction)

InstrumentCommonAttributes is a filter that will add span attributes for user id and flight id

Parameters tracerName: tracer name excludeEndpoints: consists of blacklisted endpoint name to not send tracer eg. key: /healthz , key2: map of http.Method (GET, POST, DELETE, PUT) , value : boolean

func LogTraceError

func LogTraceError(ctx context.Context, err error, errMsg string, fields ...logrus.Fields)

LogTraceError logs the provided error and message to the logger obtained from the context, records the error in the trace span and sets the status of the span to Error.

Parameters: ctx: Context in which the function operates, it must contain a valid span and logger. err: Error to be logged and recorded. If this is nil, only the error message will be logged. errMsg: Message to be logged and recorded. This message is also used as the span status description when error occurs.

This function does not return any values.

func LogTraceInfo added in v1.1.4

func LogTraceInfo(ctx context.Context, msg string, fields ...logrus.Fields)

LogTraceInfo logs the given message to the logger obtained from the context and records the message in the trace span.

This function does not return any values.

func LoggerAddField

func LoggerAddField(ctx context.Context, key string, value interface{}) context.Context

LoggerAddField extracts the logger in the context and adds a field with the given key and value

func LoggerFromContext

func LoggerFromContext(ctx context.Context) *logrus.Entry

LoggerFromContext extracts the logger from the context. If it's not found, a logger with default settings is returned For web API endpoints, the Logger go-restful filter is usually used to add the logger in the request context.

func NewAutoNamedChildSpan

func NewAutoNamedChildSpan(ctx context.Context, opts ...trace.SpanStartOption) (context.Context, trace.Span)

func NewChildSpan

func NewChildSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

func NewLogEntryContext

func NewLogEntryContext(ctx context.Context, format, level string) (context.Context, *logrus.Entry)

NewLogEntryContext sets up a log entry with the given format and level and injects it into ctx, which are then returned. For any invalid value including empty string, it will fall back to using the defaults of logrus

func NewLogger

func NewLogger(format, level string) *logrus.Logger

NewLogger returns a logger with the format and level set with the given values. For any invalid value including empty string, it will fall back to using the defaults of logrus

func NewRootSpan

func NewRootSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

func SetUpTracer

func SetUpTracer(ctx context.Context, url string, connectTimeout time.Duration) (func(), error)

SetUpTracer sets up a GRPC reciever for serviceName with url as the endpoint of the collector. If a connection is not establised within connectTimeout, it is aborted and returns an error

func SpanFromContext

func SpanFromContext(ctx context.Context) trace.Span

func TraceError added in v1.1.1

func TraceError(ctx context.Context, err error, errMsg string)

TraceError record the current error in trace span without log message.

Parameters: ctx: Context in which the function operates, it must contain a valid span. err: Error to be and recorded. If this is nil, this method does nothing. errMsg: Message to be recorded. This message is also used as the span status description when error occurs.

func TraceIDFromContext

func TraceIDFromContext(ctx context.Context) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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