Skip to content

Commit e35b9f0

Browse files
log.body.parameters as stringArray
1 parent ee2d76f commit e35b9f0

File tree

2 files changed

+17
-9
lines changed
  • instrumentation/logback/logback-appender-1.0/library/src

2 files changed

+17
-9
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
import java.io.PrintWriter;
2525
import java.io.StringWriter;
2626
import java.util.ArrayList;
27+
import java.util.Arrays;
2728
import java.util.List;
2829
import java.util.Map;
2930
import java.util.concurrent.TimeUnit;
31+
import java.util.stream.Collectors;
3032
import org.slf4j.Marker;
3133
import org.slf4j.event.KeyValuePair;
3234

@@ -202,10 +204,9 @@ void captureMdcAttributes(AttributesBuilder attributes, Map<String, String> mdcP
202204
void captureArguments(AttributesBuilder attributes, String message, Object[] arguments) {
203205
String bodyKey = "log.body.template";
204206
attributes.put(bodyKey, message);
205-
for (int idx = 0; idx < arguments.length; idx++) {
206-
Object argument = arguments[idx];
207-
propagateAttribute(attributes, String.format("log.body.parameters.%d", idx), argument);
208-
}
207+
attributes.put(
208+
AttributeKey.stringArrayKey("log.body.parameters"),
209+
Arrays.stream(arguments).map(String::valueOf).collect(Collectors.toList()));
209210
}
210211

211212
public static AttributeKey<String> getMdcAttributeKey(String key) {

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,20 @@ void arguments() {
133133
assertThat(logData.getBody().asString())
134134
.isEqualTo(
135135
"log message 'world' and 3.141592653589793, bool true, long 9223372036854775807");
136-
assertThat(logData.getAttributes().size()).isEqualTo(9);
136+
assertThat(logData.getAttributes().size()).isEqualTo(6);
137+
assertThat(logData.getAttributes())
138+
.hasEntrySatisfying(
139+
AttributeKey.stringArrayKey("log.body.parameters"),
140+
value ->
141+
assertThat(value)
142+
.isEqualTo(
143+
Arrays.asList(
144+
"'world'",
145+
String.valueOf(Math.PI),
146+
String.valueOf(true),
147+
String.valueOf(Long.MAX_VALUE))));
137148
assertThat(logData)
138149
.hasAttributesSatisfying(
139-
equalTo(AttributeKey.stringKey("log.body.parameters.0"), "'world'"),
140-
equalTo(AttributeKey.doubleKey("log.body.parameters.1"), Math.PI),
141-
equalTo(AttributeKey.booleanKey("log.body.parameters.2"), true),
142-
equalTo(AttributeKey.longKey("log.body.parameters.3"), Long.MAX_VALUE),
143150
equalTo(
144151
AttributeKey.stringKey("log.body.template"),
145152
"log message {} and {}, bool {}, long {}"));

0 commit comments

Comments
 (0)