forked from open-telemetry/opentelemetry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelegatingSpan.java
More file actions
164 lines (136 loc) · 4.54 KB
/
DelegatingSpan.java
File metadata and controls
164 lines (136 loc) · 4.54 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.opencensusshim;
import com.google.errorprone.annotations.MustBeClosed;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import java.time.Instant;
import java.util.concurrent.TimeUnit;
/**
* Delegates <i>all</i> {@link Span} methods to some underlying Span via {@link
* DelegatingSpan#getDelegate()}.
*
* <p>If not all calls are proxied, some, such as and in particular {@link
* Span#storeInContext(Context)} and {@link Span#makeCurrent()}, will use {@code this} instead of
* the proxied {@link Span} which betrays the expectation of instance fidelity imposed by the
* underlying otel mechanisms which minted the original {@link Span}, such as the otel javaagent.
*
* <p>This proxy class simplification allows the shim to perform its duties as minimally invasively
* as possible and itself never expose its own classes and objects to callers or recipients of calls
* from the shim.
*
* <p>This addresses the inconsistency where not all methods are appropriately delegated by exposing
* a single method, {@link DelegatingSpan#getDelegate()}, to simplify and better ensure delegation
* and meeting expectations.
*/
interface DelegatingSpan extends Span {
Span getDelegate();
@Override
default Span updateName(String name) {
return getDelegate().updateName(name);
}
@Override
default SpanContext getSpanContext() {
return getDelegate().getSpanContext();
}
@Override
default boolean isRecording() {
return getDelegate().isRecording();
}
@Override
default <T> Span setAttribute(AttributeKey<T> key, T value) {
return getDelegate().setAttribute(key, value);
}
@Override
default Span setAttribute(String key, String value) {
return getDelegate().setAttribute(key, value);
}
@Override
default Span setAttribute(String key, long value) {
return getDelegate().setAttribute(key, value);
}
@Override
default Span setAttribute(String key, double value) {
return getDelegate().setAttribute(key, value);
}
@Override
default Span setAttribute(String key, boolean value) {
return getDelegate().setAttribute(key, value);
}
@Override
default Span setAttribute(AttributeKey<Long> key, int value) {
return getDelegate().setAttribute(key, value);
}
@Override
default Span setAllAttributes(Attributes attributes) {
return getDelegate().setAllAttributes(attributes);
}
@Override
default Span addEvent(String name, Attributes attributes) {
return getDelegate().addEvent(name, attributes);
}
@Override
default Span addEvent(String name, Attributes attributes, long timestamp, TimeUnit unit) {
return getDelegate().addEvent(name, attributes, timestamp, unit);
}
@Override
default Span addEvent(String name) {
return getDelegate().addEvent(name);
}
@Override
default Span addEvent(String name, long timestamp, TimeUnit unit) {
return getDelegate().addEvent(name, timestamp, unit);
}
@Override
default Span addEvent(String name, Instant timestamp) {
return getDelegate().addEvent(name, timestamp);
}
@Override
default Span addEvent(String name, Attributes attributes, Instant timestamp) {
return getDelegate().addEvent(name, attributes, timestamp);
}
@Override
default Span setStatus(StatusCode statusCode, String description) {
return getDelegate().setStatus(statusCode, description);
}
@Override
default Span setStatus(StatusCode statusCode) {
return getDelegate().setStatus(statusCode);
}
@Override
default Span recordException(Throwable exception, Attributes additionalAttributes) {
return getDelegate().recordException(exception, additionalAttributes);
}
@Override
default Span recordException(Throwable exception) {
return getDelegate().recordException(exception);
}
@Override
default void end(Instant timestamp) {
getDelegate().end(timestamp);
}
@Override
default void end() {
getDelegate().end();
}
@Override
default void end(long timestamp, TimeUnit unit) {
getDelegate().end(timestamp, unit);
}
@Override
default Context storeInContext(Context context) {
return getDelegate().storeInContext(context);
}
@MustBeClosed
@Override
default Scope makeCurrent() {
return getDelegate().makeCurrent();
}
}