allow skipping callstack in errors and events

This commit is contained in:
Natalia Goc 2024-05-20 13:39:55 +02:00
parent c70a285e70
commit f5819972a4
3 changed files with 13 additions and 3 deletions

View File

@ -47,6 +47,11 @@ func (e Event) AsOpts() trace.EventOption {
return trace.WithAttributes(e.IntoTraceAttributes()...) return trace.WithAttributes(e.IntoTraceAttributes()...)
} }
func (e Event) SkipMoreInCallStack(skip int) Event {
e.extraSkipInStack += skip
return e
}
func NewInSpan[E IntoEvent](ev E, span trace.Span) { func NewInSpan[E IntoEvent](ev E, span trace.Span) {
event := ev.IntoEvent() event := ev.IntoEvent()
event.extraSkipInStack += 1 event.extraSkipInStack += 1
@ -93,6 +98,11 @@ func (e Error) AsOpts() trace.EventOption {
return trace.WithAttributes(e.IntoTraceAttributes()...) return trace.WithAttributes(e.IntoTraceAttributes()...)
} }
func (e Error) SkipMoreInCallStack(skip int) Error {
e.extraSkipInStack += skip
return e
}
func NewErrInSpan[E IntoErrorEvent](err E, span trace.Span) E { func NewErrInSpan[E IntoErrorEvent](err E, span trace.Span) E {
er := err.IntoErrorEvent() er := err.IntoErrorEvent()
er.extraSkipInStack += 1 er.extraSkipInStack += 1

View File

@ -79,10 +79,10 @@ func NewProcessor(opts ProcessorOptions) trace.SpanProcessor {
fmt := NewPrettyMultilineFormatter() fmt := NewPrettyMultilineFormatter()
formatter = fmt formatter = fmt
} }
if opts.FilterOnLevel != 0 { if opts.FilterOnLevel != level.SeverityLevel(0) {
lvl = opts.FilterOnLevel lvl = opts.FilterOnLevel
} else { } else {
lvl = level.TRACE + 10 lvl = level.TRACE + 1
} }
return &Processor{ return &Processor{

View File

@ -77,7 +77,7 @@ func FromString(level string) SeverityLevel {
case "TRACE": case "TRACE":
return TRACE return TRACE
default: default:
return CRIT return unset
} }
} }