diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/kotlin/KotlinObservationContextElement.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/kotlin/KotlinObservationContextElement.java index 7ec57275a7..598d03eef8 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/kotlin/KotlinObservationContextElement.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/kotlin/KotlinObservationContextElement.java @@ -19,6 +19,7 @@ import io.micrometer.common.lang.Nullable; import io.micrometer.context.ContextRegistry; import io.micrometer.context.ContextSnapshot; +import io.micrometer.context.ContextSnapshotFactory; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor; @@ -41,8 +42,11 @@ class KotlinObservationContextElement implements ThreadContextElement async(FakeAsyncTask fakeAsyncTask) { System.out.println("async"); - ContextSnapshot contextSnapshot = ContextSnapshot.captureAllUsing(o -> true, ContextRegistry.getInstance()); + ContextSnapshot contextSnapshot = ContextSnapshotFactory.builder() + .captureKeyPredicate(key -> true) + .contextRegistry(ContextRegistry.getInstance()) + .build() + .captureAll(); return CompletableFuture.supplyAsync(fakeAsyncTask, contextSnapshot.wrapExecutor(Executors.newSingleThreadExecutor())); } @@ -373,7 +378,11 @@ void error() { CompletableFuture async(FakeAsyncTask fakeAsyncTask) { System.out.println("async"); - ContextSnapshot contextSnapshot = ContextSnapshot.captureAllUsing(o -> true, ContextRegistry.getInstance()); + ContextSnapshot contextSnapshot = ContextSnapshotFactory.builder() + .captureKeyPredicate(key -> true) + .contextRegistry(ContextRegistry.getInstance()) + .build() + .captureAll(); return CompletableFuture.supplyAsync(fakeAsyncTask, contextSnapshot.wrapExecutor(Executors.newSingleThreadExecutor())); } diff --git a/micrometer-observation/src/test/java/io/micrometer/observation/contextpropagation/ObservationThreadLocalAccessorTests.java b/micrometer-observation/src/test/java/io/micrometer/observation/contextpropagation/ObservationThreadLocalAccessorTests.java index 7f46d4e95a..d98e8b9872 100644 --- a/micrometer-observation/src/test/java/io/micrometer/observation/contextpropagation/ObservationThreadLocalAccessorTests.java +++ b/micrometer-observation/src/test/java/io/micrometer/observation/contextpropagation/ObservationThreadLocalAccessorTests.java @@ -107,7 +107,11 @@ void capturedThreadLocalValuesShouldBeCapturedRestoredAndCleared() try (Observation.Scope scope2 = child.openScope()) { thenCurrentObservationHasParent(parent, child); then(child.getEnclosingScope()).isSameAs(scope2); - container = ContextSnapshot.captureAllUsing(key -> true, registry); + container = ContextSnapshotFactory.builder() + .captureKeyPredicate(key -> true) + .contextRegistry(registry) + .build() + .captureAll(); } }