-
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathOtelStrongRefSpanWrapper.java
More file actions
318 lines (263 loc) · 8.09 KB
/
OtelStrongRefSpanWrapper.java
File metadata and controls
318 lines (263 loc) · 8.09 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package io.sentry.opentelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.sentry.BaggageHeader;
import io.sentry.IScopes;
import io.sentry.ISentryLifecycleToken;
import io.sentry.ISpan;
import io.sentry.Instrumenter;
import io.sentry.MeasurementUnit;
import io.sentry.SentryDate;
import io.sentry.SentryTraceHeader;
import io.sentry.SpanContext;
import io.sentry.SpanOptions;
import io.sentry.SpanStatus;
import io.sentry.TraceContext;
import io.sentry.TracesSamplingDecision;
import io.sentry.protocol.Contexts;
import io.sentry.protocol.MeasurementValue;
import io.sentry.protocol.SentryId;
import io.sentry.protocol.TransactionNameSource;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* This holds a strong reference to the OpenTelemetry span, preventing it from being garbage
* collected.
*
* <p>IMPORTANT: Only use this carefully. Please read below.
*
* <p>This class should only be used in cases where Sentry SDK is used to create an OpenTelemetry
* span under the hood that no one holds a reference to otherwise.
*
* <p>e.g. ITransaction transaction = Sentry.startTransaction(...) Sentry creates an OTel span under
* the hood, but no one would reference it unless this class is used and returned to the user. By
* doing this, we tie the OTel span to the returned Sentry span/transaction which the user can hold
* on to.
*/
@ApiStatus.Internal
public final class OtelStrongRefSpanWrapper implements IOtelSpanWrapper {
@SuppressWarnings("UnusedVariable")
private final @NotNull Span otelSpan;
private final @NotNull IOtelSpanWrapper delegate;
public OtelStrongRefSpanWrapper(@NotNull Span otelSpan, @NotNull IOtelSpanWrapper delegate) {
this.otelSpan = otelSpan;
this.delegate = delegate;
}
@Override
public void setTransactionName(@NotNull String name) {
delegate.setTransactionName(name);
}
@Override
public void setTransactionName(@NotNull String name, @NotNull TransactionNameSource nameSource) {
delegate.setTransactionName(name, nameSource);
}
@Override
public @Nullable TransactionNameSource getTransactionNameSource() {
return delegate.getTransactionNameSource();
}
@Override
public @Nullable String getTransactionName() {
return delegate.getTransactionName();
}
@Override
public @NotNull SentryId getTraceId() {
return delegate.getTraceId();
}
@Override
public @NotNull Map<String, Object> getData() {
return delegate.getData();
}
@Override
public @NotNull Map<String, MeasurementValue> getMeasurements() {
return delegate.getMeasurements();
}
@Override
public @Nullable Boolean isProfileSampled() {
return delegate.isProfileSampled();
}
@Override
public @NotNull IScopes getScopes() {
return delegate.getScopes();
}
@Override
public @NotNull Map<String, String> getTags() {
return delegate.getTags();
}
@Override
public @NotNull Context storeInContext(Context context) {
return delegate.storeInContext(context);
}
@Override
public @NotNull ISpan startChild(@NotNull String operation) {
return delegate.startChild(operation);
}
@Override
public @NotNull ISpan startChild(
@NotNull String operation, @Nullable String description, @NotNull SpanOptions spanOptions) {
return delegate.startChild(operation, description, spanOptions);
}
@Override
public @NotNull ISpan startChild(
@NotNull SpanContext spanContext, @NotNull SpanOptions spanOptions) {
return delegate.startChild(spanContext, spanOptions);
}
@Override
public @NotNull ISpan startChild(
@NotNull String operation,
@Nullable String description,
@Nullable SentryDate timestamp,
@NotNull Instrumenter instrumenter) {
return delegate.startChild(operation, description, timestamp, instrumenter);
}
@Override
public @NotNull ISpan startChild(
@NotNull String operation,
@Nullable String description,
@Nullable SentryDate timestamp,
@NotNull Instrumenter instrumenter,
@NotNull SpanOptions spanOptions) {
return delegate.startChild(operation, description, timestamp, instrumenter, spanOptions);
}
@Override
public @NotNull ISpan startChild(@NotNull String operation, @Nullable String description) {
return delegate.startChild(operation, description);
}
@Override
public @NotNull SentryTraceHeader toSentryTrace() {
return delegate.toSentryTrace();
}
@Override
public @Nullable TraceContext traceContext() {
return delegate.traceContext();
}
@Override
public @Nullable BaggageHeader toBaggageHeader(@Nullable List<String> thirdPartyBaggageHeaders) {
return delegate.toBaggageHeader(thirdPartyBaggageHeaders);
}
@Override
public void finish() {
delegate.finish();
}
@Override
public void finish(@Nullable SpanStatus status) {
delegate.finish(status);
}
@Override
public void finish(@Nullable SpanStatus status, @Nullable SentryDate timestamp) {
delegate.finish(status, timestamp);
}
@Override
public void setOperation(@NotNull String operation) {
delegate.setOperation(operation);
}
@Override
public @NotNull String getOperation() {
return delegate.getOperation();
}
@Override
public void setDescription(@Nullable String description) {
delegate.setDescription(description);
}
@Override
public @Nullable String getDescription() {
return delegate.getDescription();
}
@Override
public void setStatus(@Nullable SpanStatus status) {
delegate.setStatus(status);
}
@Override
public @Nullable SpanStatus getStatus() {
return delegate.getStatus();
}
@Override
public void setThrowable(@Nullable Throwable throwable) {
delegate.setThrowable(throwable);
}
@Override
public @Nullable Throwable getThrowable() {
return delegate.getThrowable();
}
@Override
public @NotNull SpanContext getSpanContext() {
return delegate.getSpanContext();
}
@Override
public void setTag(@Nullable String key, @Nullable String value) {
delegate.setTag(key, value);
}
@Override
public @Nullable String getTag(@Nullable String key) {
return delegate.getTag(key);
}
@Override
public boolean isFinished() {
return delegate.isFinished();
}
@Override
public void setData(@Nullable String key, @Nullable Object value) {
delegate.setData(key, value);
}
@Override
public @Nullable Object getData(@Nullable String key) {
return delegate.getData(key);
}
@Override
public void setMeasurement(@NotNull String name, @NotNull Number value) {
delegate.setMeasurement(name, value);
}
@Override
public void setMeasurement(
@NotNull String name, @NotNull Number value, @NotNull MeasurementUnit unit) {
delegate.setMeasurement(name, value, unit);
}
@Override
public boolean updateEndDate(@NotNull SentryDate date) {
return delegate.updateEndDate(date);
}
@Override
public @NotNull SentryDate getStartDate() {
return delegate.getStartDate();
}
@Override
public @Nullable SentryDate getFinishDate() {
return delegate.getFinishDate();
}
@Override
public boolean isNoOp() {
return delegate.isNoOp();
}
@Override
public void setContext(@Nullable String key, @Nullable Object context) {
delegate.setContext(key, context);
}
@Override
public @NotNull Contexts getContexts() {
return delegate.getContexts();
}
@Override
public @Nullable Boolean isSampled() {
return delegate.isSampled();
}
@Override
public @Nullable TracesSamplingDecision getSamplingDecision() {
return delegate.getSamplingDecision();
}
@Override
public @NotNull ISentryLifecycleToken makeCurrent() {
return delegate.makeCurrent();
}
@ApiStatus.Internal
@Override
public @Nullable Attributes getOpenTelemetrySpanAttributes() {
return delegate.getOpenTelemetrySpanAttributes();
}
@Override
public void addFeatureFlag(final @Nullable String flag, final @Nullable Boolean result) {
delegate.addFeatureFlag(flag, result);
}
}