Skip to content

Commit

Permalink
Merge remote-tracking branch 'antosh/main' into Antosch-main
Browse files Browse the repository at this point in the history
  • Loading branch information
marcingrzejszczak committed May 7, 2024
2 parents e9a6779 + 47483c9 commit ad48472
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import reactor.core.scheduler.Schedulers;
import reactor.util.context.Context;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.*;
Expand Down Expand Up @@ -376,6 +377,26 @@ void onlyReactorPropagatesBaggageWithContextCaptureAndObservation() {
assertThat(tenant).isEqualTo("tenantValue");
}

@Test
void observationAwareBaggageThreadLocalAccessorSetsAndClosesBaggageToPropagate()
throws ReflectiveOperationException {
then(getTracer().currentTraceContext().context()).isNull();

Observation.createNotStarted("First span", observationRegistry).observeChecked(() -> {
then(getTracer().currentTraceContext().context()).isNotNull();

BaggageToPropagate baggageToPropagate = new BaggageToPropagate("tenant", "tenantValue", "tenant2",
"tenant2Value");
observationAwareBaggageThreadLocalAccessor.setValue(baggageToPropagate);
Method closeCurrentScope = ObservationAwareBaggageThreadLocalAccessor.class
.getDeclaredMethod("closeCurrentScope");
closeCurrentScope.setAccessible(true);
return closeCurrentScope.invoke(observationAwareBaggageThreadLocalAccessor);
});

then(getTracer().currentTraceContext().context()).isNull();
}

private String asyncCall() {
logWithSpan("TASK EXECUTOR");
if (getTracer().currentSpan() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private static BaggageAndScope baggageScopeClosingScope(Entry<String, String> en
if (scope == null) {
return scopeClosingBaggageAndScope(entry, baggage);
}
return scope.andThen(scopeClosingBaggageAndScope(entry, baggage));
return scopeClosingBaggageAndScope(entry, baggage).andThen(scope);
}

private static BaggageAndScope scopeClosingBaggageAndScope(Entry<String, String> entry, BaggageInScope baggage) {
Expand Down

0 comments on commit ad48472

Please sign in to comment.