-
Notifications
You must be signed in to change notification settings - Fork 1
/
span.go
64 lines (52 loc) · 2.2 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package api
import (
"context"
"go.opentelemetry.io/otel/trace"
)
// Span represents a unit of work, performed over a certain period of time.
// You MUST finish all spans you create using the `End` method.
//
// A span supports 2 independent data mechanisms that need to be properly
// propagated across service boundaries for the spans to be captured correctly.
//
// The trace context provides trace information (trace IDs, span IDs, etc.),
// which ensure that all spans for a single request are part of the same trace.
//
// Baggage, which are arbitrary key/value pairs that you can use to pass
// observability data between services (for example, sharing a customer ID from
// one service to the next).
type Span interface {
// End will mark the span as completed. If `err` is not nil, the
// status for the span will be marked as failed.
End(err error)
SpanManaged // inherit "managed" span functionality
}
// SpanManaged represents a unit of work that was initiated by another
// component. You may get a read-only reference to the span to inspect
// it or add additional events to it but you won't be able to close it
// directly.
//
// You can also use the `Context()` of the managed span to initiate child
// tasks of your own.
type SpanManaged interface {
// Context of the span instance. Creating a new span with this context
// will establish a parent -> child relationship.
Context() context.Context
// Unwrap returns the underlying OpenTelemetry span instance.
// Useful for integrating with 3rd party libraries.
Unwrap() trace.Span
// ID returns the span identifier, if any.
ID() string
// TraceID returns the span's parent trace identifier, if any.
TraceID() string
// IsSampled returns if the sampling bit is set in the span context's.
IsSampled() bool
// Event produces a log marker during the execution of the span.
Event(msg string, attributes ...map[string]interface{})
// SetAttribute adjust `key` to report `value` as attribute of the Span.
// If a `key` already exists for an attribute of the Span it will be
// overwritten with `value`.
SetAttribute(key string, value interface{})
// SetAttributes adjust multiple attributes of the Span.
SetAttributes(attributes map[string]interface{})
}