Skip to content

Commit 5b21872

Browse files
oldiumlaurit
andauthored
Implement reading of simple key-value Logstash JSON Marker attributes (#12513)
Signed-off-by: Oldřich Jedlička <[email protected]> Co-authored-by: Lauri Tulmin <[email protected]>
1 parent e274205 commit 5b21872

File tree

11 files changed

+488
-35
lines changed

11 files changed

+488
-35
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
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-mdc-attributes` | String | | Comma separated list of MDC attributes to capture. Use the wildcard character `*` to capture all attributes. |
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. |
1213

1314
[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

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public final class LogbackSingletons {
3939
boolean captureArguments =
4040
config.getBoolean(
4141
"otel.instrumentation.logback-appender.experimental.capture-arguments", false);
42+
boolean captureLogstashAttributes =
43+
config.getBoolean(
44+
"otel.instrumentation.logback-appender.experimental.capture-logstash-attributes",
45+
false);
4246
List<String> captureMdcAttributes =
4347
config.getList(
4448
"otel.instrumentation.logback-appender.experimental.capture-mdc-attributes",
@@ -53,6 +57,7 @@ public final class LogbackSingletons {
5357
.setCaptureKeyValuePairAttributes(captureKeyValuePairAttributes)
5458
.setCaptureLoggerContext(captureLoggerContext)
5559
.setCaptureArguments(captureArguments)
60+
.setCaptureLogstashAttributes(captureLogstashAttributes)
5661
.build();
5762
}
5863

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ The available settings are:
100100
| `captureMarkerAttribute` | Boolean | `false` | Enable the capture of Logback markers as attributes. |
101101
| `captureKeyValuePairAttributes` | Boolean | `false` | Enable the capture of Logback key value pairs as attributes. |
102102
| `captureLoggerContext` | Boolean | `false` | Enable the capture of Logback logger context properties as attributes. |
103-
| `captureArguments` | Boolean | `false` | Enable the capture of Logback logger arguments. |
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. |
104105
| `captureMdcAttributes` | String | | Comma separated list of MDC attributes to capture. Use the wildcard character `*` to capture all attributes. |
105106
| `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. |
106107

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

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ dependencies {
1919
strictly("2.0.0")
2020
}
2121
}
22+
compileOnly("net.logstash.logback:logstash-logback-encoder") {
23+
version {
24+
strictly("3.0")
25+
}
26+
}
2227

2328
if (findProperty("testLatestDeps") as Boolean) {
2429
testImplementation("ch.qos.logback:logback-classic:+")
@@ -75,6 +80,7 @@ testing {
7580
if (latestDepTest) {
7681
implementation("ch.qos.logback:logback-classic:+")
7782
implementation("org.slf4j:slf4j-api:+")
83+
implementation("net.logstash.logback:logstash-logback-encoder:+")
7884
} else {
7985
implementation("ch.qos.logback:logback-classic") {
8086
version {
@@ -86,6 +92,11 @@ testing {
8692
strictly("2.0.0")
8793
}
8894
}
95+
implementation("net.logstash.logback:logstash-logback-encoder") {
96+
version {
97+
strictly("3.0")
98+
}
99+
}
89100
}
90101
}
91102
}

instrumentation/logback/logback-appender-1.0/library/src/main/java/io/opentelemetry/instrumentation/logback/appender/v1_0/OpenTelemetryAppender.java

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class OpenTelemetryAppender extends UnsynchronizedAppenderBase<ILoggingEv
3434
private boolean captureKeyValuePairAttributes = false;
3535
private boolean captureLoggerContext = false;
3636
private boolean captureArguments = false;
37+
private boolean captureLogstashAttributes = false;
3738
private List<String> captureMdcAttributes = emptyList();
3839

3940
private volatile OpenTelemetry openTelemetry;
@@ -81,6 +82,7 @@ public void start() {
8182
.setCaptureKeyValuePairAttributes(captureKeyValuePairAttributes)
8283
.setCaptureLoggerContext(captureLoggerContext)
8384
.setCaptureArguments(captureArguments)
85+
.setCaptureLogstashAttributes(captureLogstashAttributes)
8486
.build();
8587
eventsToReplay = new ArrayBlockingQueue<>(numLogsCapturedBeforeOtelInstall);
8688
super.start();
@@ -175,6 +177,15 @@ public void setCaptureArguments(boolean captureArguments) {
175177
this.captureArguments = captureArguments;
176178
}
177179

180+
/**
181+
* Sets whether the Logstash attributes should be set to logs.
182+
*
183+
* @param captureLogstashAttributes To enable or disable capturing Logstash attributes
184+
*/
185+
public void setCaptureLogstashAttributes(boolean captureLogstashAttributes) {
186+
this.captureLogstashAttributes = captureLogstashAttributes;
187+
}
188+
178189
/** Configures the {@link MDC} attributes that will be copied to logs. */
179190
public void setCaptureMdcAttributes(String attributes) {
180191
if (attributes != null) {

0 commit comments

Comments
 (0)