Skip to content

Commit

Permalink
Remove mdc attributes prefix (#9536)
Browse files Browse the repository at this point in the history
Co-authored-by: Trask Stalnaker <[email protected]>
  • Loading branch information
SHaaD94 and trask authored Jan 5, 2024
1 parent 3cd9f70 commit 2ee4ee1
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ private void captureMdcAttributes(AttributesBuilder attributes) {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ void testMdc() {
.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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private void captureMdcAttributes(AttributesBuilder attributes) {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ void testMdc() {
.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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ void testContextData() {
.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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ void testMdc() {
.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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ void captureContextDataAttributes(AttributesBuilder attributes, T contextData) {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ void logContextData() {
.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ void testSome() {
mapper.captureContextDataAttributes(attributes, contextData);

// then
assertThat(attributes.build())
.containsOnly(attributeEntry("log4j.context_data.key2", "value2"));
assertThat(attributes.build()).containsOnly(attributeEntry("key2", "value2"));
}

@Test
Expand All @@ -79,9 +78,7 @@ void testAll() {

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ void testMdc() {
.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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void captureMdcAttributes(AttributesBuilder attributes, Map<String, String> mdcP
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,8 @@ void logContextData() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ void testSome() {
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
Expand All @@ -68,7 +67,7 @@ void testAll() {
// 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"));
}
}

0 comments on commit 2ee4ee1

Please sign in to comment.