Remove mdc attributes prefix (#9536)

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
This commit is contained in:
Evgeniy Zuikin 2024-01-06 01:41:53 +07:00 committed by GitHub
parent 3cd9f701b4
commit 2ee4ee116d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 22 additions and 31 deletions

View File

@ -127,8 +127,7 @@ public final class LoggingEventMapper {
}
public static AttributeKey<String> getMdcAttributeKey(String key) {
return mdcAttributeKeys.computeIfAbsent(
key, k -> AttributeKey.stringKey("jboss-logmanager.mdc." + k));
return mdcAttributeKeys.computeIfAbsent(key, AttributeKey::stringKey);
}
private static Severity levelToSeverity(java.util.logging.Level level) {

View File

@ -205,8 +205,8 @@ class JbossLogmanagerTest {
.hasSeverity(Severity.INFO)
.hasSeverityText("INFO")
.hasAttributesSatisfyingExactly(
equalTo(AttributeKey.stringKey("jboss-logmanager.mdc.key1"), "val1"),
equalTo(AttributeKey.stringKey("jboss-logmanager.mdc.key2"), "val2"),
equalTo(AttributeKey.stringKey("key1"), "val1"),
equalTo(AttributeKey.stringKey("key2"), "val2"),
equalTo(SemanticAttributes.THREAD_NAME, Thread.currentThread().getName()),
equalTo(SemanticAttributes.THREAD_ID, Thread.currentThread().getId()));
}

View File

@ -135,7 +135,7 @@ public final class LogEventMapper {
}
private static AttributeKey<String> getMdcAttributeKey(String key) {
return mdcAttributeKeys.computeIfAbsent(key, k -> AttributeKey.stringKey("log4j.mdc." + k));
return mdcAttributeKeys.computeIfAbsent(key, AttributeKey::stringKey);
}
private static Severity levelToSeverity(Priority level) {

View File

@ -155,8 +155,8 @@ class Log4j1Test {
.hasSeverity(Severity.INFO)
.hasSeverityText("INFO")
.hasAttributesSatisfyingExactly(
equalTo(AttributeKey.stringKey("log4j.mdc.key1"), "val1"),
equalTo(AttributeKey.stringKey("log4j.mdc.key2"), "val2"),
equalTo(AttributeKey.stringKey("key1"), "val1"),
equalTo(AttributeKey.stringKey("key2"), "val2"),
equalTo(SemanticAttributes.THREAD_NAME, Thread.currentThread().getName()),
equalTo(SemanticAttributes.THREAD_ID, Thread.currentThread().getId()));
}

View File

@ -143,8 +143,8 @@ class Log4j2Test {
.hasSeverity(Severity.INFO)
.hasSeverityText("INFO")
.hasAttributesSatisfyingExactly(
equalTo(AttributeKey.stringKey("log4j.context_data.key1"), "val1"),
equalTo(AttributeKey.stringKey("log4j.context_data.key2"), "val2"),
equalTo(AttributeKey.stringKey("key1"), "val1"),
equalTo(AttributeKey.stringKey("key2"), "val2"),
equalTo(SemanticAttributes.THREAD_NAME, Thread.currentThread().getName()),
equalTo(SemanticAttributes.THREAD_ID, Thread.currentThread().getId()));
}

View File

@ -132,8 +132,8 @@ class Slf4jToLog4jTest {
.hasSeverity(Severity.INFO)
.hasSeverityText("INFO")
.hasAttributesSatisfyingExactly(
equalTo(AttributeKey.stringKey("log4j.context_data.key1"), "val1"),
equalTo(AttributeKey.stringKey("log4j.context_data.key2"), "val2"),
equalTo(AttributeKey.stringKey("key1"), "val1"),
equalTo(AttributeKey.stringKey("key2"), "val2"),
equalTo(SemanticAttributes.THREAD_NAME, Thread.currentThread().getName()),
equalTo(SemanticAttributes.THREAD_ID, Thread.currentThread().getId()));
}

View File

@ -176,8 +176,7 @@ public final class LogEventMapper<T> {
}
public static AttributeKey<String> getContextDataAttributeKey(String key) {
return contextDataAttributeKeyCache.computeIfAbsent(
key, k -> AttributeKey.stringKey("log4j.context_data." + k));
return contextDataAttributeKeyCache.computeIfAbsent(key, AttributeKey::stringKey);
}
public static AttributeKey<String> getMapMessageAttributeKey(String key) {

View File

@ -166,8 +166,7 @@ abstract class AbstractOpenTelemetryAppenderTest {
.hasInstrumentationScope(instrumentationScopeInfo)
.hasBody("log message 1")
.hasAttributesSatisfyingExactly(
equalTo(stringKey("log4j.context_data.key1"), "val1"),
equalTo(stringKey("log4j.context_data.key2"), "val2"));
equalTo(stringKey("key1"), "val1"), equalTo(stringKey("key2"), "val2"));
}
@Test

View File

@ -59,8 +59,7 @@ class LogEventMapperTest {
mapper.captureContextDataAttributes(attributes, contextData);
// then
assertThat(attributes.build())
.containsOnly(attributeEntry("log4j.context_data.key2", "value2"));
assertThat(attributes.build()).containsOnly(attributeEntry("key2", "value2"));
}
@Test
@ -79,9 +78,7 @@ class LogEventMapperTest {
// then
assertThat(attributes.build())
.containsOnly(
attributeEntry("log4j.context_data.key1", "value1"),
attributeEntry("log4j.context_data.key2", "value2"));
.containsOnly(attributeEntry("key1", "value1"), attributeEntry("key2", "value2"));
}
@Test

View File

@ -193,8 +193,8 @@ class LogbackTest {
.hasSeverity(Severity.INFO)
.hasSeverityText("INFO")
.hasAttributesSatisfyingExactly(
equalTo(AttributeKey.stringKey("logback.mdc.key1"), "val1"),
equalTo(AttributeKey.stringKey("logback.mdc.key2"), "val2"),
equalTo(AttributeKey.stringKey("key1"), "val1"),
equalTo(AttributeKey.stringKey("key2"), "val2"),
equalTo(SemanticAttributes.THREAD_NAME, Thread.currentThread().getName()),
equalTo(SemanticAttributes.THREAD_ID, Thread.currentThread().getId()),
equalTo(SemanticAttributes.CODE_NAMESPACE, LogbackTest.class.getName()),

View File

@ -183,7 +183,7 @@ public final class LoggingEventMapper {
}
public static AttributeKey<String> getMdcAttributeKey(String key) {
return mdcAttributeKeys.computeIfAbsent(key, k -> AttributeKey.stringKey("logback.mdc." + k));
return mdcAttributeKeys.computeIfAbsent(key, AttributeKey::stringKey);
}
private static void setThrowable(AttributesBuilder attributes, Throwable throwable) {

View File

@ -168,10 +168,8 @@ abstract class AbstractOpenTelemetryAppenderTest {
assertThat(logData.getInstrumentationScopeInfo()).isEqualTo(instrumentationScopeInfo);
assertThat(logData.getBody().asString()).isEqualTo("log message 1");
assertThat(logData.getAttributes().size()).isEqualTo(2 + 4); // 4 code attributes
assertThat(logData.getAttributes().get(AttributeKey.stringKey("logback.mdc.key1")))
.isEqualTo("val1");
assertThat(logData.getAttributes().get(AttributeKey.stringKey("logback.mdc.key2")))
.isEqualTo("val2");
assertThat(logData.getAttributes().get(AttributeKey.stringKey("key1"))).isEqualTo("val1");
assertThat(logData.getAttributes().get(AttributeKey.stringKey("key2"))).isEqualTo("val2");
}
@Test

View File

@ -48,8 +48,7 @@ class LoggingEventMapperTest {
mapper.captureMdcAttributes(attributes, contextData);
// then
assertThat(attributes.build())
.containsOnly(entry(AttributeKey.stringKey("logback.mdc.key2"), "value2"));
assertThat(attributes.build()).containsOnly(entry(AttributeKey.stringKey("key2"), "value2"));
}
@Test
@ -68,7 +67,7 @@ class LoggingEventMapperTest {
// then
assertThat(attributes.build())
.containsOnly(
entry(AttributeKey.stringKey("logback.mdc.key1"), "value1"),
entry(AttributeKey.stringKey("logback.mdc.key2"), "value2"));
entry(AttributeKey.stringKey("key1"), "value1"),
entry(AttributeKey.stringKey("key2"), "value2"));
}
}