Skip to content

Commit

Permalink
(#9297)
Browse files Browse the repository at this point in the history
- move ConfiguredResourceAttributesHolder to javaagent-extension-api
  • Loading branch information
cleverchuk committed Oct 26, 2023
1 parent 8653b1c commit 80bea6d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> resourceAttributes = new HashMap<>();
Expand All @@ -22,8 +27,9 @@ public static Map<String, String> getResourceAttributes() {
}

public static void initialize(Attributes resourceAttribute) {
String[] mdcResourceAttributes = getConfiguredAttributes();

List<String> mdcResourceAttributes =
InstrumentationConfig.get()
.getList("otel.instrumentation.mdc.resource-attributes", Collections.emptyList());
for (String key : mdcResourceAttributes) {
String value = resourceAttribute.get(stringKey(key));
if (value != null) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 80bea6d

Please sign in to comment.