4646import io .opentelemetry .api .trace .StatusCode ;
4747import java .util .EnumSet ;
4848import java .util .Map ;
49- import java .util .concurrent .TimeUnit ;
5049import java .util .logging .Logger ;
51- import javax .annotation .Nonnull ;
5250
53- class OpenTelemetrySpanImpl extends Span implements io .opentelemetry .api .trace .Span {
51+ class OpenTelemetrySpanImpl extends Span
52+ implements io .opentelemetry .api .trace .Span , DelegatingSpan {
5453 private static final Logger LOGGER = Logger .getLogger (OpenTelemetrySpanImpl .class .getName ());
5554 private static final EnumSet <Span .Options > RECORD_EVENTS_SPAN_OPTIONS =
5655 EnumSet .of (Span .Options .RECORD_EVENTS );
@@ -62,15 +61,24 @@ class OpenTelemetrySpanImpl extends Span implements io.opentelemetry.api.trace.S
6261 this .otelSpan = otelSpan ;
6362 }
6463
64+ // otel
65+
66+ @ Override
67+ public io .opentelemetry .api .trace .Span getDelegate () {
68+ return otelSpan ;
69+ }
70+
71+ // opencensus
72+
6573 @ Override
6674 public void putAttribute (String key , AttributeValue value ) {
6775 Preconditions .checkNotNull (key , "key" );
6876 Preconditions .checkNotNull (value , "value" );
6977 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 ),
7482 arg -> null );
7583 }
7684
@@ -84,14 +92,14 @@ public void putAttributes(Map<String, AttributeValue> attributes) {
8492 public void addAnnotation (String description , Map <String , AttributeValue > attributes ) {
8593 AttributesBuilder attributesBuilder = Attributes .builder ();
8694 mapAttributes (attributes , attributesBuilder );
87- otelSpan .addEvent (description , attributesBuilder .build ());
95+ DelegatingSpan . super .addEvent (description , attributesBuilder .build ());
8896 }
8997
9098 @ Override
9199 public void addAnnotation (Annotation annotation ) {
92100 AttributesBuilder attributesBuilder = Attributes .builder ();
93101 mapAttributes (annotation .getAttributes (), attributesBuilder );
94- otelSpan .addEvent (annotation .getDescription (), attributesBuilder .build ());
102+ DelegatingSpan . super .addEvent (annotation .getDescription (), attributesBuilder .build ());
95103 }
96104
97105 @ Override
@@ -101,7 +109,7 @@ public void addLink(Link link) {
101109
102110 @ Override
103111 public void addMessageEvent (MessageEvent messageEvent ) {
104- otelSpan .addEvent (
112+ DelegatingSpan . super .addEvent (
105113 String .valueOf (messageEvent .getMessageId ()),
106114 Attributes .of (
107115 AttributeKey .stringKey (MESSAGE_EVENT_ATTRIBUTE_KEY_TYPE ),
@@ -115,70 +123,22 @@ public void addMessageEvent(MessageEvent messageEvent) {
115123 @ Override
116124 public void setStatus (Status status ) {
117125 Preconditions .checkNotNull (status , "status" );
118- otelSpan .setStatus (status .isOk () ? StatusCode .OK : StatusCode .ERROR );
126+ DelegatingSpan . super .setStatus (status .isOk () ? StatusCode .OK : StatusCode .ERROR );
119127 }
120128
121129 @ Override
122130 public io .opentelemetry .api .trace .Span setStatus (StatusCode canonicalCode , String description ) {
123- return otelSpan .setStatus (canonicalCode , description );
131+ return DelegatingSpan . super .setStatus (canonicalCode , description );
124132 }
125133
126134 @ Override
127135 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 ();
177137 }
178138
179139 @ Override
180140 public SpanContext getSpanContext () {
181- return otelSpan .getSpanContext ();
141+ return DelegatingSpan . super .getSpanContext ();
182142 }
183143
184144 @ Override
0 commit comments