46
46
import io .opentelemetry .api .trace .StatusCode ;
47
47
import java .util .EnumSet ;
48
48
import java .util .Map ;
49
- import java .util .concurrent .TimeUnit ;
50
49
import java .util .logging .Logger ;
51
- import javax .annotation .Nonnull ;
52
50
53
- class OpenTelemetrySpanImpl extends Span implements io .opentelemetry .api .trace .Span {
51
+ class OpenTelemetrySpanImpl extends Span
52
+ implements io .opentelemetry .api .trace .Span , DelegatingSpan {
54
53
private static final Logger LOGGER = Logger .getLogger (OpenTelemetrySpanImpl .class .getName ());
55
54
private static final EnumSet <Span .Options > RECORD_EVENTS_SPAN_OPTIONS =
56
55
EnumSet .of (Span .Options .RECORD_EVENTS );
@@ -62,15 +61,24 @@ class OpenTelemetrySpanImpl extends Span implements io.opentelemetry.api.trace.S
62
61
this .otelSpan = otelSpan ;
63
62
}
64
63
64
+ // otel
65
+
66
+ @ Override
67
+ public io .opentelemetry .api .trace .Span getDelegate () {
68
+ return otelSpan ;
69
+ }
70
+
71
+ // opencensus
72
+
65
73
@ Override
66
74
public void putAttribute (String key , AttributeValue value ) {
67
75
Preconditions .checkNotNull (key , "key" );
68
76
Preconditions .checkNotNull (value , "value" );
69
77
value .match (
70
- arg -> otelSpan .setAttribute (key , arg ),
71
- arg -> otelSpan .setAttribute (key , arg ),
72
- arg -> otelSpan .setAttribute (key , arg ),
73
- arg -> otelSpan .setAttribute (key , arg ),
78
+ arg -> DelegatingSpan . super .setAttribute (key , arg ),
79
+ arg -> DelegatingSpan . super .setAttribute (key , arg ),
80
+ arg -> DelegatingSpan . super .setAttribute (key , arg ),
81
+ arg -> DelegatingSpan . super .setAttribute (key , arg ),
74
82
arg -> null );
75
83
}
76
84
@@ -84,14 +92,14 @@ public void putAttributes(Map<String, AttributeValue> attributes) {
84
92
public void addAnnotation (String description , Map <String , AttributeValue > attributes ) {
85
93
AttributesBuilder attributesBuilder = Attributes .builder ();
86
94
mapAttributes (attributes , attributesBuilder );
87
- otelSpan .addEvent (description , attributesBuilder .build ());
95
+ DelegatingSpan . super .addEvent (description , attributesBuilder .build ());
88
96
}
89
97
90
98
@ Override
91
99
public void addAnnotation (Annotation annotation ) {
92
100
AttributesBuilder attributesBuilder = Attributes .builder ();
93
101
mapAttributes (annotation .getAttributes (), attributesBuilder );
94
- otelSpan .addEvent (annotation .getDescription (), attributesBuilder .build ());
102
+ DelegatingSpan . super .addEvent (annotation .getDescription (), attributesBuilder .build ());
95
103
}
96
104
97
105
@ Override
@@ -101,7 +109,7 @@ public void addLink(Link link) {
101
109
102
110
@ Override
103
111
public void addMessageEvent (MessageEvent messageEvent ) {
104
- otelSpan .addEvent (
112
+ DelegatingSpan . super .addEvent (
105
113
String .valueOf (messageEvent .getMessageId ()),
106
114
Attributes .of (
107
115
AttributeKey .stringKey (MESSAGE_EVENT_ATTRIBUTE_KEY_TYPE ),
@@ -115,70 +123,22 @@ public void addMessageEvent(MessageEvent messageEvent) {
115
123
@ Override
116
124
public void setStatus (Status status ) {
117
125
Preconditions .checkNotNull (status , "status" );
118
- otelSpan .setStatus (status .isOk () ? StatusCode .OK : StatusCode .ERROR );
126
+ DelegatingSpan . super .setStatus (status .isOk () ? StatusCode .OK : StatusCode .ERROR );
119
127
}
120
128
121
129
@ Override
122
130
public io .opentelemetry .api .trace .Span setStatus (StatusCode canonicalCode , String description ) {
123
- return otelSpan .setStatus (canonicalCode , description );
131
+ return DelegatingSpan . super .setStatus (canonicalCode , description );
124
132
}
125
133
126
134
@ Override
127
135
public void end (EndSpanOptions options ) {
128
- otelSpan .end ();
129
- }
130
-
131
- @ Override
132
- @ SuppressWarnings ("ParameterPackage" )
133
- public void end (long timestamp , TimeUnit unit ) {
134
- otelSpan .end (timestamp , unit );
135
- }
136
-
137
- @ Override
138
- public <T > io .opentelemetry .api .trace .Span setAttribute (AttributeKey <T > key , @ Nonnull T value ) {
139
- return otelSpan .setAttribute (key , value );
140
- }
141
-
142
- @ Override
143
- public io .opentelemetry .api .trace .Span addEvent (String name ) {
144
- return otelSpan .addEvent (name );
145
- }
146
-
147
- @ Override
148
- public io .opentelemetry .api .trace .Span addEvent (String name , long timestamp , TimeUnit unit ) {
149
- return otelSpan .addEvent (name , timestamp , unit );
150
- }
151
-
152
- @ Override
153
- public io .opentelemetry .api .trace .Span addEvent (String name , Attributes attributes ) {
154
- return otelSpan .addEvent (name , attributes );
155
- }
156
-
157
- @ Override
158
- public io .opentelemetry .api .trace .Span addEvent (
159
- String name , Attributes attributes , long timestamp , TimeUnit unit ) {
160
- return otelSpan .addEvent (name , attributes , timestamp , unit );
161
- }
162
-
163
- @ Override
164
- public io .opentelemetry .api .trace .Span recordException (Throwable exception ) {
165
- return otelSpan .recordException (exception );
166
- }
167
-
168
- @ Override
169
- public io .opentelemetry .api .trace .Span recordException (
170
- Throwable exception , Attributes additionalAttributes ) {
171
- return otelSpan .recordException (exception , additionalAttributes );
172
- }
173
-
174
- @ Override
175
- public io .opentelemetry .api .trace .Span updateName (String name ) {
176
- return otelSpan .updateName (name );
136
+ DelegatingSpan .super .end ();
177
137
}
178
138
179
139
@ Override
180
140
public SpanContext getSpanContext () {
181
- return otelSpan .getSpanContext ();
141
+ return DelegatingSpan . super .getSpanContext ();
182
142
}
183
143
184
144
@ Override
0 commit comments