Skip to content

Commit dbe4196

Browse files
authored
Add logstash structured arg support (#14959)
1 parent 9ef79ef commit dbe4196

File tree

16 files changed

+536
-167
lines changed

16 files changed

+536
-167
lines changed
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Settings for the Logback Appender instrumentation
22

3-
| System property | Type | Default | Description |
4-
|----------------------------------------------------------------------------------------|---------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5-
| `otel.instrumentation.logback-appender.experimental-log-attributes` | Boolean | `false` | Enable the capture of experimental log attributes `thread.name` and `thread.id`. |
6-
| `otel.instrumentation.logback-appender.experimental.capture-code-attributes` | Boolean | `false` | Enable the capture of [source code attributes]. Note that capturing source code attributes at logging sites might add a performance overhead. |
7-
| `otel.instrumentation.logback-appender.experimental.capture-marker-attribute` | Boolean | `false` | Enable the capture of Logback markers as attributes. |
8-
| `otel.instrumentation.logback-appender.experimental.capture-key-value-pair-attributes` | Boolean | `false` | Enable the capture of Logback key value pairs as attributes. |
9-
| `otel.instrumentation.logback-appender.experimental.capture-logger-context-attributes` | Boolean | `false` | Enable the capture of Logback logger context properties as attributes. |
10-
| `otel.instrumentation.logback-appender.experimental.capture-arguments` | Boolean | `false` | Enable the capture of Logback logger arguments. |
11-
| `otel.instrumentation.logback-appender.experimental.capture-logstash-attributes` | Boolean | `false` | Enable the capture of Logstash attributes, supported are those added to logs via `Markers.append()`, `Markers.appendEntries()`, `Markers.appendArray()` and `Markers.appendRaw()` methods. |
12-
| `otel.instrumentation.logback-appender.experimental.capture-mdc-attributes` | String | | Comma separated list of MDC attributes to capture. Use the wildcard character `*` to capture all attributes. |
13-
| `otel.instrumentation.logback-appender.experimental.capture-event-name` | Boolean | `false` | Enable moving the `event.name` attribute (captured by one of the other mechanisms of capturing attributes) to the log event name. |
3+
| System property | Type | Default | Description |
4+
|--------------------------------------------------------------------------------------------|---------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5+
| `otel.instrumentation.logback-appender.experimental-log-attributes` | Boolean | `false` | Enable the capture of experimental log attributes `thread.name` and `thread.id`. |
6+
| `otel.instrumentation.logback-appender.experimental.capture-code-attributes` | Boolean | `false` | Enable the capture of [source code attributes]. Note that capturing source code attributes at logging sites might add a performance overhead. |
7+
| `otel.instrumentation.logback-appender.experimental.capture-marker-attribute` | Boolean | `false` | Enable the capture of Logback markers as attributes. |
8+
| `otel.instrumentation.logback-appender.experimental.capture-key-value-pair-attributes` | Boolean | `false` | Enable the capture of Logback key value pairs as attributes. |
9+
| `otel.instrumentation.logback-appender.experimental.capture-logger-context-attributes` | Boolean | `false` | Enable the capture of Logback logger context properties as attributes. |
10+
| `otel.instrumentation.logback-appender.experimental.capture-arguments` | Boolean | `false` | Enable the capture of Logback logger arguments. |
11+
| `otel.instrumentation.logback-appender.experimental.capture-logstash-marker-attributes` | Boolean | `false` | Enable the capture of Logstash markers, supported are those added to logs via `Markers.append()`, `Markers.appendEntries()`, `Markers.appendArray()` and `Markers.appendRaw()` methods. |
12+
| `otel.instrumentation.logback-appender.experimental.capture-logstash-structured-arguments` | Boolean | `false` | Enable the capture of Logstash StructuredArguments as attributes (e.g., `StructuredArguments.v()` and `StructuredArguments.keyValue()`). |
13+
| `otel.instrumentation.logback-appender.experimental.capture-mdc-attributes` | String | | Comma separated list of MDC attributes to capture. Use the wildcard character `*` to capture all attributes. |
14+
| `otel.instrumentation.logback-appender.experimental.capture-event-name` | Boolean | `false` | Enable moving the `event.name` attribute (captured by one of the other mechanisms of capturing attributes) to the log event name. |
1415

1516
[source code attributes]: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/attributes.md#source-code-attributes

instrumentation/logback/logback-appender-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/appender/v1_0/LogbackSingletons.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.opentelemetry.instrumentation.api.incubator.config.internal.InstrumentationConfig;
1111
import io.opentelemetry.instrumentation.logback.appender.v1_0.internal.LoggingEventMapper;
1212
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
13+
import io.opentelemetry.javaagent.bootstrap.internal.DeprecatedConfigProperties;
1314
import java.util.List;
1415

1516
public final class LogbackSingletons {
@@ -39,9 +40,15 @@ public final class LogbackSingletons {
3940
boolean captureArguments =
4041
config.getBoolean(
4142
"otel.instrumentation.logback-appender.experimental.capture-arguments", false);
42-
boolean captureLogstashAttributes =
43-
config.getBoolean(
43+
boolean captureLogstashMarkerAttributes =
44+
DeprecatedConfigProperties.getBoolean(
45+
config,
4446
"otel.instrumentation.logback-appender.experimental.capture-logstash-attributes",
47+
"otel.instrumentation.logback-appender.experimental.capture-logstash-marker-attributes",
48+
false);
49+
boolean captureLogstashStructuredArguments =
50+
config.getBoolean(
51+
"otel.instrumentation.logback-appender.experimental.capture-logstash-structured-arguments",
4552
false);
4653
List<String> captureMdcAttributes =
4754
config.getList(
@@ -60,7 +67,8 @@ public final class LogbackSingletons {
6067
.setCaptureKeyValuePairAttributes(captureKeyValuePairAttributes)
6168
.setCaptureLoggerContext(captureLoggerContext)
6269
.setCaptureArguments(captureArguments)
63-
.setCaptureLogstashAttributes(captureLogstashAttributes)
70+
.setCaptureLogstashMarkerAttributes(captureLogstashMarkerAttributes)
71+
.setCaptureLogstashStructuredArguments(captureLogstashStructuredArguments)
6472
.setCaptureEventName(captureEventName)
6573
.build();
6674
}

instrumentation/logback/logback-appender-1.0/library/README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,19 @@ Settings can be configured in `logback.xml`, for example:
9393

9494
The available settings are:
9595

96-
| XML Element | Type | Default | Description |
97-
|------------------------------------|---------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
98-
| `captureExperimentalAttributes` | Boolean | `false` | Enable the capture of experimental log attributes `thread.name` and `thread.id`. |
99-
| `captureCodeAttributes` | Boolean | `false` | Enable the capture of [source code attributes]. Note that capturing source code attributes at logging sites might add a performance overhead. |
100-
| `captureMarkerAttribute` | Boolean | `false` | Enable the capture of Logback markers as attributes. |
101-
| `captureKeyValuePairAttributes` | Boolean | `false` | Enable the capture of Logback key value pairs as attributes. |
102-
| `captureLoggerContext` | Boolean | `false` | Enable the capture of Logback logger context properties as attributes. |
103-
| `captureArguments` | Boolean | `false` | Enable the capture of Logback logger arguments. |
104-
| `captureLogstashAttributes` | Boolean | `false` | Enable the capture of Logstash attributes, supported are those added to logs via `Markers.append()`, `Markers.appendEntries()`, `Markers.appendArray()` and `Markers.appendRaw()` methods. |
105-
| `captureMdcAttributes` | String | | Comma separated list of MDC attributes to capture. Use the wildcard character `*` to capture all attributes. |
106-
| `captureEventName` | Boolean | `false` | Enable moving the `event.name` attribute (captured by one of the other mechanisms of capturing attributes) to the log event name. |
107-
| `numLogsCapturedBeforeOtelInstall` | Integer | 1000 | Log telemetry is emitted after the initialization of the OpenTelemetry Logback appender with an OpenTelemetry object. This setting allows you to modify the size of the cache used to replay the first logs. thread.id attribute is not captured. |
96+
| XML Element | Type | Default | Description |
97+
|--------------------------------------|---------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
98+
| `captureExperimentalAttributes` | Boolean | `false` | Enable the capture of experimental log attributes `thread.name` and `thread.id`. |
99+
| `captureCodeAttributes` | Boolean | `false` | Enable the capture of [source code attributes]. Note that capturing source code attributes at logging sites might add a performance overhead. |
100+
| `captureMarkerAttribute` | Boolean | `false` | Enable the capture of Logback markers as attributes. |
101+
| `captureKeyValuePairAttributes` | Boolean | `false` | Enable the capture of Logback key value pairs as attributes. |
102+
| `captureLoggerContext` | Boolean | `false` | Enable the capture of Logback logger context properties as attributes. |
103+
| `captureArguments` | Boolean | `false` | Enable the capture of Logback logger arguments. |
104+
| `captureLogstashMarkerAttributes` | Boolean | `false` | Enable the capture of Logstash markers, supported are those added to logs via `Markers.append()`, `Markers.appendEntries()`, `Markers.appendArray()` and `Markers.appendRaw()` methods. |
105+
| `captureLogstashStructuredArguments` | Boolean | `false` | Enable the capture of Logstash StructuredArguments as attributes (e.g., `StructuredArguments.v()` and `StructuredArguments.keyValue()`). |
106+
| `captureMdcAttributes` | String | | Comma separated list of MDC attributes to capture. Use the wildcard character `*` to capture all attributes. |
107+
| `captureEventName` | Boolean | `false` | Enable moving the `event.name` attribute (captured by one of the other mechanisms of capturing attributes) to the log event name. |
108+
| `numLogsCapturedBeforeOtelInstall` | Integer | 1000 | Log telemetry is emitted after the initialization of the OpenTelemetry Logback appender with an OpenTelemetry object. This setting allows you to modify the size of the cache used to replay the first logs. thread.id attribute is not captured. |
108109

109110

110111
[source code attributes]: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/attributes.md#source-code-attributes

instrumentation/logback/logback-appender-1.0/library/build.gradle.kts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,30 @@ val latestDepTest = findProperty("testLatestDeps") as Boolean
7474
testing {
7575
suites {
7676
val slf4j2ApiTest by registering(JvmTestSuite::class) {
77+
dependencies {
78+
implementation(project(":instrumentation:logback:logback-appender-1.0:library"))
79+
implementation("io.opentelemetry:opentelemetry-sdk-testing")
80+
implementation(project(":testing-common"))
81+
82+
if (latestDepTest) {
83+
implementation("ch.qos.logback:logback-classic:latest.release")
84+
implementation("org.slf4j:slf4j-api:latest.release")
85+
} else {
86+
implementation("ch.qos.logback:logback-classic") {
87+
version {
88+
strictly("1.3.0")
89+
}
90+
}
91+
implementation("org.slf4j:slf4j-api") {
92+
version {
93+
strictly("2.0.0")
94+
}
95+
}
96+
}
97+
}
98+
}
99+
100+
val logstashMarkerTest by registering(JvmTestSuite::class) {
77101
dependencies {
78102
implementation(project(":instrumentation:logback:logback-appender-1.0:library"))
79103
implementation("io.opentelemetry:opentelemetry-sdk-testing")
@@ -103,6 +127,36 @@ testing {
103127
}
104128
}
105129

130+
val logstashStructuredArgsTest by registering(JvmTestSuite::class) {
131+
dependencies {
132+
implementation(project(":instrumentation:logback:logback-appender-1.0:library"))
133+
implementation("io.opentelemetry:opentelemetry-sdk-testing")
134+
implementation(project(":testing-common"))
135+
136+
if (latestDepTest) {
137+
implementation("ch.qos.logback:logback-classic:latest.release")
138+
implementation("org.slf4j:slf4j-api:latest.release")
139+
implementation("net.logstash.logback:logstash-logback-encoder:latest.release")
140+
} else {
141+
implementation("ch.qos.logback:logback-classic") {
142+
version {
143+
strictly("1.3.0")
144+
}
145+
}
146+
implementation("org.slf4j:slf4j-api") {
147+
version {
148+
strictly("2.0.0")
149+
}
150+
}
151+
implementation("net.logstash.logback:logstash-logback-encoder") {
152+
version {
153+
strictly("6.6")
154+
}
155+
}
156+
}
157+
}
158+
}
159+
106160
val asyncAppenderTest by registering(JvmTestSuite::class) {
107161
dependencies {
108162
implementation(project(":instrumentation:logback:logback-appender-1.0:library"))

0 commit comments

Comments
 (0)