diff --git a/conventions/src/main/kotlin/io.opentelemetry.instrumentation.base.gradle.kts b/conventions/src/main/kotlin/io.opentelemetry.instrumentation.base.gradle.kts index d29aa4acd96c..e70a2d02d66d 100644 --- a/conventions/src/main/kotlin/io.opentelemetry.instrumentation.base.gradle.kts +++ b/conventions/src/main/kotlin/io.opentelemetry.instrumentation.base.gradle.kts @@ -119,3 +119,33 @@ if (testLatestDeps) { } } } + +tasks { + val generateInstrumentationVersionFile by registering { + val name = computeInstrumentationName() + val version = project.version as String + inputs.property("instrumentation.name", name) + inputs.property("instrumentation.version", version) + + val propertiesDir = File(project.buildDir, "generated/instrumentationVersion/META-INF/io/opentelemetry/instrumentation/") + outputs.dir(propertiesDir) + + doLast { + File(propertiesDir, "$name.properties").writeText("version=$version") + } + } +} + +fun computeInstrumentationName(): String { + val name = when (projectDir.name) { + "javaagent", "library", "library-autoconfigure" -> projectDir.parentFile.name + else -> project.name + } + return "io.opentelemetry.$name" +} + +sourceSets { + main { + output.dir("build/generated/instrumentationVersion", "builtBy" to "generateInstrumentationVersionFile") + } +} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/InstrumentationVersion.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/InstrumentationVersion.java index 4b539b335fe8..245f3a6f056b 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/InstrumentationVersion.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/InstrumentationVersion.java @@ -5,6 +5,12 @@ package io.opentelemetry.instrumentation.api; +/** + * This class will be removed. + * + * @deprecated This class will be removed. + */ +@Deprecated public final class InstrumentationVersion { public static final String VERSION = InstrumentationVersion.class.getPackage().getImplementationVersion(); diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Instrumenter.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Instrumenter.java index 367c286a4b13..8d2fe5b55ac5 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Instrumenter.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Instrumenter.java @@ -13,7 +13,7 @@ import io.opentelemetry.api.trace.StatusCode; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.InstrumentationVersion; +import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties; import io.opentelemetry.instrumentation.api.internal.SupportabilityMetrics; import java.time.Instant; import java.util.ArrayList; @@ -60,7 +60,10 @@ public static InstrumenterBuilder builder String instrumentationName, SpanNameExtractor spanNameExtractor) { return new InstrumenterBuilder<>( - openTelemetry, instrumentationName, InstrumentationVersion.VERSION, spanNameExtractor); + openTelemetry, + instrumentationName, + EmbeddedInstrumentationProperties.findVersion(instrumentationName), + spanNameExtractor); } /** @@ -80,6 +83,7 @@ public static InstrumenterBuilder builder * different library versions it's easy to find out which instrumentations produced the telemetry * data. */ + // TODO: add a setInstrumentationVersion method to the builder instead public static InstrumenterBuilder builder( OpenTelemetry openTelemetry, String instrumentationName, diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/EmbeddedInstrumentationProperties.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/EmbeddedInstrumentationProperties.java new file mode 100644 index 000000000000..70002f426220 --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/EmbeddedInstrumentationProperties.java @@ -0,0 +1,80 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.internal; + +import static java.util.logging.Level.FINE; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public final class EmbeddedInstrumentationProperties { + + private static final Logger logger = + Logger.getLogger(EmbeddedInstrumentationProperties.class.getName()); + + private static final ClassLoader DEFAULT_LOADER; + + static { + ClassLoader defaultLoader = EmbeddedInstrumentationProperties.class.getClassLoader(); + if (defaultLoader == null) { + defaultLoader = new BootstrapProxy(); + } + DEFAULT_LOADER = defaultLoader; + } + + private static volatile ClassLoader loader = DEFAULT_LOADER; + private static final Map versions = new ConcurrentHashMap<>(); + + public static void setPropertiesLoader(ClassLoader propertiesLoader) { + if (loader != DEFAULT_LOADER) { + logger.warning( + "Embedded properties loader has already been set up, further setPropertiesLoader() calls are ignored"); + return; + } + loader = propertiesLoader; + } + + @Nullable + public static String findVersion(String instrumentationName) { + return versions.computeIfAbsent( + instrumentationName, EmbeddedInstrumentationProperties::loadVersion); + } + + @Nullable + private static String loadVersion(String instrumentationName) { + String path = + "META-INF/io/opentelemetry/instrumentation/" + instrumentationName + ".properties"; + try (InputStream in = loader.getResourceAsStream(path)) { + if (in == null) { + logger.log(FINE, "Did not find embedded instrumentation properties file {0}", path); + return null; + } + Properties parsed = new Properties(); + parsed.load(in); + return parsed.getProperty("version"); + } catch (IOException e) { + logger.log(FINE, "Failed to load embedded instrumentation properties file " + path, e); + return null; + } + } + + private static final class BootstrapProxy extends ClassLoader { + BootstrapProxy() { + super(null); + } + } + + private EmbeddedInstrumentationProperties() {} +} diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java index 6efe3219b818..c03823cf1018 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java @@ -23,7 +23,6 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.ContextKey; import io.opentelemetry.context.propagation.TextMapGetter; -import io.opentelemetry.instrumentation.api.InstrumentationVersion; import io.opentelemetry.instrumentation.api.internal.SpanKey; import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider; import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; @@ -714,7 +713,8 @@ void instrumentationTypeDetected_generic() { @Test void instrumentationVersion_default() { InstrumenterBuilder, Map> builder = - Instrumenter.builder(otelTesting.getOpenTelemetry(), "test", name -> "span"); + Instrumenter.builder( + otelTesting.getOpenTelemetry(), "test-instrumentation", name -> "span"); Instrumenter, Map> instrumenter = builder.newInstrumenter(); @@ -723,16 +723,17 @@ void instrumentationVersion_default() { instrumenter.end(context, Collections.emptyMap(), Collections.emptyMap(), null); + // see the test-instrumentation.properties file + InstrumentationLibraryInfo expectedLibraryInfo = + InstrumentationLibraryInfo.create("test-instrumentation", "1.2.3"); + otelTesting .assertTraces() .hasTracesSatisfyingExactly( trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("span") - .hasInstrumentationLibraryInfo( - InstrumentationLibraryInfo.create( - "test", InstrumentationVersion.VERSION)))); + span.hasName("span").hasInstrumentationLibraryInfo(expectedLibraryInfo))); } @Test diff --git a/instrumentation-api/src/test/resources/META-INF/io/opentelemetry/instrumentation/test-instrumentation.properties b/instrumentation-api/src/test/resources/META-INF/io/opentelemetry/instrumentation/test-instrumentation.properties new file mode 100644 index 000000000000..df05e67a7fab --- /dev/null +++ b/instrumentation-api/src/test/resources/META-INF/io/opentelemetry/instrumentation/test-instrumentation.properties @@ -0,0 +1,2 @@ +# This file is used by the InstrumenterTest#instrumentationVersion_default() test method +version=1.2.3 diff --git a/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/AwsLambdaEventsInstrumenterFactory.java b/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/AwsLambdaEventsInstrumenterFactory.java index 82f9da9d5827..062095fbceac 100644 --- a/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/AwsLambdaEventsInstrumenterFactory.java +++ b/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/AwsLambdaEventsInstrumenterFactory.java @@ -24,7 +24,7 @@ public static AwsLambdaFunctionInstrumenter createInstrumenter(OpenTelemetry ope openTelemetry, Instrumenter.builder( openTelemetry, - "io.opentelemetry.aws-lambda-1.0", + "io.opentelemetry.aws-lambda-events-2.2", AwsLambdaEventsInstrumenterFactory::spanName) .addAttributesExtractors( new AwsLambdaFunctionAttributesExtractor(), diff --git a/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/AwsLambdaSqsInstrumenterFactory.java b/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/AwsLambdaSqsInstrumenterFactory.java index e5deb64cd8f7..70d7ece91e6c 100644 --- a/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/AwsLambdaSqsInstrumenterFactory.java +++ b/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/AwsLambdaSqsInstrumenterFactory.java @@ -20,7 +20,7 @@ public class AwsLambdaSqsInstrumenterFactory { public static Instrumenter forEvent(OpenTelemetry openTelemetry) { return Instrumenter.builder( openTelemetry, - "io.opentelemetry.aws-lambda-1.0", + "io.opentelemetry.aws-lambda-events-2.2", AwsLambdaSqsInstrumenterFactory::spanName) .addAttributesExtractors(new SqsEventAttributesExtractor()) .addSpanLinksExtractor(new SqsEventSpanLinksExtractor()) @@ -30,7 +30,7 @@ public static Instrumenter forEvent(OpenTelemetry openTelemetry) public static Instrumenter forMessage(OpenTelemetry openTelemetry) { return Instrumenter.builder( openTelemetry, - "io.opentelemetry.aws-lambda-1.0", + "io.opentelemetry.aws-lambda-events-2.2", message -> message.getEventSource() + " process") .addAttributesExtractors(new SqsMessageAttributesExtractor()) .addSpanLinksExtractor(new SqsMessageSpanLinksExtractor()) diff --git a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsSingletons.java b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsSingletons.java index 7b8e17273e8b..52350e8f6c43 100644 --- a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsSingletons.java +++ b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsSingletons.java @@ -18,7 +18,7 @@ public final class JaxrsSingletons { public static final String ABORT_HANDLED = "io.opentelemetry.javaagent.instrumentation.jaxrs2.filter.abort.handled"; - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jaxrs-1.0-common"; + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jaxrs-1.0"; private static final Instrumenter INSTRUMENTER; diff --git a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/OpenTelemetryDriver.java b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/OpenTelemetryDriver.java index 841261322d8e..72f7cecc6a3e 100644 --- a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/OpenTelemetryDriver.java +++ b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/OpenTelemetryDriver.java @@ -20,7 +20,9 @@ package io.opentelemetry.instrumentation.jdbc; -import io.opentelemetry.instrumentation.api.InstrumentationVersion; +import static io.opentelemetry.instrumentation.jdbc.internal.JdbcSingletons.INSTRUMENTATION_NAME; + +import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties; import io.opentelemetry.instrumentation.jdbc.internal.DbInfo; import io.opentelemetry.instrumentation.jdbc.internal.JdbcConnectionUrlParser; import io.opentelemetry.instrumentation.jdbc.internal.OpenTelemetryConnection; @@ -122,7 +124,12 @@ private static String extractRealUrl(String url) { } private static int[] parseInstrumentationVersion() { - String[] parts = InstrumentationVersion.VERSION.split("\\."); + String version = EmbeddedInstrumentationProperties.findVersion(INSTRUMENTATION_NAME); + if (version == null) { + // return 0.0 as a fallback + return new int[] {0, 0}; + } + String[] parts = version.split("\\."); if (parts.length >= 2) { try { int majorVersion = Integer.parseInt(parts[0]); diff --git a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcSingletons.java b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcSingletons.java index 4776c37f58af..6d919947e4e9 100644 --- a/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcSingletons.java +++ b/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcSingletons.java @@ -17,7 +17,7 @@ * any time. */ public final class JdbcSingletons { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jdbc"; + public static final String INSTRUMENTATION_NAME = "io.opentelemetry.jdbc"; private static final Instrumenter INSTRUMENTER; diff --git a/instrumentation/jdbc/library/src/test/groovy/io/opentelemetry/instrumentation/jdbc/OpenTelemetryDriverTest.groovy b/instrumentation/jdbc/library/src/test/groovy/io/opentelemetry/instrumentation/jdbc/OpenTelemetryDriverTest.groovy index 762685b6c497..9e00e320fe2f 100644 --- a/instrumentation/jdbc/library/src/test/groovy/io/opentelemetry/instrumentation/jdbc/OpenTelemetryDriverTest.groovy +++ b/instrumentation/jdbc/library/src/test/groovy/io/opentelemetry/instrumentation/jdbc/OpenTelemetryDriverTest.groovy @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.jdbc -import io.opentelemetry.instrumentation.api.InstrumentationVersion +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter import io.opentelemetry.instrumentation.jdbc.internal.OpenTelemetryConnection import spock.lang.Specification @@ -37,7 +37,7 @@ class OpenTelemetryDriverTest extends Specification { expect: !OpenTelemetryDriver.INSTANCE.jdbcCompliant() - String[] parts = InstrumentationVersion.getPackage().getImplementationVersion().split("\\.") + String[] parts = Instrumenter.getPackage().getImplementationVersion().split("\\.") OpenTelemetryDriver.INSTANCE.majorVersion == Integer.parseInt(parts[0]) OpenTelemetryDriver.INSTANCE.minorVersion == Integer.parseInt(parts[1]) diff --git a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisSingletons.java b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisSingletons.java index ea7221bef9c3..58fb8391d005 100644 --- a/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisSingletons.java +++ b/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisSingletons.java @@ -14,7 +14,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; public final class JedisSingletons { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jedis-3.0"; + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jedis-4.0"; private static final Instrumenter INSTRUMENTER; diff --git a/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mojarra/MojarraSingletons.java b/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mojarra/MojarraSingletons.java index b2b2ca43ca67..2fa14640ef2a 100644 --- a/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mojarra/MojarraSingletons.java +++ b/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mojarra/MojarraSingletons.java @@ -12,7 +12,7 @@ import io.opentelemetry.javaagent.instrumentation.jsf.JsfRequest; public class MojarraSingletons { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.mojarra-1.2"; + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jsf-mojarra-1.2"; private static final Instrumenter INSTRUMENTER; diff --git a/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/myfaces/MyFacesSingletons.java b/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/myfaces/MyFacesSingletons.java index 8e76277d22ca..49e45646d037 100644 --- a/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/myfaces/MyFacesSingletons.java +++ b/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/myfaces/MyFacesSingletons.java @@ -11,7 +11,7 @@ import io.opentelemetry.javaagent.instrumentation.jsf.JsfRequest; public class MyFacesSingletons { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.myfaces-1.2"; + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jsf-myfaces-1.2"; private static final Instrumenter INSTRUMENTER; diff --git a/instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTelemetryBuilder.java b/instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTelemetryBuilder.java index 64a2ca658a39..ac546cb61ff3 100644 --- a/instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTelemetryBuilder.java +++ b/instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTelemetryBuilder.java @@ -16,7 +16,7 @@ import org.apache.kafka.clients.producer.ProducerRecord; public final class KafkaTelemetryBuilder { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.kafka-clients-0.11"; + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.kafka-clients-2.6"; private final OpenTelemetry openTelemetry; private final List, Void>> producerAttributesExtractors = diff --git a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceTelemetry.java b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceTelemetry.java index 455ecfd8b7e4..449f3ebdcce8 100644 --- a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceTelemetry.java +++ b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceTelemetry.java @@ -8,10 +8,14 @@ import io.lettuce.core.tracing.Tracing; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.api.trace.TracerBuilder; +import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties; /** Entrypoint for instrumenting Lettuce or clients. */ public final class LettuceTelemetry { + public static final String INSTRUMENTATION_NAME = "io.opentelemetry.lettuce-5.1"; + /** Returns a new {@link LettuceTelemetry} configured with the given {@link OpenTelemetry}. */ public static LettuceTelemetry create(OpenTelemetry openTelemetry) { return new LettuceTelemetry(openTelemetry); @@ -20,7 +24,12 @@ public static LettuceTelemetry create(OpenTelemetry openTelemetry) { private final Tracer tracer; private LettuceTelemetry(OpenTelemetry openTelemetry) { - tracer = openTelemetry.getTracer("io.opentelemetry.lettuce-5.1"); + TracerBuilder tracerBuilder = openTelemetry.tracerBuilder(INSTRUMENTATION_NAME); + String version = EmbeddedInstrumentationProperties.findVersion(INSTRUMENTATION_NAME); + if (version != null) { + tracerBuilder.setInstrumentationVersion(version); + } + tracer = tracerBuilder.build(); } /** diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/RatpackTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/RatpackTelemetryBuilder.java index b1f435a6336a..e6005bc9c4fd 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/RatpackTelemetryBuilder.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/RatpackTelemetryBuilder.java @@ -29,7 +29,7 @@ /** A builder for {@link RatpackTelemetry}. */ public final class RatpackTelemetryBuilder { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.ratpack-1.4"; + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.ratpack-1.7"; private final OpenTelemetry openTelemetry; diff --git a/instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/jpms/ExposeRmiModuleInstrumentation.java b/instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/jpms/ExposeRmiModuleInstrumentation.java index 60863acc3e77..e5120f6bc103 100644 --- a/instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/jpms/ExposeRmiModuleInstrumentation.java +++ b/instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/jpms/ExposeRmiModuleInstrumentation.java @@ -8,10 +8,10 @@ import static java.util.logging.Level.FINE; import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith; -import io.opentelemetry.instrumentation.api.InstrumentationVersion; import io.opentelemetry.javaagent.bootstrap.InstrumentationHolder; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; import java.util.Collections; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Logger; @@ -57,9 +57,9 @@ public void transform(TypeTransformer transformer) { transformer.applyTransformer( (builder, typeDescription, classLoader, module) -> { if (module != null && module.isNamed()) { - // using InstrumentationVersion because it's in the unnamed module in the bootstrap + // using Java8BytecodeBridge because it's in the unnamed module in the bootstrap // loader, and that's where the rmi instrumentation helper classes will end up - JavaModule helperModule = JavaModule.ofType(InstrumentationVersion.class); + JavaModule helperModule = JavaModule.ofType(Java8BytecodeBridge.class); // expose sun.rmi.server package to unnamed module ClassInjector.UsingInstrumentation.redefineModule( InstrumentationHolder.getInstrumentation(), diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentInstaller.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentInstaller.java index 39e6cd02edc0..6c77ebd9c735 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentInstaller.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentInstaller.java @@ -19,7 +19,9 @@ import io.opentelemetry.context.Scope; import io.opentelemetry.extension.noopapi.NoopOpenTelemetry; import io.opentelemetry.instrumentation.api.config.Config; +import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties; import io.opentelemetry.javaagent.bootstrap.AgentClassLoader; +import io.opentelemetry.javaagent.bootstrap.AgentInitializer; import io.opentelemetry.javaagent.bootstrap.BootstrapPackagePrefixesHolder; import io.opentelemetry.javaagent.bootstrap.ClassFileTransformerHolder; import io.opentelemetry.javaagent.extension.AgentListener; @@ -111,6 +113,9 @@ public static ResettableClassFileTransformer installBytebuddyAgent( WeakRefAsyncOperationEndStrategies.initialize(); + EmbeddedInstrumentationProperties.setPropertiesLoader( + AgentInitializer.getExtensionsClassLoader()); + Config config = Config.get(); setBootstrapPackages(config); diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentVersion.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentVersion.java new file mode 100644 index 000000000000..631b7ae02fbb --- /dev/null +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentVersion.java @@ -0,0 +1,15 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.tooling; + +import io.opentelemetry.javaagent.OpenTelemetryAgent; + +public final class AgentVersion { + public static final String VERSION = + OpenTelemetryAgent.class.getPackage().getImplementationVersion(); + + private AgentVersion() {} +} diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AutoVersionResourceProvider.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AutoVersionResourceProvider.java index 327c3f1c2a91..4010f191da29 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AutoVersionResourceProvider.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AutoVersionResourceProvider.java @@ -8,7 +8,6 @@ import com.google.auto.service.AutoService; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.instrumentation.api.InstrumentationVersion; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; import io.opentelemetry.sdk.resources.Resource; @@ -21,8 +20,8 @@ public class AutoVersionResourceProvider implements ResourceProvider { @Override public Resource createResource(ConfigProperties config) { - return InstrumentationVersion.VERSION == null + return AgentVersion.VERSION == null ? Resource.empty() - : Resource.create(Attributes.of(TELEMETRY_AUTO_VERSION, InstrumentationVersion.VERSION)); + : Resource.create(Attributes.of(TELEMETRY_AUTO_VERSION, AgentVersion.VERSION)); } } diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/VersionLogger.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/VersionLogger.java index fba6e4d370b8..454e67df1269 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/VersionLogger.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/VersionLogger.java @@ -8,7 +8,6 @@ import static java.util.logging.Level.FINE; import static java.util.logging.Level.INFO; -import io.opentelemetry.instrumentation.api.InstrumentationVersion; import java.util.logging.Logger; public final class VersionLogger { @@ -16,7 +15,7 @@ public final class VersionLogger { private static final Logger logger = Logger.getLogger(VersionLogger.class.getName()); public static void logAllVersions() { - logger.log(INFO, "opentelemetry-javaagent - version: {0}", InstrumentationVersion.VERSION); + logger.log(INFO, "opentelemetry-javaagent - version: {0}", AgentVersion.VERSION); if (logger.isLoggable(FINE)) { logger.log( FINE,