28
28
import io .opentelemetry .instrumentation .api .internal .EmbeddedInstrumentationProperties ;
29
29
import io .opentelemetry .instrumentation .api .internal .InstrumenterBuilderAccess ;
30
30
import io .opentelemetry .instrumentation .api .internal .InstrumenterUtil ;
31
+ import io .opentelemetry .instrumentation .api .internal .InternalInstrumenterCustomizer ;
32
+ import io .opentelemetry .instrumentation .api .internal .InternalInstrumenterCustomizerProvider ;
33
+ import io .opentelemetry .instrumentation .api .internal .InternalInstrumenterCustomizerUtil ;
31
34
import io .opentelemetry .instrumentation .api .internal .SchemaUrlProvider ;
32
35
import io .opentelemetry .instrumentation .api .internal .SpanKey ;
33
36
import io .opentelemetry .instrumentation .api .internal .SpanKeyProvider ;
34
37
import java .util .ArrayList ;
35
38
import java .util .List ;
36
39
import java .util .Set ;
40
+ import java .util .function .Function ;
37
41
import java .util .logging .Logger ;
38
42
import java .util .stream .Collectors ;
39
43
import java .util .stream .Stream ;
40
44
import javax .annotation .Nullable ;
41
45
42
- // copied from OpenTelemetry Instrumentation 2.6 .0
46
+ // copied from OpenTelemetry Instrumentation 2.19 .0
43
47
44
48
/**
45
49
* A builder of an {@link Instrumenter}.
@@ -59,7 +63,7 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
59
63
60
64
final OpenTelemetry openTelemetry ;
61
65
final String instrumentationName ;
62
- final SpanNameExtractor <? super REQUEST > spanNameExtractor ;
66
+ SpanNameExtractor <? super REQUEST > spanNameExtractor ;
63
67
64
68
final List <SpanLinksExtractor <? super REQUEST >> spanLinksExtractors = new ArrayList <>();
65
69
final List <AttributesExtractor <? super REQUEST , ? super RESPONSE >> attributesExtractors =
@@ -293,6 +297,8 @@ public Instrumenter<REQUEST, RESPONSE> buildInstrumenter(
293
297
private Instrumenter <REQUEST , RESPONSE > buildInstrumenter (
294
298
InstrumenterConstructor <REQUEST , RESPONSE > constructor ,
295
299
SpanKindExtractor <? super REQUEST > spanKindExtractor ) {
300
+ applyCustomizers (this );
301
+
296
302
this .spanKindExtractor = spanKindExtractor ;
297
303
return constructor .create (this );
298
304
}
@@ -387,6 +393,49 @@ private void propagateOperationListenersToOnEnd() {
387
393
propagateOperationListenersToOnEnd = true ;
388
394
}
389
395
396
+ private static <REQUEST , RESPONSE > void applyCustomizers (
397
+ InstrumenterBuilder <REQUEST , RESPONSE > builder ) {
398
+ for (InternalInstrumenterCustomizerProvider provider :
399
+ InternalInstrumenterCustomizerUtil .getInstrumenterCustomizerProviders ()) {
400
+ provider .customize (
401
+ new InternalInstrumenterCustomizer <REQUEST , RESPONSE >() {
402
+ @ Override
403
+ public String getInstrumentationName () {
404
+ return builder .instrumentationName ;
405
+ }
406
+
407
+ @ Override
408
+ public void addAttributesExtractor (AttributesExtractor <REQUEST , RESPONSE > extractor ) {
409
+ builder .addAttributesExtractor (extractor );
410
+ }
411
+
412
+ @ Override
413
+ public void addAttributesExtractors (
414
+ Iterable <? extends AttributesExtractor <REQUEST , RESPONSE >> extractors ) {
415
+ builder .addAttributesExtractors (extractors );
416
+ }
417
+
418
+ @ Override
419
+ public void addOperationMetrics (OperationMetrics operationMetrics ) {
420
+ builder .addOperationMetrics (operationMetrics );
421
+ }
422
+
423
+ @ Override
424
+ public void addContextCustomizer (ContextCustomizer <REQUEST > customizer ) {
425
+ builder .addContextCustomizer (customizer );
426
+ }
427
+
428
+ @ Override
429
+ public void setSpanNameExtractor (
430
+ Function <SpanNameExtractor <? super REQUEST >, SpanNameExtractor <? super REQUEST >>
431
+ spanNameExtractorTransformer ) {
432
+ builder .spanNameExtractor =
433
+ spanNameExtractorTransformer .apply (builder .spanNameExtractor );
434
+ }
435
+ });
436
+ }
437
+ }
438
+
390
439
private interface InstrumenterConstructor <RQ , RS > {
391
440
Instrumenter <RQ , RS > create (InstrumenterBuilder <RQ , RS > builder );
392
441
0 commit comments