forked from open-telemetry/opentelemetry-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDefaultTracer.java
More file actions
123 lines (98 loc) · 2.78 KB
/
DefaultTracer.java
File metadata and controls
123 lines (98 loc) · 2.78 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.api.trace;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.internal.ApiUsageLogger;
import io.opentelemetry.context.Context;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
/** No-op implementation of {@link Tracer}. */
@ThreadSafe
final class DefaultTracer implements Tracer {
private static final Tracer INSTANCE = new DefaultTracer();
static Tracer getInstance() {
return INSTANCE;
}
@Override
public boolean isEnabled() {
return false;
}
@Override
public SpanBuilder spanBuilder(String spanName) {
return NoopSpanBuilder.create();
}
private DefaultTracer() {}
// Noop implementation of Span.Builder.
private static final class NoopSpanBuilder implements SpanBuilder {
static NoopSpanBuilder create() {
return new NoopSpanBuilder();
}
@Nullable private SpanContext spanContext;
@Override
public Span startSpan() {
if (spanContext == null) {
spanContext = Span.current().getSpanContext();
}
return Span.wrap(spanContext);
}
@Override
public NoopSpanBuilder setParent(Context context) {
if (context == null) {
ApiUsageLogger.log("context is null");
return this;
}
spanContext = Span.fromContext(context).getSpanContext();
return this;
}
@Override
public NoopSpanBuilder setNoParent() {
spanContext = SpanContext.getInvalid();
return this;
}
@Override
public NoopSpanBuilder addLink(SpanContext spanContext) {
return this;
}
@Override
public NoopSpanBuilder addLink(SpanContext spanContext, Attributes attributes) {
return this;
}
@Override
public NoopSpanBuilder setAttribute(String key, @Nullable String value) {
return this;
}
@Override
public NoopSpanBuilder setAttribute(String key, long value) {
return this;
}
@Override
public NoopSpanBuilder setAttribute(String key, double value) {
return this;
}
@Override
public NoopSpanBuilder setAttribute(String key, boolean value) {
return this;
}
@Override
public <T> NoopSpanBuilder setAttribute(AttributeKey<T> key, @Nullable T value) {
return this;
}
@Override
public NoopSpanBuilder setAllAttributes(Attributes attributes) {
return this;
}
@Override
public NoopSpanBuilder setSpanKind(SpanKind spanKind) {
return this;
}
@Override
public NoopSpanBuilder setStartTimestamp(long startTimestamp, TimeUnit unit) {
return this;
}
private NoopSpanBuilder() {}
}
}