Skip to content
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

fix: Add cleanup for Trace context #266

Merged
merged 3 commits into from Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -31,10 +31,15 @@ public class TraceLoggingEventEnhancer implements LoggingEventEnhancer {
*
* @param id The traceID, in the form projects/[PROJECT_ID]/traces/[TRACE_ID]
*/
public static void setCurrentTraceId(String id) {
MDC.put(TRACE_ID, id);
}
public static void setCurrentTraceId(String id) { MDC.put(TRACE_ID, id); }

/**
* Clearing a trace Id from the MDC
*
*/
chingor13 marked this conversation as resolved.
Show resolved Hide resolved
public static void clearTraceId() {
MDC.remove(TRACE_ID);
}
/**
* Get the Trace ID associated with any logging done by the current thread.
*
Expand Down
Expand Up @@ -21,6 +21,7 @@
import ch.qos.logback.classic.spi.LoggingEvent;
import com.google.cloud.logging.LogEntry;
import com.google.cloud.logging.Payload.StringPayload;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

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

@After
public void tearDown() {
TraceLoggingEventEnhancer.clearTraceId();
}

@Test
public void testEnhanceLogEntry() {
// setup
Expand Down