Skip to content

Commit 35da705

Browse files
committed
Add necessary description of classes
1 parent 5531d16 commit 35da705

File tree

8 files changed

+147
-72
lines changed

8 files changed

+147
-72
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
Comparing source compatibility of opentelemetry-instrumentation-api-2.17.0-SNAPSHOT.jar against opentelemetry-instrumentation-api-2.16.0.jar
2-
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.instrumenter.ConditionalAttributesExtractorProvider (not serializable)
2+
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractorCustomizer (not serializable)
33
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
44
+++ NEW SUPERCLASS: java.lang.Object
55
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor<REQUEST,RESPONSE> get()
66
GENERIC TEMPLATES: +++ REQUEST:java.lang.Object, +++ RESPONSE:java.lang.Object
7-
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.List<java.lang.String> supportedNames()
8-
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.instrumenter.ConditionalContextCustomizerProvider (not serializable)
7+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.List<java.lang.String> instrumentationNames()
8+
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.instrumenter.ContextCustomizerCustomizer (not serializable)
99
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
1010
+++ NEW SUPERCLASS: java.lang.Object
1111
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.instrumenter.ContextCustomizer<REQUEST> get()
1212
GENERIC TEMPLATES: +++ REQUEST:java.lang.Object
13-
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.List<java.lang.String> supportedNames()
14-
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.instrumenter.ConditionalOperationMetricsProvider (not serializable)
13+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.List<java.lang.String> instrumentationNames()
14+
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.instrumenter.OperationMetricsCustomizer (not serializable)
1515
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
1616
+++ NEW SUPERCLASS: java.lang.Object
1717
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics get()
18-
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.List<java.lang.String> supportedNames()
18+
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.List<java.lang.String> instrumentationNames()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.api.instrumenter;
7+
8+
import java.util.List;
9+
10+
/**
11+
* A service provider interface (SPI) for providing {@link AttributesExtractorCustomizer} instances
12+
* that are conditionally applied based on the instrumentation name.
13+
*
14+
* <p>This allows external modules or plugins to contribute custom attribute extraction logic for
15+
* specific instrumented libraries, without modifying core instrumentation code.
16+
*/
17+
public interface AttributesExtractorCustomizer {
18+
/**
19+
* Returns a list of instrumentation names that this customizer supports.
20+
*
21+
* <p>The customizer will only be applied if the current instrumentation matches one of the
22+
* returned names. For example: ["io.opentelemetry.netty-3.8",
23+
* "io.opentelemetry.apache-httpclient-4.3"].
24+
*
25+
* @return a list of supported instrumentation names
26+
*/
27+
List<String> instrumentationNames();
28+
29+
/**
30+
* Returns a new instance of an {@link AttributesExtractor} that will extract attributes from
31+
* requests and responses during the instrumentation process.
32+
*
33+
* @param <REQUEST> the type of request object used by the instrumented library
34+
* @param <RESPONSE> the type of response object used by the instrumented library
35+
* @return an attributes extractor instance
36+
*/
37+
<REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> get();
38+
}

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

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.api.instrumenter;
7+
8+
import java.util.List;
9+
10+
/**
11+
* A service provider interface (SPI) for providing custom {@link ContextCustomizer} implementations
12+
* that are conditionally applied based on the instrumentation name.
13+
*
14+
* <p>This allows external modules or plugins to customize context propagation and initialization
15+
* logic for specific instrumented libraries, without modifying core instrumentation code.
16+
*/
17+
public interface ContextCustomizerCustomizer {
18+
19+
/**
20+
* Returns a list of instrumentation names that this customizer supports.
21+
*
22+
* <p>The customizer will only be applied if the current instrumentation matches one of the
23+
* returned names. For example: ["io.opentelemetry.netty-3.8",
24+
* "io.opentelemetry.apache-httpclient-4.3"].
25+
*
26+
* @return a list of supported instrumentation names
27+
*/
28+
List<String> instrumentationNames();
29+
30+
/**
31+
* Returns a new instance of a {@link ContextCustomizer} that will customize the tracing context
32+
* during request processing.
33+
*
34+
* @param <REQUEST> the type of request object used by the instrumented library
35+
* @return a context customizer instance
36+
*/
37+
<REQUEST> ContextCustomizer<REQUEST> get();
38+
}

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

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,37 +72,41 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
7272
boolean propagateOperationListenersToOnEnd = false;
7373
boolean enabled = true;
7474

75-
private static final Map<String, List<ConditionalContextCustomizerProvider>>
76-
CONTEXT_CUSTOMIZER_MAP = new HashMap<>();
77-
private static final Map<String, List<ConditionalAttributesExtractorProvider>>
78-
ATTRIBUTES_EXTRACTOR_MAP = new HashMap<>();
79-
private static final Map<String, List<ConditionalOperationMetricsProvider>>
80-
OPERATION_METRICS_MAP = new HashMap<>();
75+
private static final Map<String, List<ContextCustomizerCustomizer>> CONTEXT_CUSTOMIZER_MAP =
76+
new HashMap<>();
77+
private static final Map<String, List<AttributesExtractorCustomizer>> ATTRIBUTES_EXTRACTOR_MAP =
78+
new HashMap<>();
79+
private static final Map<String, List<OperationMetricsCustomizer>> OPERATION_METRICS_MAP =
80+
new HashMap<>();
8181

8282
static {
83-
ServiceLoader.load(ConditionalContextCustomizerProvider.class)
83+
ServiceLoader.load(ContextCustomizerCustomizer.class)
8484
.forEach(
85-
provider -> {
86-
for (String name : provider.supportedNames()) {
87-
CONTEXT_CUSTOMIZER_MAP.computeIfAbsent(name, k -> new ArrayList<>()).add(provider);
85+
customizers -> {
86+
for (String name : customizers.instrumentationNames()) {
87+
CONTEXT_CUSTOMIZER_MAP
88+
.computeIfAbsent(name, k -> new ArrayList<>())
89+
.add(customizers);
8890
}
8991
});
9092

91-
ServiceLoader.load(ConditionalAttributesExtractorProvider.class)
93+
ServiceLoader.load(AttributesExtractorCustomizer.class)
9294
.forEach(
93-
provider -> {
94-
for (String name : provider.supportedNames()) {
95+
customizers -> {
96+
for (String name : customizers.instrumentationNames()) {
9597
ATTRIBUTES_EXTRACTOR_MAP
9698
.computeIfAbsent(name, k -> new ArrayList<>())
97-
.add(provider);
99+
.add(customizers);
98100
}
99101
});
100102

101-
ServiceLoader.load(ConditionalOperationMetricsProvider.class)
103+
ServiceLoader.load(OperationMetricsCustomizer.class)
102104
.forEach(
103-
provider -> {
104-
for (String name : provider.supportedNames()) {
105-
OPERATION_METRICS_MAP.computeIfAbsent(name, k -> new ArrayList<>()).add(provider);
105+
customizers -> {
106+
for (String name : customizers.instrumentationNames()) {
107+
OPERATION_METRICS_MAP
108+
.computeIfAbsent(name, k -> new ArrayList<>())
109+
.add(customizers);
106110
}
107111
});
108112
}
@@ -117,26 +121,26 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
117121
this.instrumentationVersion =
118122
EmbeddedInstrumentationProperties.findVersion(instrumentationName);
119123

120-
List<ConditionalContextCustomizerProvider> contextProviders =
124+
List<ContextCustomizerCustomizer> contextProviders =
121125
CONTEXT_CUSTOMIZER_MAP.get(instrumentationName);
122126
if (contextProviders != null) {
123-
for (ConditionalContextCustomizerProvider provider : contextProviders) {
127+
for (ContextCustomizerCustomizer provider : contextProviders) {
124128
addContextCustomizer(provider.get());
125129
}
126130
}
127131

128-
List<ConditionalAttributesExtractorProvider> attributeProviders =
132+
List<AttributesExtractorCustomizer> attributeProviders =
129133
ATTRIBUTES_EXTRACTOR_MAP.get(instrumentationName);
130134
if (attributeProviders != null) {
131-
for (ConditionalAttributesExtractorProvider provider : attributeProviders) {
135+
for (AttributesExtractorCustomizer provider : attributeProviders) {
132136
addAttributesExtractor(provider.get());
133137
}
134138
}
135139

136-
List<ConditionalOperationMetricsProvider> metricsProviders =
140+
List<OperationMetricsCustomizer> metricsProviders =
137141
OPERATION_METRICS_MAP.get(instrumentationName);
138142
if (metricsProviders != null) {
139-
for (ConditionalOperationMetricsProvider provider : metricsProviders) {
143+
for (OperationMetricsCustomizer provider : metricsProviders) {
140144
addOperationMetrics(provider.get());
141145
}
142146
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.api.instrumenter;
7+
8+
import java.util.List;
9+
10+
/**
11+
* A service provider interface (SPI) for providing custom {@link OperationMetrics} instances that
12+
* are conditionally applied based on the instrumentation name.
13+
*
14+
* <p>This allows external modules or plugins to contribute custom metrics collection logic for
15+
* specific instrumented operations, without modifying core instrumentation code.
16+
*/
17+
public interface OperationMetricsCustomizer {
18+
19+
/**
20+
* Returns a list of instrumentation names that this metrics customizer supports.
21+
*
22+
* <p>The customizer will only be applied if the current instrumentation matches one of the
23+
* returned names. For example: ["io.opentelemetry.spring-webmvc-5.0",
24+
* "io.opentelemetry.netty-3.8"].
25+
*
26+
* @return a list of supported instrumentation names
27+
*/
28+
List<String> instrumentationNames();
29+
30+
/**
31+
* Returns a new instance of an {@link OperationMetrics} that will record metrics for the
32+
* instrumented operation.
33+
*
34+
* @return an operation metrics instance
35+
*/
36+
OperationMetrics get();
37+
}

0 commit comments

Comments
 (0)