Skip to content

Commit 6a3dd1e

Browse files
authored
Fix opentelemetry context manager auto-registration. (#600)
The serviceloader file was in the wrong location. Added unit test to ensure this works again and keeps working. This fixes #599 Signed-off-by: Sjoerd Talsma <[email protected]>
1 parent aeef944 commit 6a3dd1e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

managers/context-manager-opentelemetry/src/test/java/nl/talsmasoftware/context/managers/opentelemetry/OpenTelemetryContextManagerTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.opentelemetry.context.ContextKey;
2020
import io.opentelemetry.context.Scope;
2121
import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
22+
import nl.talsmasoftware.context.api.ContextSnapshot;
2223
import org.junit.jupiter.api.Test;
2324
import org.junit.jupiter.api.extension.RegisterExtension;
2425

@@ -87,4 +88,20 @@ void clear_does_nothing_but_also_does_not_throw_exception() {
8788
void toString_returns_simple_classname() {
8889
assertThat(subject).hasToString("OpenTelemetryContextManager");
8990
}
91+
92+
@Test
93+
void automaticRegistration() {
94+
ContextKey<Object> key = ContextKey.named("dummy");
95+
String dummyValue = UUID.randomUUID().toString();
96+
ContextSnapshot snapshot;
97+
try (Scope scope = Context.current().with(key, dummyValue).makeCurrent()) {
98+
snapshot = ContextSnapshot.capture();
99+
}
100+
101+
assertThat(Context.current().get(key)).isNull();
102+
try (ContextSnapshot.Reactivation reactivation = snapshot.reactivate()) {
103+
assertThat(Context.current().get(key)).isEqualTo(dummyValue);
104+
}
105+
assertThat(Context.current().get(key)).isNull();
106+
}
90107
}

0 commit comments

Comments
 (0)