Skip to content

Commit d644db3

Browse files
committed
have constants for attribute keys, revert extracting key value pair handling to separate method
1 parent 22c6082 commit d644db3

File tree

1 file changed

+22
-23
lines changed
  • instrumentation/logback/logback-appender-1.0/library/src/main/java/io/opentelemetry/instrumentation/logback/appender/v1_0/internal

1 file changed

+22
-23
lines changed

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

+22-23
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public final class LoggingEventMapper {
5454

5555
private static final AttributeKey<List<String>> LOG_MARKER =
5656
AttributeKey.stringArrayKey("logback.marker");
57+
private static final AttributeKey<String> LOG_BODY_TEMPLATE =
58+
AttributeKey.stringKey("log.body.template");
59+
private static final AttributeKey<List<String>> LOG_BODY_PARAMETERS =
60+
AttributeKey.stringArrayKey("log.body.parameters");
5761

5862
private final boolean captureExperimentalAttributes;
5963
private final List<String> captureMdcAttributes;
@@ -202,10 +206,9 @@ void captureMdcAttributes(AttributesBuilder attributes, Map<String, String> mdcP
202206
}
203207

204208
void captureArguments(AttributesBuilder attributes, String message, Object[] arguments) {
205-
String bodyKey = "log.body.template";
206-
attributes.put(bodyKey, message);
209+
attributes.put(LOG_BODY_TEMPLATE, message);
207210
attributes.put(
208-
AttributeKey.stringArrayKey("log.body.parameters"),
211+
LOG_BODY_PARAMETERS,
209212
Arrays.stream(arguments).map(String::valueOf).collect(Collectors.toList()));
210213
}
211214

@@ -249,26 +252,22 @@ private static void captureKeyValuePairAttributes(
249252
if (keyValuePairs != null) {
250253
for (KeyValuePair keyValuePair : keyValuePairs) {
251254
Object value = keyValuePair.value;
252-
propagateAttribute(attributes, keyValuePair.key, value);
253-
}
254-
}
255-
}
256-
257-
@NoMuzzle
258-
private static void propagateAttribute(AttributesBuilder attributes, String key, Object value) {
259-
if (value != null) {
260-
// preserve type for boolean and numeric values, everything else is converted to String
261-
if (value instanceof Boolean) {
262-
attributes.put(key, (Boolean) value);
263-
} else if (value instanceof Byte
264-
|| value instanceof Integer
265-
|| value instanceof Long
266-
|| value instanceof Short) {
267-
attributes.put(key, ((Number) value).longValue());
268-
} else if (value instanceof Double || value instanceof Float) {
269-
attributes.put(key, ((Number) value).doubleValue());
270-
} else {
271-
attributes.put(getAttributeKey(key), value.toString());
255+
if (value != null) {
256+
String key = keyValuePair.key;
257+
// preserve type for boolean and numeric values, everything else is converted to String
258+
if (value instanceof Boolean) {
259+
attributes.put(key, (Boolean) value);
260+
} else if (value instanceof Byte
261+
|| value instanceof Integer
262+
|| value instanceof Long
263+
|| value instanceof Short) {
264+
attributes.put(key, ((Number) value).longValue());
265+
} else if (value instanceof Double || value instanceof Float) {
266+
attributes.put(key, ((Number) value).doubleValue());
267+
} else {
268+
attributes.put(getAttributeKey(key), value.toString());
269+
}
270+
}
272271
}
273272
}
274273
}

0 commit comments

Comments
 (0)