-
Notifications
You must be signed in to change notification settings - Fork 919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logback: don't make MDCPropertyMap of logging event immutable #12718
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -5,8 +5,12 @@ | |||
|
||||
package io.opentelemetry.instrumentation.logback.mdc.v1_0; | ||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; | ||||
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||||
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; | ||||
import java.util.Map; | ||||
import org.junit.jupiter.api.Test; | ||||
import org.junit.jupiter.api.extension.RegisterExtension; | ||||
|
||||
class LogbackTest extends AbstractLogbackTest { | ||||
|
@@ -18,4 +22,15 @@ class LogbackTest extends AbstractLogbackTest { | |||
public InstrumentationExtension getInstrumentationExtension() { | ||||
return testing; | ||||
} | ||||
|
||||
@Test | ||||
void testMdcMutable() { | ||||
TestAppender testAppender = TestAppender.instance; | ||||
runWithSpanAndBaggage("test", baggage, () -> logger.info("log message")); | ||||
|
||||
assertThat(testAppender.lastEvent.getMessage()).isEqualTo("log message"); | ||||
Map<String, String> map = testAppender.lastEvent.getMDCPropertyMap(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two instrumentation points: Line 54 in 8ff6cb0
Is there any reason to miss getMdc test here?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a library instrumentation tests. It only serves as a regression test to ensure that we don't accidentally introduce something similar to the union map in the future. |
||||
// verify that mdc map associated with the event is mutable | ||||
map.put("test", "test"); | ||||
} | ||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,70 @@ | ||||||
/* | ||||||
* Copyright The OpenTelemetry Authors | ||||||
* SPDX-License-Identifier: Apache-2.0 | ||||||
*/ | ||||||
|
||||||
package io.opentelemetry.instrumentation.logback.mdc.v1_0; | ||||||
|
||||||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||||||
import ch.qos.logback.core.Appender; | ||||||
import ch.qos.logback.core.UnsynchronizedAppenderBase; | ||||||
import ch.qos.logback.core.spi.AppenderAttachable; | ||||||
import ch.qos.logback.core.spi.AppenderAttachableImpl; | ||||||
import java.util.Iterator; | ||||||
|
||||||
public class TestAppender extends UnsynchronizedAppenderBase<ILoggingEvent> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this class must be public |
||||||
implements AppenderAttachable<ILoggingEvent> { | ||||||
|
||||||
static TestAppender instance; | ||||||
private final AppenderAttachableImpl<ILoggingEvent> aai = new AppenderAttachableImpl<>(); | ||||||
ILoggingEvent lastEvent; | ||||||
|
||||||
public TestAppender() { | ||||||
instance = this; | ||||||
} | ||||||
|
||||||
private void processEvent(ILoggingEvent event) { | ||||||
lastEvent = event; | ||||||
} | ||||||
|
||||||
@Override | ||||||
protected void append(ILoggingEvent event) { | ||||||
processEvent(event); | ||||||
aai.appendLoopOnAppenders(event); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public void addAppender(Appender<ILoggingEvent> appender) { | ||||||
aai.addAppender(appender); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public Iterator<Appender<ILoggingEvent>> iteratorForAppenders() { | ||||||
return aai.iteratorForAppenders(); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public Appender<ILoggingEvent> getAppender(String name) { | ||||||
return aai.getAppender(name); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public boolean isAttached(Appender<ILoggingEvent> appender) { | ||||||
return aai.isAttached(appender); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public void detachAndStopAllAppenders() { | ||||||
aai.detachAndStopAllAppenders(); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public boolean detachAppender(Appender<ILoggingEvent> appender) { | ||||||
return aai.detachAppender(appender); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public boolean detachAppender(String name) { | ||||||
return aai.detachAppender(name); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was there some benefit in retaining both individual maps with the use of
UnionMap
that we lose now?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It avoided copying the original map.