Documentation
¶
Index ¶
- Constants
- func Component(name string) attribute.KeyValue
- func ComponentName(packageName, structName string) string
- func GetStackTrace() string
- func Instrument(ctx context.Context, lp loggerProvider, tp tracerProvider, ...) (context.Context, trace.Span, *logrusx.Logger)
- func InstrumentNext(ctx context.Context, lp loggerNextProvider, tp tracerProvider, ...) (context.Context, trace.Span, *loggerx.Logger)
- func RecoverWithStackTrace(ctx context.Context, l *loggerx.Logger, msg string)
- func RecoverWithStackTracef(l *logrusx.Logger, msg string, args ...interface{})
- func StackTraceAttrs(recovered any) []attribute.KeyValue
Constants ¶
const ComponentNameSeparator = "."
Variables ¶
This section is empty.
Functions ¶
func ComponentName ¶ added in v0.0.125
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 RecoverWithStackTrace ¶
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
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
Types ¶
This section is empty.