Skip to content

Commit f518d9a

Browse files
committed
Only capture log body template if arguments are provided
Reduces log volume when message templates are not being used.
1 parent 07ef9f9 commit f518d9a

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
| `otel.instrumentation.logback-appender.experimental.capture-marker-attribute` | Boolean | `false` | Enable the capture of Logback markers as attributes. |
88
| `otel.instrumentation.logback-appender.experimental.capture-key-value-pair-attributes` | Boolean | `false` | Enable the capture of Logback key value pairs as attributes. |
99
| `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-template` | Boolean | `false` | Enable the capture of Logback log event message template. |
10+
| `otel.instrumentation.logback-appender.experimental.capture-template` | Boolean | `false` | Enable the capture of Logback log event message template (if arguments are provided). |
1111
| `otel.instrumentation.logback-appender.experimental.capture-arguments` | Boolean | `false` | Enable the capture of Logback log event arguments. |
1212
| `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. |
1313
| `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()`). |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ 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-
| `captureTemplate` | Boolean | `false` | Enable the capture of Logback log event message template. |
103+
| `captureTemplate` | Boolean | `false` | Enable the capture of Logback log event message template (if arguments are provided). |
104104
| `captureArguments` | Boolean | `false` | Enable the capture of Logback log event arguments. |
105105
| `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. |
106106
| `captureLogstashStructuredArguments` | Boolean | `false` | Enable the capture of Logstash StructuredArguments as attributes (e.g., `StructuredArguments.v()` and `StructuredArguments.keyValue()`). |

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,10 @@ public void setCaptureLoggerContext(boolean captureLoggerContext) {
180180
}
181181

182182
/**
183-
* Sets whether the message template should be captured in logs
183+
* Sets whether the message template should be captured in logs if arguments are provided.
184184
*
185-
* @param captureTemplate whether the message template should be captured in logs
185+
* @param captureTemplate whether the message template should be captured in logs if arguments are
186+
* provided
186187
*/
187188
public void setCaptureTemplate(boolean captureTemplate) {
188189
this.captureTemplate = captureTemplate;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ private void mapLoggingEvent(
217217
captureLoggerContext(builder, loggingEvent.getLoggerContextVO().getPropertyMap());
218218
}
219219

220-
if (captureTemplate) {
220+
if (captureTemplate
221+
&& loggingEvent.getArgumentArray() != null
222+
&& loggingEvent.getArgumentArray().length > 0) {
221223
captureTemplate(builder, loggingEvent);
222224
}
223225

instrumentation/logback/logback-appender-1.0/library/src/slf4j2ApiTest/java/io/opentelemetry/instrumentation/logback/appender/v1_0/Slf4j2Test.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ void keyValue() {
6060
.hasResource(resource)
6161
.hasInstrumentationScope(instrumentationScopeInfo)
6262
.hasBody("log message 1")
63-
.hasTotalAttributeCount(
64-
codeAttributesLogCount() + 9) // 8 key value pairs + 1 template
63+
.hasTotalAttributeCount(codeAttributesLogCount() + 8) // 8 key value pairs
6564
.hasEventName("MyEventName")
6665
.hasAttributesSatisfying(
6766
equalTo(AttributeKey.stringKey("string key"), "string value"),
@@ -71,8 +70,7 @@ void keyValue() {
7170
equalTo(AttributeKey.longKey("int key"), 3),
7271
equalTo(AttributeKey.longKey("long key"), 4),
7372
equalTo(AttributeKey.doubleKey("float key"), 5.0),
74-
equalTo(AttributeKey.doubleKey("double key"), 6.0),
75-
equalTo(AttributeKey.stringKey("log.body.template"), "log message 1")));
73+
equalTo(AttributeKey.doubleKey("double key"), 6.0)));
7674
}
7775

7876
@Test
@@ -92,12 +90,11 @@ void multipleMarkers() {
9290
.hasResource(resource)
9391
.hasInstrumentationScope(instrumentationScopeInfo)
9492
.hasBody("log message 1")
95-
.hasTotalAttributeCount(codeAttributesLogCount() + 2) // 1 marker + 1 template
93+
.hasTotalAttributeCount(codeAttributesLogCount() + 1) // 1 marker
9694
.hasAttributesSatisfying(
9795
equalTo(
9896
AttributeKey.stringArrayKey("logback.marker"),
99-
Arrays.asList(markerName1, markerName2)),
100-
equalTo(AttributeKey.stringKey("log.body.template"), "log message 1")));
97+
Arrays.asList(markerName1, markerName2))));
10198
}
10299

103100
@Test

0 commit comments

Comments
 (0)