Skip to content
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

[Maven Extension] Add Tracer instrumentationVersion (ie otel.library.version) #191

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions maven-extension/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ configure<PublishingExtension> {

tasks {
shadowJar {
manifest {
attributes["Implementation-Version"] = project.version
}
archiveClassifier.set("")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.TracerBuilder;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
Expand Down Expand Up @@ -106,7 +107,12 @@ public void initialize() {
.getBoolean("otel.instrumentation.maven.mojo.enabled");
this.mojosInstrumentationEnabled = mojoSpansEnabled == null ? true : mojoSpansEnabled;

this.tracer = this.openTelemetry.getTracer("io.opentelemetry.contrib.maven");
TracerBuilder tracerBuilder = openTelemetry.tracerBuilder("io.opentelemetry.contrib.maven");
String otelMavenExtensionVersion = this.getClass().getPackage().getImplementationVersion();
if (otelMavenExtensionVersion != null) {
tracerBuilder.setInstrumentationVersion(otelMavenExtensionVersion);
}
this.tracer = tracerBuilder.build();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the null check? From looking at the implementation it appears we can go with:

this.tracer = this.openTelemetry.getTracer("io.opentelemetry.contrib.maven", this.getClass().getPackage().getImplementationVersion());

Copy link
Member Author

@cyrille-leclerc cyrille-leclerc Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially started like this as implementationVersion will only be null in unit tests.

However, I hardened the code because null is a violation of the contractOpenTelemetry#getTracer(@Nonnull instrumentationName, @Nonnull instrumentationVersion).

It's probably an acceptable violation of the contract as the implementation supports null and we would not be afraid of regressions if the implementation starts rejecting null instrumentationVersion because it would fail in unit tests.

So if you are ok with this light violation, I'm happy to simplify the code and adopt your proposal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kenfinnigan please review the proposed code change. Slightly different from your suggestion in order to also output the otel maven extension version in the logs.

}

public Tracer getTracer() {
Expand Down