Skip to content

Commit

Permalink
Merge pull request quarkusio#24048 from cescoffier/more-safe-dc
Browse files Browse the repository at this point in the history
Mark OpenTelemetry and @ConsumeEvent context as safe
  • Loading branch information
gsmet authored Mar 2, 2022
2 parents ee50eed + cf586c1 commit b966f1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.opentelemetry.runtime;

import static io.quarkus.vertx.core.runtime.context.VertxContextSafetyToggle.setContextSafe;
import static io.smallrye.common.vertx.VertxContext.getOrCreateDuplicatedContext;
import static io.smallrye.common.vertx.VertxContext.isDuplicatedContext;

Expand Down Expand Up @@ -85,8 +86,12 @@ public Scope attach(io.vertx.core.Context vertxContext, Context toAttach) {
*/
@Override
public Context current() {
return Vertx.currentContext() != null ? getOrCreateDuplicatedContext(vertx).getLocal(OTEL_CONTEXT)
: DEFAULT_CONTEXT_STORAGE.current();
io.vertx.core.Context current = getVertxContext();
if (current != null) {
return current.getLocal(OTEL_CONTEXT);
} else {
return DEFAULT_CONTEXT_STORAGE.current();
}
}

/**
Expand All @@ -108,6 +113,12 @@ public static Context getContext(io.vertx.core.Context vertxContext) {
* @return a duplicated Vert.x Context or null.
*/
private static io.vertx.core.Context getVertxContext() {
return Vertx.currentContext() != null ? getOrCreateDuplicatedContext(vertx) : null;
io.vertx.core.Context context = Vertx.currentContext();
if (context != null) {
io.vertx.core.Context dc = getOrCreateDuplicatedContext(context);
setContextSafe(dc, true);
return dc;
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.vertx.runtime;

import static io.quarkus.vertx.core.runtime.context.VertxContextSafetyToggle.setContextSafe;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -100,6 +102,7 @@ public void handle(Message<Object> m) {
if (invoker.isBlocking()) {
// We need to create a duplicated context from the "context"
Context dup = VertxContext.getOrCreateDuplicatedContext(context);
setContextSafe(dup, true);
dup.executeBlocking(new Handler<Promise<Object>>() {
@Override
public void handle(Promise<Object> event) {
Expand Down

0 comments on commit b966f1d

Please sign in to comment.