|
16 | 16 | import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil;
|
17 | 17 | import io.opentelemetry.instrumentation.api.internal.SupportabilityMetrics;
|
18 | 18 | import java.time.Instant;
|
19 |
| -import java.util.ArrayList; |
20 |
| -import java.util.List; |
21 |
| -import java.util.ListIterator; |
22 | 19 | import java.util.concurrent.TimeUnit;
|
23 | 20 | import javax.annotation.Nullable;
|
24 | 21 |
|
@@ -72,25 +69,25 @@ public static <REQUEST, RESPONSE> InstrumenterBuilder<REQUEST, RESPONSE> builder
|
72 | 69 | private final SpanNameExtractor<? super REQUEST> spanNameExtractor;
|
73 | 70 | private final SpanKindExtractor<? super REQUEST> spanKindExtractor;
|
74 | 71 | private final SpanStatusExtractor<? super REQUEST, ? super RESPONSE> spanStatusExtractor;
|
75 |
| - private final List<? extends SpanLinksExtractor<? super REQUEST>> spanLinksExtractors; |
76 |
| - private final List<? extends AttributesExtractor<? super REQUEST, ? super RESPONSE>> |
77 |
| - attributesExtractors; |
78 |
| - private final List<? extends ContextCustomizer<? super REQUEST>> contextCustomizers; |
79 |
| - private final List<? extends OperationListener> operationListeners; |
| 72 | + private final SpanLinksExtractor<? super REQUEST>[] spanLinksExtractors; |
| 73 | + private final AttributesExtractor<? super REQUEST, ? super RESPONSE>[] attributesExtractors; |
| 74 | + private final ContextCustomizer<? super REQUEST>[] contextCustomizers; |
| 75 | + private final OperationListener[] operationListeners; |
80 | 76 | private final ErrorCauseExtractor errorCauseExtractor;
|
81 | 77 | private final boolean enabled;
|
82 | 78 | private final SpanSuppressor spanSuppressor;
|
83 | 79 |
|
| 80 | + @SuppressWarnings({"rawtypes", "unchecked"}) |
84 | 81 | Instrumenter(InstrumenterBuilder<REQUEST, RESPONSE> builder) {
|
85 | 82 | this.instrumentationName = builder.instrumentationName;
|
86 | 83 | this.tracer = builder.buildTracer();
|
87 | 84 | this.spanNameExtractor = builder.spanNameExtractor;
|
88 | 85 | this.spanKindExtractor = builder.spanKindExtractor;
|
89 | 86 | this.spanStatusExtractor = builder.spanStatusExtractor;
|
90 |
| - this.spanLinksExtractors = new ArrayList<>(builder.spanLinksExtractors); |
91 |
| - this.attributesExtractors = new ArrayList<>(builder.attributesExtractors); |
92 |
| - this.contextCustomizers = new ArrayList<>(builder.contextCustomizers); |
93 |
| - this.operationListeners = builder.buildOperationListeners(); |
| 87 | + this.spanLinksExtractors = builder.spanLinksExtractors.toArray(new SpanLinksExtractor[0]); |
| 88 | + this.attributesExtractors = builder.attributesExtractors.toArray(new AttributesExtractor[0]); |
| 89 | + this.contextCustomizers = builder.contextCustomizers.toArray(new ContextCustomizer[0]); |
| 90 | + this.operationListeners = builder.buildOperationListeners().toArray(new OperationListener[0]); |
94 | 91 | this.errorCauseExtractor = builder.errorCauseExtractor;
|
95 | 92 | this.enabled = builder.enabled;
|
96 | 93 | this.spanSuppressor = builder.buildSpanSuppressor();
|
@@ -193,12 +190,12 @@ private Context doStart(Context parentContext, REQUEST request, @Nullable Instan
|
193 | 190 | Span span = spanBuilder.setParent(context).startSpan();
|
194 | 191 | context = context.with(span);
|
195 | 192 |
|
196 |
| - if (!operationListeners.isEmpty()) { |
| 193 | + if (operationListeners.length != 0) { |
197 | 194 | // operation listeners run after span start, so that they have access to the current span
|
198 | 195 | // for capturing exemplars
|
199 | 196 | long startNanos = getNanos(startTime);
|
200 |
| - for (OperationListener operationListener : operationListeners) { |
201 |
| - context = operationListener.onStart(context, attributes, startNanos); |
| 197 | + for (int i = 0; i < operationListeners.length; i++) { |
| 198 | + context = operationListeners[i].onStart(context, attributes, startNanos); |
202 | 199 | }
|
203 | 200 | }
|
204 | 201 |
|
@@ -231,12 +228,10 @@ private void doEnd(
|
231 | 228 | }
|
232 | 229 | span.setAllAttributes(attributes);
|
233 | 230 |
|
234 |
| - if (!operationListeners.isEmpty()) { |
| 231 | + if (operationListeners.length != 0) { |
235 | 232 | long endNanos = getNanos(endTime);
|
236 |
| - ListIterator<? extends OperationListener> i = |
237 |
| - operationListeners.listIterator(operationListeners.size()); |
238 |
| - while (i.hasPrevious()) { |
239 |
| - i.previous().onEnd(context, attributes, endNanos); |
| 233 | + for (int i = operationListeners.length - 1; i >= 0; i--) { |
| 234 | + operationListeners[i].onEnd(context, attributes, endNanos); |
240 | 235 | }
|
241 | 236 | }
|
242 | 237 |
|
|
0 commit comments