Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.jboss.as.ejb3.deployment.EjbDeploymentInformation;
import org.jboss.as.ejb3.deployment.ModuleDeployment;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.remote.tracing.TracingHelper;
import org.jboss.as.network.ClientMapping;
import org.jboss.as.security.remoting.RemoteConnection;
import org.jboss.ejb.client.Affinity;
Expand Down Expand Up @@ -91,7 +92,6 @@
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMapAdapter;
import io.opentracing.util.GlobalTracer;

/**
Expand Down Expand Up @@ -208,7 +208,7 @@ public SecurityIdentity getSecurityIdentity() {
}

Span s = wrapContextAroundNewSpan(retrieveContextFromAttachments(attachments));
try(Scope _s = GlobalTracer.get().activateSpan(s)) {
try(Scope _s = TracingHelper.activateSpan(s)) {
final Map<String, Object> contextDataHolder = new HashMap<>();
result = invokeMethod(componentView, invokedMethod, invocationRequest, requestContent, cancellationFlag, contextDataHolder);
attachments.putAll(contextDataHolder);
Expand Down Expand Up @@ -272,7 +272,7 @@ private SpanContext retrieveContextFromAttachments(Map<String, Object> attachmen
stringAttachments.put(e.getKey(), (String) e.getValue());
}
}
return GlobalTracer.get().extract(Format.Builtin.TEXT_MAP, new TextMapAdapter(stringAttachments));
return GlobalTracer.get().extract(Format.Builtin.TEXT_MAP, TracingHelper.textMapAdaptor(stringAttachments));
}

private void updateAffinities(InvocationRequest invocationRequest, Map<String, Object> attachments, EJBLocator<?> ejbLocator, ComponentView componentView) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.jboss.as.ejb3.remote.tracing;

import io.opentracing.Scope;
import io.opentracing.ScopeManager;
import io.opentracing.Span;
import io.opentracing.propagation.TextMap;
import io.opentracing.propagation.TextMapExtractAdapter;
import io.opentracing.util.GlobalTracer;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

public class TracingHelper {

private static boolean usesDeprecatedApi = false;
private static Constructor<?> textMapAdapterCtor;
private static Method scopeManagerActivateMethod;

static {
try {
for(Method m : ScopeManager.class.getDeclaredMethods()) {
if(m.getName().equals("activate")) {
scopeManagerActivateMethod = m;
break;
}
}
if(scopeManagerActivateMethod == null) {
throw new IllegalStateException("Could not find ScopeManager#activate method.");
}
if(scopeManagerActivateMethod.getParameterCount() == 2) {
usesDeprecatedApi = true;
}
if(!usesDeprecatedApi) {
textMapAdapterCtor = ClassLoader.getSystemClassLoader()
.loadClass("io.opentracing.propagation.TextMapAdapter")
.getConstructors()[0];
} else {
textMapAdapterCtor = TextMapExtractAdapter.class.getConstructors()[0];
}
} catch (ClassNotFoundException e) {
throw new RuntimeException("WildFly does not use deprecated OpenTracing API but the class " +
"io.opentracing.propagation.TextMapAdapter was not found on the classpath.", e);
}
}

public static Scope activateSpan(Span s) {
try {
if(usesDeprecatedApi) {
return (Scope) scopeManagerActivateMethod.invoke(GlobalTracer.get().scopeManager(), s, false);
}
return (Scope) scopeManagerActivateMethod.invoke(GlobalTracer.get().scopeManager(), s);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}

public static TextMap textMapAdaptor(Map<String, String> stringAttachments) {
try {
return (TextMap) textMapAdapterCtor.newInstance(stringAttachments);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<module name="org.wildfly.reactive.dep.jts" services="import" optional="true"/>

<!-- For OpenTracing -->
<!--<module name="io.narayana.tracing" optional="true"/>-->
<module name="io.narayana.tracing" optional="true"/>
<module name="io.opentracing.opentracing-api" optional="true"/>
<module name="io.opentracing.opentracing-util" optional="true"/>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
<version.io.agroal>1.3</version.io.agroal>
<version.io.jaegertracing>0.34.3</version.io.jaegertracing>
<version.io.netty>4.1.48.Final</version.io.netty>
<version.io.opentracing>0.32.0</version.io.opentracing> <!-- 0.32 is needed as integrated to REST Easy where Tracer.buildSpan(...).startActive() is used, while 0.33.0 removed it -->
<version.io.opentracing>0.31.0</version.io.opentracing>
<version.io.opentracing.concurrent>0.2.1</version.io.opentracing.concurrent>
<version.io.opentracing.interceptors>0.0.4</version.io.opentracing.interceptors>
<version.io.opentracing.jaxrs2>0.4.1</version.io.opentracing.jaxrs2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;

import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.contrib.tracerresolver.TracerFactory;
import io.opentracing.mock.MockSpan;
Expand All @@ -15,6 +16,7 @@
import org.wildfly.test.integration.microprofile.opentracing.application.OpenTracingApplication;
import org.wildfly.test.integration.microprofile.opentracing.application.TracedEndpoint;
import org.jboss.as.test.shared.TestSuiteEnvironment;
import org.jboss.as.ejb3.remote.tracing.TracingHelper;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
Expand Down Expand Up @@ -75,7 +77,8 @@ public void clientRequestSpanJoinsServer() {

// test
// the first span
try (Scope ignored = tracer.buildSpan("existing-span").startActive(true)) {
Span s = tracer.buildSpan("existing-span").start();
try (Scope ignored = TracingHelper.activateSpan(s)) {

// the second span is the client request, as a child of `existing-span`
Client restClient = ClientTracingRegistrar.configure(ClientBuilder.newBuilder()).build();
Expand All @@ -88,6 +91,8 @@ public void clientRequestSpanJoinsServer() {
// just a sanity check
Assert.assertEquals(200, response.getStatus());
}
} finally {
s.finish();
}

// verify
Expand Down