diff --git a/tw-context-starter/build.gradle b/tw-context-starter/build.gradle index 5afede4..c28c294 100644 --- a/tw-context-starter/build.gradle +++ b/tw-context-starter/build.gradle @@ -7,6 +7,7 @@ apply from: '../build.common.gradle' dependencies { implementation libraries.springBootAutoconfigure implementation libraries.twBaseUtils + implementation libraries.micrometerContextPropagation api project(":tw-context:") testImplementation libraries.springBootStarterTest diff --git a/tw-context-starter/src/main/java/com/transferwise/common/context/TwContextAutoConfiguration.java b/tw-context-starter/src/main/java/com/transferwise/common/context/TwContextAutoConfiguration.java index 8dd689a..7d18d4a 100644 --- a/tw-context-starter/src/main/java/com/transferwise/common/context/TwContextAutoConfiguration.java +++ b/tw-context-starter/src/main/java/com/transferwise/common/context/TwContextAutoConfiguration.java @@ -12,6 +12,10 @@ @Configuration public class TwContextAutoConfiguration { + TwContextAutoConfiguration() { + ContextRegistry.getInstance().registerThreadLocalAccessor(new TwContextThreadLocalAccessor()); + } + @Bean @ConditionalOnMissingBean public UnitOfWorkManager twContextUnitOfWorkManager(IMeterCache meterCache) { diff --git a/tw-context/src/main/java/com/transferwise/common/context/TwContext.java b/tw-context/src/main/java/com/transferwise/common/context/TwContext.java index f2d6786..6bd0f60 100644 --- a/tw-context/src/main/java/com/transferwise/common/context/TwContext.java +++ b/tw-context/src/main/java/com/transferwise/common/context/TwContext.java @@ -3,7 +3,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.RateLimiter; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import io.micrometer.context.ContextRegistry; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -40,10 +39,6 @@ public class TwContext { static final TwContext ROOT_CONTEXT = new TwContext(null, true); - static { - ContextRegistry.getInstance().registerThreadLocalAccessor(new TwContextThreadLocalAccessor()); - } - public static TwContext current() { Optional twContext = contextTl.get(); return twContext == null || !twContext.isPresent() ? ROOT_CONTEXT : twContext.get();