tracex

package
v0.0.147 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const ComponentNameSeparator = "."

Variables

This section is empty.

Functions

func Component added in v0.0.146

func Component(name string) attribute.KeyValue

func ComponentName added in v0.0.125

func ComponentName(packageName, structName string) string

func GetStackTrace

func GetStackTrace() string

GetStackTrace returns the stack trace of the caller.

func Instrument added in v0.0.125

func Instrument(ctx context.Context, lp loggerProvider, tp tracerProvider, componentName string, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span, *logrusx.Logger)

This allows us to easily instrument our code with a unify way and reduce the boilerplate of instrumentation. Reduce the possibles errors. `span.End()` must be called at the end of using the span.

const myComponentName = "xpackage.xStruct"

func (xs *xStruct) instrument(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span, *logrusx.Logger) {
    return tracex.Instrument(ctx, xs.l.Logger, xs.d.Tracer, myComponentName, name, opts...)
}

func (xs *xStruct) process(ctx context.Context) error {
	ctx, span, l := xs.instrument(ctx, "process")
	defer span.End()
}

func InstrumentNext added in v0.0.146

func InstrumentNext(ctx context.Context, lp loggerNextProvider, tp tracerProvider, componentName string, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span, *loggerx.Logger)

func RecoverWithStackTrace

func RecoverWithStackTrace(ctx context.Context, l *loggerx.Logger, msg string)

RecoverWithStackTrace recovers from a panic and logs the message with a stack trace. It should only be used as a defer statement at the beginning of a function. i.e. defer tracex.RecoverWithStackTracef(l, "panic while handling messages")

func RecoverWithStackTracef added in v0.0.75

func RecoverWithStackTracef(l *logrusx.Logger, msg string, args ...interface{})

RecoverWithStackTracef recovers from a panic and logs the message with a stack trace. It should only be used as a defer statement at the beginning of a function. i.e. defer tracex.RecoverWithStackTracef(l, "panic while handling messages")

func StackTraceAttrs added in v0.0.146

func StackTraceAttrs(recovered any) []attribute.KeyValue

Types

This section is empty.

Jump to

Keyboard shortcuts

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