Skip to content

Commit af43dfa

Browse files
author
Simon Zeltser
authored
fix: Add cleanup for Trace context (#266)
* fix: fixing tests to cleanup trace context Previously we didn't cleanup trace context so it could cause side effects to some tests as a result of added label in trace context tests. To mitigate this, we added a method to cleanup trace context from MDC as well as invoke it before every test * fix: fixing tests to cleanup trace context Previously we didn't cleanup trace context so it could cause side effects to some tests as a result of added label in trace context tests. To mitigate this, we added a method to cleanup trace context from MDC as well as invoke it before every test * fix: lint
1 parent e7753e6 commit af43dfa

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/main/java/com/google/cloud/logging/logback/TraceLoggingEventEnhancer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public static void setCurrentTraceId(String id) {
3535
MDC.put(TRACE_ID, id);
3636
}
3737

38+
/** Clearing a trace Id from the MDC */
39+
public static void clearTraceId() {
40+
MDC.remove(TRACE_ID);
41+
}
3842
/**
3943
* Get the Trace ID associated with any logging done by the current thread.
4044
*

src/test/java/com/google/cloud/logging/logback/TraceLoggingEventEnhancerTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import ch.qos.logback.classic.spi.LoggingEvent;
2222
import com.google.cloud.logging.LogEntry;
2323
import com.google.cloud.logging.Payload.StringPayload;
24+
import org.junit.After;
2425
import org.junit.Before;
2526
import org.junit.Test;
2627

@@ -32,6 +33,11 @@ public void setUp() {
3233
classUnderTest = new TraceLoggingEventEnhancer();
3334
}
3435

36+
@After
37+
public void tearDown() {
38+
TraceLoggingEventEnhancer.clearTraceId();
39+
}
40+
3541
@Test
3642
public void testEnhanceLogEntry() {
3743
// setup

0 commit comments

Comments
 (0)