Skip to content

Commit 1651163

Browse files
committed
address review comment
1 parent 9bbffc0 commit 1651163

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Instrumenter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static <REQUEST, RESPONSE> InstrumenterBuilder<REQUEST, RESPONSE> builder
7979
private final ContextCustomizer<? super REQUEST>[] contextCustomizers;
8080
private final OperationListener[] operationListeners;
8181
private final AttributesExtractor<? super REQUEST, ? super RESPONSE>[]
82-
operationAttributesExtractors;
82+
operationListenerAttributesExtractors;
8383
private final ErrorCauseExtractor errorCauseExtractor;
8484
private final boolean propagateOperationListenersToOnEnd;
8585
private final boolean enabled;
@@ -96,8 +96,8 @@ public static <REQUEST, RESPONSE> InstrumenterBuilder<REQUEST, RESPONSE> builder
9696
this.attributesExtractors = builder.attributesExtractors.toArray(new AttributesExtractor[0]);
9797
this.contextCustomizers = builder.contextCustomizers.toArray(new ContextCustomizer[0]);
9898
this.operationListeners = builder.buildOperationListeners().toArray(new OperationListener[0]);
99-
this.operationAttributesExtractors =
100-
builder.operationAttributesExtractors.toArray(new AttributesExtractor[0]);
99+
this.operationListenerAttributesExtractors =
100+
builder.operationListenerAttributesExtractors.toArray(new AttributesExtractor[0]);
101101
this.errorCauseExtractor = builder.errorCauseExtractor;
102102
this.propagateOperationListenersToOnEnd = builder.propagateOperationListenersToOnEnd;
103103
this.enabled = builder.enabled;
@@ -211,11 +211,11 @@ private Context doStartImpl(Context parentContext, REQUEST request, @Nullable In
211211
context = context.with(span);
212212

213213
if (operationListeners.length != 0) {
214-
if (operationAttributesExtractors.length != 0) {
214+
if (operationListenerAttributesExtractors.length != 0) {
215215
UnsafeAttributes operationAttributes = new UnsafeAttributes();
216216
operationAttributes.putAll(attributes.asMap());
217217
for (AttributesExtractor<? super REQUEST, ? super RESPONSE> extractor :
218-
operationAttributesExtractors) {
218+
operationListenerAttributesExtractors) {
219219
extractor.onStart(operationAttributes, parentContext, request);
220220
}
221221
attributes = operationAttributes;
@@ -272,11 +272,11 @@ private void doEnd(
272272
operationListeners = this.operationListeners;
273273
}
274274
if (operationListeners.length != 0) {
275-
if (operationAttributesExtractors.length != 0) {
275+
if (operationListenerAttributesExtractors.length != 0) {
276276
UnsafeAttributes operationAttributes = new UnsafeAttributes();
277277
operationAttributes.putAll(attributes.asMap());
278278
for (AttributesExtractor<? super REQUEST, ? super RESPONSE> extractor :
279-
operationAttributesExtractors) {
279+
operationListenerAttributesExtractors) {
280280
extractor.onEnd(operationAttributes, context, request, response, error);
281281
}
282282
attributes = operationAttributes;

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBuilder.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
6161
final List<SpanLinksExtractor<? super REQUEST>> spanLinksExtractors = new ArrayList<>();
6262
final List<AttributesExtractor<? super REQUEST, ? super RESPONSE>> attributesExtractors =
6363
new ArrayList<>();
64-
final List<AttributesExtractor<? super REQUEST, ? super RESPONSE>> operationAttributesExtractors =
65-
new ArrayList<>();
64+
final List<AttributesExtractor<? super REQUEST, ? super RESPONSE>>
65+
operationListenerAttributesExtractors = new ArrayList<>();
6666
final List<ContextCustomizer<? super REQUEST>> contextCustomizers = new ArrayList<>();
6767
private final List<OperationListener> operationListeners = new ArrayList<>();
6868
private final List<OperationMetrics> operationMetrics = new ArrayList<>();
@@ -77,10 +77,11 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
7777
boolean enabled = true;
7878

7979
{
80-
Experimental.internalAddOperationAttributesExtractor(
81-
(builder, operationAttributesExtractor) ->
82-
this.operationAttributesExtractors.add(
83-
requireNonNull(operationAttributesExtractor, "operationAttributesExtractor")));
80+
Experimental.internalAddOperationListenerAttributesExtractor(
81+
(builder, operationListenerAttributesExtractor) ->
82+
this.operationListenerAttributesExtractors.add(
83+
requireNonNull(
84+
operationListenerAttributesExtractor, "operationListenerAttributesExtractor")));
8485
}
8586

8687
InstrumenterBuilder(

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/Experimental.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public final class Experimental {
3030

3131
@Nullable
3232
private static volatile BiConsumer<InstrumenterBuilder<?, ?>, AttributesExtractor<?, ?>>
33-
operationAttributesExtractorAdder;
33+
operationListenerAttributesExtractorAdder;
3434

3535
private Experimental() {}
3636

@@ -68,20 +68,21 @@ public static <REQUEST> void internalSetUrlTemplateExtractor(
6868
* attributes to the metrics without adding them to the span. To add attributes to the span use
6969
* {@link InstrumenterBuilder#addAttributesExtractor(AttributesExtractor)}.
7070
*/
71-
public static <REQUEST, RESPONSE> void addOperationAttributesExtractor(
71+
public static <REQUEST, RESPONSE> void addOperationListenerAttributesExtractor(
7272
InstrumenterBuilder<REQUEST, RESPONSE> builder,
7373
AttributesExtractor<? super REQUEST, ? super RESPONSE> attributesExtractor) {
74-
if (operationAttributesExtractorAdder != null) {
75-
operationAttributesExtractorAdder.accept(builder, attributesExtractor);
74+
if (operationListenerAttributesExtractorAdder != null) {
75+
operationListenerAttributesExtractorAdder.accept(builder, attributesExtractor);
7676
}
7777
}
7878

7979
@SuppressWarnings({"rawtypes", "unchecked"})
80-
public static <REQUEST, RESPONSE> void internalAddOperationAttributesExtractor(
80+
public static <REQUEST, RESPONSE> void internalAddOperationListenerAttributesExtractor(
8181
BiConsumer<
8282
InstrumenterBuilder<REQUEST, RESPONSE>,
8383
AttributesExtractor<? super REQUEST, ? super RESPONSE>>
84-
operationAttributesExtractorAdder) {
85-
Experimental.operationAttributesExtractorAdder = (BiConsumer) operationAttributesExtractorAdder;
84+
operationListenerAttributesExtractorAdder) {
85+
Experimental.operationListenerAttributesExtractorAdder =
86+
(BiConsumer) operationListenerAttributesExtractorAdder;
8687
}
8788
}

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
528528
otelTesting.getOpenTelemetry(), "test", unused -> "span")
529529
.addOperationListener(operationListener)
530530
.addAttributesExtractor(new AttributesExtractor1());
531-
Experimental.addOperationAttributesExtractor(builder, new AttributesExtractor2());
531+
Experimental.addOperationListenerAttributesExtractor(builder, new AttributesExtractor2());
532532
Instrumenter<Map<String, String>, Map<String, String>> instrumenter =
533533
builder.buildServerInstrumenter(new MapGetter());
534534

0 commit comments

Comments
 (0)