-
Notifications
You must be signed in to change notification settings - Fork 828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instrumenter instrumentation version and schema url #5752
Merged
mateuszrzeszutek
merged 9 commits into
open-telemetry:main
from
mateuszrzeszutek:instrumentation-version-schema
Apr 11, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dbf3a2d
Instrumenter instrumentation version and schema url
23453b7
nullable instrumentation version
bc4cb4a
Apply suggestions from code review
430ed7e
reformat
39db85f
code review comments
b07ec24
instrumentation properties files
7d27f7a
Apply suggestions from code review
1005fac
code review comments
0d86059
Apply suggestions from code review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,16 @@ | |
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.api.metrics.Meter; | ||
import io.opentelemetry.api.metrics.MeterBuilder; | ||
import io.opentelemetry.api.trace.SpanKind; | ||
import io.opentelemetry.api.trace.StatusCode; | ||
import io.opentelemetry.api.trace.Tracer; | ||
import io.opentelemetry.api.trace.TracerBuilder; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.propagation.TextMapGetter; | ||
import io.opentelemetry.context.propagation.TextMapSetter; | ||
import io.opentelemetry.instrumentation.api.annotations.UnstableApi; | ||
import io.opentelemetry.instrumentation.api.config.Config; | ||
import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties; | ||
import io.opentelemetry.instrumentation.api.internal.SpanKey; | ||
import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider; | ||
import java.util.ArrayList; | ||
|
@@ -39,17 +42,18 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> { | |
.getBoolean("otel.instrumentation.experimental.outgoing-span-suppression-by-type", false); | ||
|
||
final OpenTelemetry openTelemetry; | ||
final Meter meter; | ||
final String instrumentationName; | ||
final String instrumentationVersion; | ||
final SpanNameExtractor<? super REQUEST> spanNameExtractor; | ||
|
||
final List<SpanLinksExtractor<? super REQUEST>> spanLinksExtractors = new ArrayList<>(); | ||
final List<AttributesExtractor<? super REQUEST, ? super RESPONSE>> attributesExtractors = | ||
new ArrayList<>(); | ||
final List<ContextCustomizer<? super REQUEST>> contextCustomizers = new ArrayList<>(); | ||
final List<RequestListener> requestListeners = new ArrayList<>(); | ||
private final List<RequestListener> requestListeners = new ArrayList<>(); | ||
private final List<RequestMetrics> requestMetrics = new ArrayList<>(); | ||
|
||
@Nullable private String instrumentationVersion; | ||
@Nullable private String schemaUrl = null; | ||
SpanKindExtractor<? super REQUEST> spanKindExtractor = SpanKindExtractor.alwaysInternal(); | ||
SpanStatusExtractor<? super REQUEST, ? super RESPONSE> spanStatusExtractor = | ||
SpanStatusExtractor.getDefault(); | ||
|
@@ -62,13 +66,34 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> { | |
InstrumenterBuilder( | ||
OpenTelemetry openTelemetry, | ||
String instrumentationName, | ||
String instrumentationVersion, | ||
SpanNameExtractor<? super REQUEST> spanNameExtractor) { | ||
this.openTelemetry = openTelemetry; | ||
this.meter = openTelemetry.getMeterProvider().get(instrumentationName); | ||
this.instrumentationName = instrumentationName; | ||
this.instrumentationVersion = instrumentationVersion; | ||
this.spanNameExtractor = spanNameExtractor; | ||
this.instrumentationVersion = | ||
EmbeddedInstrumentationProperties.findVersion(instrumentationName); | ||
} | ||
|
||
/** | ||
* Sets the instrumentation version that'll be associated with all telemetry produced by this | ||
* {@link Instrumenter}. | ||
* | ||
* @param instrumentationVersion is the version of the instrumentation library, not the version of | ||
* the instrument*ed* library. | ||
*/ | ||
public InstrumenterBuilder<REQUEST, RESPONSE> setInstrumentationVersion( | ||
String instrumentationVersion) { | ||
this.instrumentationVersion = instrumentationVersion; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the OpenTelemetry schema URL that'll be associated with all telemetry produced by this | ||
* {@link Instrumenter}. | ||
*/ | ||
public InstrumenterBuilder<REQUEST, RESPONSE> setSchemaUrl(String schemaUrl) { | ||
this.schemaUrl = schemaUrl; | ||
return this; | ||
} | ||
|
||
/** | ||
|
@@ -127,9 +152,8 @@ public InstrumenterBuilder<REQUEST, RESPONSE> addRequestListener(RequestListener | |
} | ||
|
||
/** Adds a {@link RequestMetrics} whose metrics will be recorded for request start and end. */ | ||
@UnstableApi | ||
public InstrumenterBuilder<REQUEST, RESPONSE> addRequestMetrics(RequestMetrics factory) { | ||
requestListeners.add(factory.create(meter)); | ||
requestMetrics.add(factory); | ||
return this; | ||
} | ||
|
||
|
@@ -276,7 +300,44 @@ private Instrumenter<REQUEST, RESPONSE> newInstrumenter( | |
return constructor.create(this); | ||
} | ||
|
||
SpanSuppressionStrategy getSpanSuppressionStrategy() { | ||
Tracer buildTracer() { | ||
TracerBuilder tracerBuilder = | ||
openTelemetry.getTracerProvider().tracerBuilder(instrumentationName); | ||
if (instrumentationVersion != null) { | ||
tracerBuilder.setInstrumentationVersion(instrumentationVersion); | ||
} | ||
if (schemaUrl != null) { | ||
tracerBuilder.setSchemaUrl(schemaUrl); | ||
} | ||
return tracerBuilder.build(); | ||
} | ||
|
||
List<RequestListener> buildRequestListeners() { | ||
mateuszrzeszutek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// just copy the listeners list if there are no metrics registered | ||
if (requestMetrics.isEmpty()) { | ||
return new ArrayList<>(requestListeners); | ||
} | ||
|
||
List<RequestListener> listeners = | ||
new ArrayList<>(requestListeners.size() + requestMetrics.size()); | ||
listeners.addAll(requestListeners); | ||
|
||
MeterBuilder meterBuilder = openTelemetry.getMeterProvider().meterBuilder(instrumentationName); | ||
if (instrumentationVersion != null) { | ||
meterBuilder.setInstrumentationVersion(instrumentationVersion); | ||
} | ||
if (schemaUrl != null) { | ||
meterBuilder.setSchemaUrl(schemaUrl); | ||
} | ||
Comment on lines
+326
to
+331
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
Meter meter = meterBuilder.build(); | ||
for (RequestMetrics factory : requestMetrics) { | ||
listeners.add(factory.create(meter)); | ||
} | ||
|
||
return listeners; | ||
} | ||
|
||
SpanSuppressionStrategy buildSpanSuppressionStrategy() { | ||
Set<SpanKey> spanKeys = getSpanKeysFromAttributesExtractors(); | ||
if (enableSpanSuppressionByType) { | ||
return SpanSuppressionStrategy.from(spanKeys); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC @theletterf - I've added a new section to the Instrumenter API doc, please take a look at this when you have a moment 🙏