-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#9297) add new instrumentation config `otel.instrumentation.mdc.reso…
…urce-attributes` that will be used to configure `Resource` attributes to be added to logging map diagnostic context.
- Loading branch information
1 parent
4deb652
commit cf86974
Showing
5 changed files
with
71 additions
and
0 deletions.
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
43 changes: 43 additions & 0 deletions
43
.../src/main/java/io/opentelemetry/javaagent/tooling/ConfiguredResourceAttributesHolder.java
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.tooling; | ||
|
||
import static io.opentelemetry.api.common.AttributeKey.stringKey; | ||
import static java.util.Collections.emptyList; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public final class ConfiguredResourceAttributesHolder { | ||
|
||
private static final Map<String, String> resourceAttribute = new HashMap<>(); | ||
|
||
public static Map<String, String> getResourceAttribute() { | ||
return resourceAttribute; | ||
} | ||
|
||
public static void initialize(Attributes resourceAttribute, InstrumentationConfig config) { | ||
List<String> mdcResourceAttributes = | ||
config.getList("otel.instrumentation.mdc.resource-attributes", emptyList()); | ||
|
||
for (String key : mdcResourceAttributes) { | ||
String value = resourceAttribute.get(stringKey(key)); | ||
if (value != null) { | ||
ConfiguredResourceAttributesHolder.resourceAttribute.put( | ||
String.format("otel.resource.%s", key), value); | ||
} | ||
} | ||
} | ||
|
||
public static String getAttributeValue(String key) { | ||
return resourceAttribute.get(String.format("otel.resource.%s", key)); | ||
} | ||
|
||
private ConfiguredResourceAttributesHolder() {} | ||
} |
16 changes: 16 additions & 0 deletions
16
...gent-tooling/src/main/java/io/opentelemetry/sdk/autoconfigure/SdkAutoconfigureAccess.java
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.autoconfigure; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
|
||
public final class SdkAutoconfigureAccess { | ||
public static Attributes getResourceAttribute(AutoConfiguredOpenTelemetrySdk sdk) { | ||
return sdk.getResource().getAttributes(); | ||
} | ||
|
||
private SdkAutoconfigureAccess() {} | ||
} |