Skip to content

Commit

Permalink
fix: Add cleanup for Trace context (#266)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Simon Zeltser committed Dec 10, 2020
1 parent e7753e6 commit af43dfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Expand Up @@ -35,6 +35,10 @@ public static void setCurrentTraceId(String id) {
MDC.put(TRACE_ID, id);
}

/** Clearing a trace Id from the MDC */
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

1 comment on commit af43dfa

@darewreck54
Copy link

@darewreck54 darewreck54 commented on af43dfa Dec 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonz130 do you know when they will publish this library to the maven registry? Right now it looks like the latest is 0.119.0-alpha https://mvnrepository.com/artifact/com.google.cloud/google-cloud-logging-logback

Please sign in to comment.