/
span.go
33 lines (29 loc) · 1015 Bytes
/
span.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package telemetry
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
// Encapsulate can be applied to a span to indicate that this span should
// collapse its children by default.
func Encapsulate() trace.SpanStartOption {
return trace.WithAttributes(attribute.Bool(UIEncapsulateAttr, true))
}
// Internal can be applied to a span to indicate that this span should not be
// shown to the user by default.
func Internal() trace.SpanStartOption {
return trace.WithAttributes(attribute.Bool(InternalAttr, true))
}
// End is a helper to end a span with an error if the function returns an error.
//
// It is optimized for use as a defer one-liner with a function that has a
// named error return value, conventionally `rerr`.
//
// defer telemetry.End(span, func() error { return rerr })
func End(span trace.Span, fn func() error) {
if err := fn(); err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
}
span.End()
}