Skip to content

Commit 588ff31

Browse files
committed
Rename common logging properties
1 parent 5853bd7 commit 588ff31

18 files changed

Lines changed: 228 additions & 99 deletions

File tree

docs/instrumentation-list.yaml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9633,20 +9633,20 @@ libraries:
96339633
Enables adding baggage entries to the Log4j ThreadContext, prefixed with "baggage.".
96349634
type: boolean
96359635
default: false
9636-
- name: otel.instrumentation.common.logging.trace-id
9637-
declarative_name: java.common.logging.trace_id
9636+
- name: otel.instrumentation.common.logging.trace-id-key
9637+
declarative_name: java.common.logging.trace_id_key
96389638
description: |
96399639
Specifies the key name used to store the trace ID in the logging context.
96409640
type: string
96419641
default: trace_id
9642-
- name: otel.instrumentation.common.logging.span-id
9643-
declarative_name: java.common.logging.span_id
9642+
- name: otel.instrumentation.common.logging.span-id-key
9643+
declarative_name: java.common.logging.span_id_key
96449644
description: |
96459645
Specifies the key name used to store the span ID in the logging context.
96469646
type: string
96479647
default: span_id
9648-
- name: otel.instrumentation.common.logging.trace-flags
9649-
declarative_name: java.common.logging.trace_flags
9648+
- name: otel.instrumentation.common.logging.trace-flags-key
9649+
declarative_name: java.common.logging.trace_flags_key
96509650
description: |
96519651
Specifies the key name used to store the trace flags in the logging context.
96529652
type: string
@@ -9675,8 +9675,8 @@ libraries:
96759675
Enables adding baggage entries to the Log4j ThreadContext, prefixed with "baggage.".
96769676
type: boolean
96779677
default: false
9678-
- name: otel.instrumentation.common.logging.trace-id
9679-
declarative_name: java.common.logging.trace_id
9678+
- name: otel.instrumentation.common.logging.trace-id-key
9679+
declarative_name: java.common.logging.trace_id_key
96809680
description: |
96819681
Specifies the key name used to store the trace ID in the logging context.
96829682
type: string
@@ -9711,20 +9711,20 @@ libraries:
97119711
javaagent_target_versions:
97129712
- log4j:log4j:[1.2,)
97139713
configurations:
9714-
- name: otel.instrumentation.common.logging.trace-id
9715-
declarative_name: java.common.logging.trace_id
9714+
- name: otel.instrumentation.common.logging.trace-id-key
9715+
declarative_name: java.common.logging.trace_id_key
97169716
description: |
97179717
Specifies the key name used to store the trace ID in the logging context.
97189718
type: string
97199719
default: trace_id
9720-
- name: otel.instrumentation.common.logging.span-id
9721-
declarative_name: java.common.logging.span_id
9720+
- name: otel.instrumentation.common.logging.span-id-key
9721+
declarative_name: java.common.logging.span_id_key
97229722
description: |
97239723
Specifies the key name used to store the span ID in the logging context.
97249724
type: string
97259725
default: span_id
9726-
- name: otel.instrumentation.common.logging.trace-flags
9727-
declarative_name: java.common.logging.trace_flags
9726+
- name: otel.instrumentation.common.logging.trace-flags-key
9727+
declarative_name: java.common.logging.trace_flags_key
97289728
description: |
97299729
Specifies the key name used to store the trace flags in the logging context.
97309730
type: string
@@ -9832,20 +9832,20 @@ libraries:
98329832
Enables adding baggage entries to the Logback MDC, prefixed with "baggage.".
98339833
type: boolean
98349834
default: false
9835-
- name: otel.instrumentation.common.logging.trace-id
9836-
declarative_name: java.common.logging.trace_id
9835+
- name: otel.instrumentation.common.logging.trace-id-key
9836+
declarative_name: java.common.logging.trace_id_key
98379837
description: |
98389838
Specifies the key name used to store the trace ID in the logging context.
98399839
type: string
98409840
default: trace_id
9841-
- name: otel.instrumentation.common.logging.span-id
9842-
declarative_name: java.common.logging.span_id
9841+
- name: otel.instrumentation.common.logging.span-id-key
9842+
declarative_name: java.common.logging.span_id_key
98439843
description: |
98449844
Specifies the key name used to store the span ID in the logging context.
98459845
type: string
98469846
default: span_id
9847-
- name: otel.instrumentation.common.logging.trace-flags
9848-
declarative_name: java.common.logging.trace_flags
9847+
- name: otel.instrumentation.common.logging.trace-flags-key
9848+
declarative_name: java.common.logging.trace_flags_key
98499849
description: |
98509850
Specifies the key name used to store the trace flags in the logging context.
98519851
type: string

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/config/internal/CommonConfig.java

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
import java.util.HashSet;
1414
import java.util.List;
1515
import java.util.Set;
16+
import java.util.logging.Logger;
1617

1718
/**
1819
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
1920
* any time.
2021
*/
2122
public final class CommonConfig {
23+
private static final Logger logger = Logger.getLogger(CommonConfig.class.getName());
2224

2325
private final List<String> clientRequestHeaders;
2426
private final List<String> clientResponseHeaders;
@@ -88,15 +90,60 @@ public CommonConfig(OpenTelemetry openTelemetry) {
8890
.get("server")
8991
.getBoolean("emit_experimental_telemetry/development", false);
9092
enduserConfig = new EnduserConfig(commonConfig);
93+
DeclarativeConfigProperties logging = commonConfig.get("logging");
9194
loggingTraceIdKey =
92-
commonConfig.get("logging").getString("trace_id", LoggingContextConstants.TRACE_ID);
95+
getConfig(
96+
logging,
97+
"trace_id_key",
98+
"trace_id",
99+
"instrumentation/development: java: common: logging: trace_id_key",
100+
"instrumentation/development: java: common: logging: trace_id",
101+
LoggingContextConstants.TRACE_ID);
93102
loggingSpanIdKey =
94-
commonConfig.get("logging").getString("span_id", LoggingContextConstants.SPAN_ID);
103+
getConfig(
104+
logging,
105+
"span_id_key",
106+
"span_id",
107+
"instrumentation/development: java: common: logging: span_id_key",
108+
"instrumentation/development: java: common: logging: span_id",
109+
LoggingContextConstants.SPAN_ID);
95110
loggingTraceFlagsKey =
96-
commonConfig.get("logging").getString("trace_flags", LoggingContextConstants.TRACE_FLAGS);
111+
getConfig(
112+
logging,
113+
"trace_flags_key",
114+
"trace_flags",
115+
"instrumentation/development: java: common: logging: trace_flags_key",
116+
"instrumentation/development: java: common: logging: trace_flags",
117+
LoggingContextConstants.TRACE_FLAGS);
97118
v3Preview = commonConfig.getBoolean("v3_preview", false);
98119
}
99120

121+
@SuppressWarnings("deprecation") // using deprecated config property
122+
private static String getConfig(
123+
DeclarativeConfigProperties config,
124+
String newDeclarativeKey,
125+
String oldDeclarativeKey,
126+
String newDeclarativeProperty,
127+
String oldDeclarativeProperty,
128+
String defaultValue) {
129+
String value = config.getString(newDeclarativeKey);
130+
if (value != null) {
131+
return value;
132+
}
133+
value = config.getString(oldDeclarativeKey);
134+
if (value != null) {
135+
logger.warning(
136+
"The '"
137+
+ oldDeclarativeProperty
138+
+ "' declarative configuration is deprecated"
139+
+ " and will be removed in a future version. Use '"
140+
+ newDeclarativeProperty
141+
+ "' instead.");
142+
return value;
143+
}
144+
return defaultValue;
145+
}
146+
100147
public List<String> getClientRequestHeaders() {
101148
return clientRequestHeaders;
102149
}

instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/javaagent/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
|-------------------------------------------------------|---------|---------------|--------------------------------------------------------------------|
55
| `otel.instrumentation.log4j-context-data.add-baggage` | Boolean | `false` | Enable exposing baggage attributes through MDC. |
66
| `otel.instrumentation.common.mdc.resource-attributes` | String | | Comma separated list of resource attributes to expose through MDC. |
7-
| `otel.instrumentation.common.logging.trace-id` | String | `trace_id` | Customize MDC key name for the trace id. |
8-
| `otel.instrumentation.common.logging.span-id` | String | `span_id` | Customize MDC key name for the span id. |
9-
| `otel.instrumentation.common.logging.trace-flags` | String | `trace_flags` | Customize MDC key name for the trace flags. |
7+
| `otel.instrumentation.common.logging.trace-id-key` | String | `trace_id` | Customize MDC key name for the trace id. |
8+
| `otel.instrumentation.common.logging.span-id-key` | String | `span_id` | Customize MDC key name for the span id. |
9+
| `otel.instrumentation.common.logging.trace-flags-key` | String | `trace_flags` | Customize MDC key name for the trace flags. |

instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/javaagent/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ testing {
6868
targets {
6969
all {
7070
testTask.configure {
71-
jvmArgs("-Dotel.instrumentation.common.logging.trace-id=trace_id_test")
72-
jvmArgs("-Dotel.instrumentation.common.logging.span-id=span_id_test")
73-
jvmArgs("-Dotel.instrumentation.common.logging.trace-flags=trace_flags_test")
71+
jvmArgs("-Dotel.instrumentation.common.logging.trace-id-key=trace_id_test")
72+
jvmArgs("-Dotel.instrumentation.common.logging.span-id-key=span_id_test")
73+
jvmArgs("-Dotel.instrumentation.common.logging.trace-flags-key=trace_flags_test")
7474
jvmArgs("-Dlog4j2.enable.threadlocals=true")
7575
}
7676
}

instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/library-autoconfigure/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ will be added to the context when a log statement is made when a span is active:
4444

4545
These keys can be customized using the following system properties or environment variables:
4646

47-
| System property | Environment variable |
48-
|-------------------------------------------------------|---------------------------------------------------|
49-
| `otel.instrumentation.common.logging.trace-id` | `OTEL_INSTRUMENTATION_COMMON_LOGGING_TRACE_ID` |
50-
| `otel.instrumentation.common.logging.span-id` | `OTEL_INSTRUMENTATION_COMMON_LOGGING_SPAN_ID` |
51-
| `otel.instrumentation.common.logging.trace-flags` | `OTEL_INSTRUMENTATION_COMMON_LOGGING_TRACE_FLAGS` |
47+
| System property | Environment variable |
48+
|-------------------------------------------------------|-------------------------------------------------------|
49+
| `otel.instrumentation.common.logging.trace-id-key` | `OTEL_INSTRUMENTATION_COMMON_LOGGING_TRACE_ID_KEY` |
50+
| `otel.instrumentation.common.logging.span-id-key` | `OTEL_INSTRUMENTATION_COMMON_LOGGING_SPAN_ID_KEY` |
51+
| `otel.instrumentation.common.logging.trace-flags-key` | `OTEL_INSTRUMENTATION_COMMON_LOGGING_TRACE_FLAGS_KEY` |
5252

5353
If the `otel.instrumentation.log4j-context-data.add-baggage` system property (or the
5454
`OTEL_INSTRUMENTATION_LOG4J_CONTEXT_DATA_ADD_BAGGAGE` environment variable) is set to `true`,

instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/log4j/contextdata/v2_17/internal/ContextDataKeys.java

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
import io.opentelemetry.instrumentation.api.incubator.config.internal.DeclarativeConfigUtil;
1111
import io.opentelemetry.instrumentation.api.incubator.log.LoggingContextConstants;
1212
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
13+
import java.util.logging.Logger;
1314

1415
/**
1516
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
1617
* any time.
1718
*/
1819
public final class ContextDataKeys {
20+
private static final Logger logger = Logger.getLogger(ContextDataKeys.class.getName());
1921

2022
private final String traceIdKey;
2123
private final String spanIdKey;
@@ -25,20 +27,79 @@ public final class ContextDataKeys {
2527
public static ContextDataKeys create(OpenTelemetry openTelemetry) {
2628
DeclarativeConfigProperties logging =
2729
DeclarativeConfigUtil.getInstrumentationConfig(openTelemetry, "common").get("logging");
28-
return new ContextDataKeys(
29-
logging.getString(
30+
String traceIdKey =
31+
getConfig(
32+
logging,
33+
"trace_id_key",
3034
"trace_id",
31-
ConfigPropertiesUtil.getString(
32-
"otel.instrumentation.common.logging.trace-id", LoggingContextConstants.TRACE_ID)),
33-
logging.getString(
35+
"instrumentation/development: java: common: logging: trace_id_key",
36+
"instrumentation/development: java: common: logging: trace_id",
37+
"otel.instrumentation.common.logging.trace-id-key",
38+
"otel.instrumentation.common.logging.trace-id",
39+
LoggingContextConstants.TRACE_ID);
40+
String spanIdKey =
41+
getConfig(
42+
logging,
43+
"span_id_key",
3444
"span_id",
35-
ConfigPropertiesUtil.getString(
36-
"otel.instrumentation.common.logging.span-id", LoggingContextConstants.SPAN_ID)),
37-
logging.getString(
45+
"instrumentation/development: java: common: logging: span_id_key",
46+
"instrumentation/development: java: common: logging: span_id",
47+
"otel.instrumentation.common.logging.span-id-key",
48+
"otel.instrumentation.common.logging.span-id",
49+
LoggingContextConstants.SPAN_ID);
50+
String traceFlagsKey =
51+
getConfig(
52+
logging,
53+
"trace_flags_key",
3854
"trace_flags",
39-
ConfigPropertiesUtil.getString(
40-
"otel.instrumentation.common.logging.trace-flags",
41-
LoggingContextConstants.TRACE_FLAGS)));
55+
"instrumentation/development: java: common: logging: trace_flags_key",
56+
"instrumentation/development: java: common: logging: trace_flags",
57+
"otel.instrumentation.common.logging.trace-flags-key",
58+
"otel.instrumentation.common.logging.trace-flags",
59+
LoggingContextConstants.TRACE_FLAGS);
60+
return new ContextDataKeys(traceIdKey, spanIdKey, traceFlagsKey);
61+
}
62+
63+
@SuppressWarnings("deprecation") // using deprecated config property
64+
private static String getConfig(
65+
DeclarativeConfigProperties config,
66+
String newDeclarativeKey,
67+
String oldDeclarativeKey,
68+
String newDeclarativeProperty,
69+
String oldDeclarativeProperty,
70+
String newProperty,
71+
String oldProperty,
72+
String defaultValue) {
73+
String value = config.getString(newDeclarativeKey);
74+
if (value != null) {
75+
return value;
76+
}
77+
value = config.getString(oldDeclarativeKey);
78+
if (value != null) {
79+
logger.warning(
80+
"The '"
81+
+ oldDeclarativeProperty
82+
+ "' declarative configuration is deprecated"
83+
+ " and will be removed in a future version. Use '"
84+
+ newDeclarativeProperty
85+
+ "' instead.");
86+
return value;
87+
}
88+
value = ConfigPropertiesUtil.getString(newProperty);
89+
if (value != null) {
90+
return value;
91+
}
92+
value = ConfigPropertiesUtil.getString(oldProperty);
93+
if (value != null) {
94+
logger.warning(
95+
"The '"
96+
+ oldProperty
97+
+ "' system property is deprecated and will be removed in 3.0. Use '"
98+
+ newProperty
99+
+ "' instead.");
100+
return value;
101+
}
102+
return defaultValue;
42103
}
43104

44105
private ContextDataKeys(String traceIdKey, String spanIdKey, String traceFlags) {

instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/metadata.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ configurations:
1010
Enables adding baggage entries to the Log4j ThreadContext, prefixed with "baggage.".
1111
type: boolean
1212
default: false
13-
- name: otel.instrumentation.common.logging.trace-id
14-
declarative_name: java.common.logging.trace_id
13+
- name: otel.instrumentation.common.logging.trace-id-key
14+
declarative_name: java.common.logging.trace_id_key
1515
description: >
1616
Specifies the key name used to store the trace ID in the logging context.
1717
type: string
1818
default: trace_id
19-
- name: otel.instrumentation.common.logging.span-id
20-
declarative_name: java.common.logging.span_id
19+
- name: otel.instrumentation.common.logging.span-id-key
20+
declarative_name: java.common.logging.span_id_key
2121
description: >
2222
Specifies the key name used to store the span ID in the logging context.
2323
type: string
2424
default: span_id
25-
- name: otel.instrumentation.common.logging.trace-flags
26-
declarative_name: java.common.logging.trace_flags
25+
- name: otel.instrumentation.common.logging.trace-flags-key
26+
declarative_name: java.common.logging.trace_flags_key
2727
description: >
2828
Specifies the key name used to store the trace flags in the logging context.
2929
type: string

instrumentation/log4j/log4j-context-data/log4j-context-data-2.7/javaagent/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ tasks {
4545
filter {
4646
includeTestsMatching("Log4j27LoggingKeysTest")
4747
}
48-
jvmArgs("-Dotel.instrumentation.common.logging.trace-id=trace_id_test")
49-
jvmArgs("-Dotel.instrumentation.common.logging.span-id=span_id_test")
50-
jvmArgs("-Dotel.instrumentation.common.logging.trace-flags=trace_flags_test")
48+
jvmArgs("-Dotel.instrumentation.common.logging.trace-id-key=trace_id_test")
49+
jvmArgs("-Dotel.instrumentation.common.logging.span-id-key=span_id_test")
50+
jvmArgs("-Dotel.instrumentation.common.logging.trace-flags-key=trace_flags_test")
5151
}
5252

5353
named("check") {

instrumentation/log4j/log4j-context-data/log4j-context-data-2.7/metadata.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ configurations:
1010
Enables adding baggage entries to the Log4j ThreadContext, prefixed with "baggage.".
1111
type: boolean
1212
default: false
13-
- name: otel.instrumentation.common.logging.trace-id
14-
declarative_name: java.common.logging.trace_id
13+
- name: otel.instrumentation.common.logging.trace-id-key
14+
declarative_name: java.common.logging.trace_id_key
1515
description: >
1616
Specifies the key name used to store the trace ID in the logging context.
1717
type: string
1818
default: trace_id
19-
- name: otel.instrumentation.common.logging.span-id
20-
declarative_name: java.common.logging.span_id
19+
- name: otel.instrumentation.common.logging.span-id-key
20+
declarative_name: java.common.logging.span_id_key
2121
description: >
2222
Specifies the key name used to store the span ID in the logging context.
2323
type: string
2424
default: span_id
25-
- name: otel.instrumentation.common.logging.trace-flags
26-
declarative_name: java.common.logging.trace_flags
25+
- name: otel.instrumentation.common.logging.trace-flags-key
26+
declarative_name: java.common.logging.trace_flags_key
2727
description: >
2828
Specifies the key name used to store the trace flags in the logging context.
2929
type: string

instrumentation/log4j/log4j-mdc-1.2/javaagent/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
| System property | Type | Default | Description |
44
|-------------------------------------------------------|---------|---------------|--------------------------------------------------------------------|
55
| `otel.instrumentation.common.mdc.resource-attributes` | String | | Comma separated list of resource attributes to expose through MDC. |
6-
| `otel.instrumentation.common.logging.trace-id` | String | `trace_id` | Customize MDC key name for the trace id. |
7-
| `otel.instrumentation.common.logging.span-id` | String | `span_id` | Customize MDC key name for the span id. |
8-
| `otel.instrumentation.common.logging.trace-flags` | String | `trace_flags` | Customize MDC key name for the trace flags. |
6+
| `otel.instrumentation.common.logging.trace-id-key` | String | `trace_id` | Customize MDC key name for the trace id. |
7+
| `otel.instrumentation.common.logging.span-id-key` | String | `span_id` | Customize MDC key name for the span id. |
8+
| `otel.instrumentation.common.logging.trace-flags-key` | String | `trace_flags` | Customize MDC key name for the trace flags. |

0 commit comments

Comments
 (0)