-
Notifications
You must be signed in to change notification settings - Fork 35
/
dummy_span.go
73 lines (57 loc) · 1.61 KB
/
dummy_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
65
66
67
68
69
70
71
72
73
package tracing
import (
"context"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
)
// DummySpan is used to create a stub span as a placeholder for spans not
// intended for export.
// This is used to selectively disable tracing individual spans based on
// criteria, such as log level.
// Any child spans created from a DummySpan will be linked to the dummy's
// next non-dummy ancestor.
type DummySpan struct {
embedded.Span
// Next non-dummy parent span.
parentSpan trace.Span
}
// newDummySpan creates a dummy span as a child of provided parent span.
func newDummySpan(ctx context.Context) (context.Context, trace.Span) {
span := &DummySpan{
parentSpan: trace.SpanFromContext(ctx),
}
ctx = trace.ContextWithSpan(ctx, span)
return ctx, span
}
func (s *DummySpan) End(options ...trace.SpanEndOption) {
// no-op
}
func (s *DummySpan) AddEvent(name string, options ...trace.EventOption) {
// no-op
}
func (s *DummySpan) IsRecording() bool {
return s.parentSpan.IsRecording()
}
func (s *DummySpan) RecordError(err error, options ...trace.EventOption) {
// no-op
}
func (s *DummySpan) SpanContext() trace.SpanContext {
return s.parentSpan.SpanContext()
}
func (s *DummySpan) SetStatus(code codes.Code, description string) {
// no-op
}
func (s *DummySpan) SetName(name string) {
// no-op
}
func (s *DummySpan) SetAttributes(kv ...attribute.KeyValue) {
// no-op
}
func (s *DummySpan) TracerProvider() trace.TracerProvider {
return s.parentSpan.TracerProvider()
}
func (s *DummySpan) AddLink(trace.Link) {
// no-op
}