Skip to content

Commit

Permalink
Merge branch '1.11.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatan-ivanov committed Sep 20, 2023
2 parents 8d18d8c + c024548 commit f267eeb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,8 +42,11 @@ class KotlinObservationContextElement implements ThreadContextElement<ContextSna

KotlinObservationContextElement(ObservationRegistry observationRegistry, ContextRegistry contextRegistry) {
this.observationRegistry = observationRegistry;
this.contextSnapshot = ContextSnapshot.captureAllUsing(ObservationThreadLocalAccessor.KEY::equals,
contextRegistry);
this.contextSnapshot = ContextSnapshotFactory.builder()
.captureKeyPredicate(ObservationThreadLocalAccessor.KEY::equals)
.contextRegistry(contextRegistry)
.build()
.captureAll();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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.ObservationConvention;
import io.micrometer.observation.ObservationTextPublisher;
Expand Down Expand Up @@ -351,7 +352,11 @@ void error() {
@Observed(name = "test.async")
CompletableFuture<String> 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()));
}
Expand All @@ -373,7 +378,11 @@ void error() {

CompletableFuture<String> 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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit f267eeb

Please sign in to comment.