diff --git a/instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/library-autoconfigure/build.gradle.kts b/instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/library-autoconfigure/build.gradle.kts index 26b587e868e3..e33133932c6f 100644 --- a/instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/library-autoconfigure/build.gradle.kts +++ b/instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/library-autoconfigure/build.gradle.kts @@ -5,7 +5,7 @@ plugins { base.archivesName.set("${base.archivesName.get()}-autoconfigure") dependencies { - compileOnly(project(":javaagent-bootstrap")) + compileOnly(project(":javaagent-extension-api")) library("org.apache.logging.log4j:log4j-core:2.17.0") testImplementation(project(":instrumentation:log4j:log4j-context-data:log4j-context-data-common:testing")) diff --git a/instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/log4j/contextdata/v2_17/OpenTelemetryContextDataProvider.java b/instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/log4j/contextdata/v2_17/OpenTelemetryContextDataProvider.java index eb069d5f9f7c..c8a111cf580e 100644 --- a/instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/log4j/contextdata/v2_17/OpenTelemetryContextDataProvider.java +++ b/instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/log4j/contextdata/v2_17/OpenTelemetryContextDataProvider.java @@ -15,10 +15,10 @@ import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil; -import io.opentelemetry.javaagent.bootstrap.ConfiguredResourceAttributesHolder; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import io.opentelemetry.javaagent.bootstrap.internal.ConfiguredResourceAttributesHolder; import org.apache.logging.log4j.core.util.ContextDataProvider; /** @@ -41,7 +41,8 @@ public class OpenTelemetryContextDataProvider implements ContextDataProvider { */ private static boolean isConfiguredResourceAttributeAccessible() { try { - Class.forName("io.opentelemetry.javaagent.bootstrap.ConfiguredResourceAttributesHolder"); + Class.forName( + "io.opentelemetry.javaagent.bootstrap.internal.ConfiguredResourceAttributesHolder"); return true; } catch (ClassNotFoundException ok) { diff --git a/instrumentation/log4j/log4j-context-data/log4j-context-data-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/contextdata/v2_7/SpanDecoratingContextDataInjector.java b/instrumentation/log4j/log4j-context-data/log4j-context-data-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/contextdata/v2_7/SpanDecoratingContextDataInjector.java index 87c810271435..1cd131257e69 100644 --- a/instrumentation/log4j/log4j-context-data/log4j-context-data-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/contextdata/v2_7/SpanDecoratingContextDataInjector.java +++ b/instrumentation/log4j/log4j-context-data/log4j-context-data-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/contextdata/v2_7/SpanDecoratingContextDataInjector.java @@ -14,7 +14,7 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.context.Context; -import io.opentelemetry.javaagent.bootstrap.ConfiguredResourceAttributesHolder; +import io.opentelemetry.javaagent.bootstrap.internal.ConfiguredResourceAttributesHolder; import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; import java.util.List; import java.util.Map; diff --git a/instrumentation/log4j/log4j-mdc-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/mdc/v1_2/LoggingEventInstrumentation.java b/instrumentation/log4j/log4j-mdc-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/mdc/v1_2/LoggingEventInstrumentation.java index bf5f4834c189..98fc320f6662 100644 --- a/instrumentation/log4j/log4j-mdc-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/mdc/v1_2/LoggingEventInstrumentation.java +++ b/instrumentation/log4j/log4j-mdc-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/log4j/mdc/v1_2/LoggingEventInstrumentation.java @@ -17,7 +17,7 @@ import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.util.VirtualField; -import io.opentelemetry.javaagent.bootstrap.ConfiguredResourceAttributesHolder; +import io.opentelemetry.javaagent.bootstrap.internal.ConfiguredResourceAttributesHolder; import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; diff --git a/instrumentation/logback/logback-mdc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/mdc/v1_0/LoggingEventInstrumentation.java b/instrumentation/logback/logback-mdc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/mdc/v1_0/LoggingEventInstrumentation.java index 616b016ec1f8..370b960a5a56 100644 --- a/instrumentation/logback/logback-mdc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/mdc/v1_0/LoggingEventInstrumentation.java +++ b/instrumentation/logback/logback-mdc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/mdc/v1_0/LoggingEventInstrumentation.java @@ -23,7 +23,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.util.VirtualField; import io.opentelemetry.instrumentation.logback.mdc.v1_0.internal.UnionMap; -import io.opentelemetry.javaagent.bootstrap.ConfiguredResourceAttributesHolder; +import io.opentelemetry.javaagent.bootstrap.internal.ConfiguredResourceAttributesHolder; import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; diff --git a/javaagent-bootstrap/src/test/java/io/opentelemetry/javaagent/bootstrap/ConfiguredResourceAttributesHolderTest.java b/javaagent-bootstrap/src/test/java/io/opentelemetry/javaagent/bootstrap/ConfiguredResourceAttributesHolderTest.java deleted file mode 100644 index 0d2fb9cb1d90..000000000000 --- a/javaagent-bootstrap/src/test/java/io/opentelemetry/javaagent/bootstrap/ConfiguredResourceAttributesHolderTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.bootstrap; - -import static org.assertj.core.api.Assertions.assertThat; - -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.Attributes; -import java.util.Collections; -import org.junit.jupiter.api.Test; -import org.junitpioneer.jupiter.ClearSystemProperty; -import org.junitpioneer.jupiter.SetSystemProperty; - -class ConfiguredResourceAttributesHolderTest { - - @Test - @SetSystemProperty( - key = "otel.instrumentation.mdc.resource-attributes", - value = "service.name,runtime") - void testGetAttributeValue() { - Attributes attributes = - Attributes.builder().put("service.name", "test-service").put("runtime", "JVM").build(); - - ConfiguredResourceAttributesHolder.initialize(attributes); - - assertThat(ConfiguredResourceAttributesHolder.getAttributeValue("service.name")) - .isEqualTo("test-service"); - assertThat(ConfiguredResourceAttributesHolder.getAttributeValue("runtime")).isEqualTo("JVM"); - } - - @Test - @SetSystemProperty(key = "otel.instrumentation.mdc.resource-attributes", value = "items") - void testGetAttributeValueWhenKeyIsNotString() { - Attributes attributes = - Attributes.builder() - .put(AttributeKey.stringArrayKey("items"), Collections.singletonList("test-item")) - .build(); - - ConfiguredResourceAttributesHolder.initialize(attributes); - assertThat(ConfiguredResourceAttributesHolder.getAttributeValue("items")).isNull(); - } - - @Test - @ClearSystemProperty(key = "otel.instrumentation.mdc.resource-attributes") - void testGetAttributeValueWhenConfigIsNotSet() { - Attributes attributes = - Attributes.builder().put(AttributeKey.stringArrayKey("don't care"), "won't care").build(); - - ConfiguredResourceAttributesHolder.initialize(attributes); - assertThat(ConfiguredResourceAttributesHolder.getAttributeValue("dc-wc")).isNull(); - } -} diff --git a/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/ConfiguredResourceAttributesHolder.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/ConfiguredResourceAttributesHolder.java similarity index 67% rename from javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/ConfiguredResourceAttributesHolder.java rename to javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/ConfiguredResourceAttributesHolder.java index b36ef9c2d3c6..123126c71cfb 100644 --- a/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/ConfiguredResourceAttributesHolder.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/ConfiguredResourceAttributesHolder.java @@ -3,16 +3,21 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.bootstrap; +package io.opentelemetry.javaagent.bootstrap.internal; import static io.opentelemetry.api.common.AttributeKey.stringKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; 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 ConfiguredResourceAttributesHolder { private static final Map resourceAttributes = new HashMap<>(); @@ -22,8 +27,9 @@ public static Map getResourceAttributes() { } public static void initialize(Attributes resourceAttribute) { - String[] mdcResourceAttributes = getConfiguredAttributes(); - + List mdcResourceAttributes = + InstrumentationConfig.get() + .getList("otel.instrumentation.mdc.resource-attributes", Collections.emptyList()); for (String key : mdcResourceAttributes) { String value = resourceAttribute.get(stringKey(key)); if (value != null) { @@ -32,15 +38,6 @@ public static void initialize(Attributes resourceAttribute) { } } - private static String[] getConfiguredAttributes() { - String resourceAttributes = - ConfigPropertiesUtil.getString("otel.instrumentation.mdc.resource-attributes"); - if (resourceAttributes == null) { - return new String[] {}; - } - return resourceAttributes.split(","); - } - @Nullable public static String getAttributeValue(String key) { return resourceAttributes.get(key); 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 8cbe60221344..ba18b0b1cde4 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 @@ -21,7 +21,7 @@ import io.opentelemetry.javaagent.bootstrap.AgentClassLoader; import io.opentelemetry.javaagent.bootstrap.BootstrapPackagePrefixesHolder; import io.opentelemetry.javaagent.bootstrap.ClassFileTransformerHolder; -import io.opentelemetry.javaagent.bootstrap.ConfiguredResourceAttributesHolder; +import io.opentelemetry.javaagent.bootstrap.internal.ConfiguredResourceAttributesHolder; import io.opentelemetry.javaagent.bootstrap.DefineClassHelper; import io.opentelemetry.javaagent.bootstrap.InstrumentedTaskClasses; import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseCustomizer;