Skip to content

Commit

Permalink
Mark OpenTelemetry and @ConsumeEvent context as safe
Browse files Browse the repository at this point in the history
  • Loading branch information
cescoffier authored and gsmet committed Mar 2, 2022
1 parent 99d643d commit 25b6b4c
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 25b6b4c

Please sign in to comment.