-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfiguredResourceAttributesHolder.java
51 lines (40 loc) · 1.5 KB
/
ConfiguredResourceAttributesHolder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.bootstrap;
import static io.opentelemetry.api.common.AttributeKey.stringKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
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) {
String[] mdcResourceAttributes = getConfiguredAttributes();
for (String key : mdcResourceAttributes) {
String value = resourceAttribute.get(stringKey(key));
if (value != null) {
ConfiguredResourceAttributesHolder.resourceAttribute.put(
String.format("otel.resource.%s", key), value);
}
}
}
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 resourceAttribute.get(String.format("otel.resource.%s", key));
}
private ConfiguredResourceAttributesHolder() {}
}