diff --git a/microprofile/opentracing-extension/src/main/java/org/wildfly/extension/microprofile/opentracing/TracingDependencyProcessor.java b/microprofile/opentracing-extension/src/main/java/org/wildfly/extension/microprofile/opentracing/TracingDependencyProcessor.java
index 28092b1b4273..67f21b2da172 100644
--- a/microprofile/opentracing-extension/src/main/java/org/wildfly/extension/microprofile/opentracing/TracingDependencyProcessor.java
+++ b/microprofile/opentracing-extension/src/main/java/org/wildfly/extension/microprofile/opentracing/TracingDependencyProcessor.java
@@ -22,6 +22,8 @@
package org.wildfly.extension.microprofile.opentracing;
+import org.jboss.as.ee.structure.DeploymentType;
+import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
@@ -43,6 +45,10 @@ public void deploy(DeploymentPhaseContext phaseContext) {
}
private void addDependencies(DeploymentUnit deploymentUnit) {
+ if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
+ return;
+ }
+
ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
ModuleLoader moduleLoader = Module.getBootModuleLoader();
diff --git a/microprofile/opentracing-extension/src/main/java/org/wildfly/extension/microprofile/opentracing/TracingDeploymentProcessor.java b/microprofile/opentracing-extension/src/main/java/org/wildfly/extension/microprofile/opentracing/TracingDeploymentProcessor.java
index e43fa37dd9cf..9f2f2573d6b3 100644
--- a/microprofile/opentracing-extension/src/main/java/org/wildfly/extension/microprofile/opentracing/TracingDeploymentProcessor.java
+++ b/microprofile/opentracing-extension/src/main/java/org/wildfly/extension/microprofile/opentracing/TracingDeploymentProcessor.java
@@ -22,18 +22,17 @@
package org.wildfly.extension.microprofile.opentracing;
-import io.smallrye.opentracing.SmallRyeTracingDynamicFeature;
+import org.jboss.as.ee.structure.DeploymentType;
+import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.ee.weld.WeldDeploymentMarker;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.web.common.WarMetaData;
-import org.jboss.as.weld.deployment.WeldPortableExtensions;
import org.jboss.metadata.javaee.spec.ParamValueMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.spec.ListenerMetaData;
import org.wildfly.microprofile.opentracing.smallrye.TracerInitializer;
-import org.wildfly.microprofile.opentracing.smallrye.TracingCDIExtension;
import org.wildfly.security.manager.WildFlySecurityManager;
import java.util.ArrayList;
@@ -45,19 +44,18 @@ public void deploy(DeploymentPhaseContext deploymentPhaseContext) {
TracingExtensionLogger.ROOT_LOGGER.processingDeployment();
DeploymentUnit deploymentUnit = deploymentPhaseContext.getDeploymentUnit();
+ if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
+ return;
+ }
+
if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
// SmallRye JAX-RS requires CDI. Without CDI, there's no integration needed
TracingExtensionLogger.ROOT_LOGGER.noCdiDeployment();
return;
}
+ setServiceName(deploymentUnit);
addListeners(deploymentUnit);
- addJaxRsIntegration(deploymentUnit);
- addCDIExtension(deploymentUnit);
- }
-
- @Override
- public void undeploy(DeploymentUnit deploymentUnit) {
}
private void addListeners(DeploymentUnit deploymentUnit) {
@@ -69,12 +67,6 @@ private void addListeners(DeploymentUnit deploymentUnit) {
TracingExtensionLogger.ROOT_LOGGER.registeringTracerInitializer();
- String serviceName = getServiceName(deploymentUnit);
- ParamValueMetaData serviceNameContextParameter = new ParamValueMetaData();
- serviceNameContextParameter.setParamName(TracerInitializer.SMALLRYE_OPENTRACING_SERVICE_NAME);
- serviceNameContextParameter.setParamValue(serviceName);
- addContextParameter(jbossWebMetaData, serviceNameContextParameter);
-
ListenerMetaData listenerMetaData = new ListenerMetaData();
listenerMetaData.setListenerClass(TracerInitializer.class.getName());
@@ -86,26 +78,18 @@ private void addListeners(DeploymentUnit deploymentUnit) {
jbossWebMetaData.setListeners(listeners);
}
- private void addJaxRsIntegration(DeploymentUnit deploymentUnit) {
+ private void setServiceName(DeploymentUnit deploymentUnit) {
JBossWebMetaData jbossWebMetaData = getJBossWebMetaData(deploymentUnit);
if (null == jbossWebMetaData) {
// nothing to do here
return;
}
- TracingExtensionLogger.ROOT_LOGGER.registeringJaxRs();
-
- ParamValueMetaData restEasyProvider = new ParamValueMetaData();
- restEasyProvider.setParamName("resteasy.providers");
- restEasyProvider.setParamValue(SmallRyeTracingDynamicFeature.class.getName());
- addContextParameter(jbossWebMetaData, restEasyProvider);
- }
-
- private void addCDIExtension(DeploymentUnit deploymentUnit) {
- TracingExtensionLogger.ROOT_LOGGER.registeringCDIExtension();
-
- WeldPortableExtensions extensions = WeldPortableExtensions.getPortableExtensions(deploymentUnit);
- extensions.registerExtensionInstance(new TracingCDIExtension(), deploymentUnit);
+ String serviceName = getServiceName(deploymentUnit);
+ ParamValueMetaData serviceNameContextParameter = new ParamValueMetaData();
+ serviceNameContextParameter.setParamName(TracerInitializer.SMALLRYE_OPENTRACING_SERVICE_NAME);
+ serviceNameContextParameter.setParamValue(serviceName);
+ addContextParameter(jbossWebMetaData, serviceNameContextParameter);
}
private JBossWebMetaData getJBossWebMetaData(DeploymentUnit deploymentUnit) {
@@ -134,10 +118,22 @@ private String getServiceName(DeploymentUnit deploymentUnit) {
}
if (null == serviceName || serviceName.isEmpty()) {
+ if (null != deploymentUnit.getParent()) {
+ // application.ear!module.war
+ serviceName = deploymentUnit.getParent().getServiceName().getSimpleName()
+ + "!"
+ + deploymentUnit.getServiceName().getSimpleName();
+ } else {
+ serviceName = deploymentUnit.getServiceName().getSimpleName();
+ }
+
TracingExtensionLogger.ROOT_LOGGER.serviceNameDerivedFromDeploymentUnit(serviceName);
- serviceName = deploymentUnit.getServiceName().getSimpleName();
}
return serviceName;
}
+
+ @Override
+ public void undeploy(DeploymentUnit deploymentUnit) {
+ }
}
diff --git a/microprofile/opentracing-extension/src/main/java/org/wildfly/extension/microprofile/opentracing/TracingExtensionLogger.java b/microprofile/opentracing-extension/src/main/java/org/wildfly/extension/microprofile/opentracing/TracingExtensionLogger.java
index 60ba6df27e15..8bfb48509a6a 100644
--- a/microprofile/opentracing-extension/src/main/java/org/wildfly/extension/microprofile/opentracing/TracingExtensionLogger.java
+++ b/microprofile/opentracing-extension/src/main/java/org/wildfly/extension/microprofile/opentracing/TracingExtensionLogger.java
@@ -43,18 +43,10 @@ public interface TracingExtensionLogger extends BasicLogger {
@Message(id = 2, value = "MicroProfile OpenTracing Subsystem is processing deployment")
void processingDeployment();
- @LogMessage(level = DEBUG)
- @Message(id = 3, value = "Registering SmallRye CDI Extension")
- void registeringCDIExtension();
-
@LogMessage(level = DEBUG)
@Message(id = 4, value = "The deployment does not have CDI enabled. Skipping MicroProfile OpenTracing integration.")
void noCdiDeployment();
- @LogMessage(level = DEBUG)
- @Message(id = 5, value = "Registering MicroProfile OpenTracing JAX-RS integration")
- void registeringJaxRs();
-
@LogMessage(level = DEBUG)
@Message(id = 6, value = "Deriving service name based on the deployment unit's name: %s")
void serviceNameDerivedFromDeploymentUnit(String serviceName);
diff --git a/microprofile/opentracing-smallrye/pom.xml b/microprofile/opentracing-smallrye/pom.xml
index ef30390ba0ee..aa01b53f7418 100644
--- a/microprofile/opentracing-smallrye/pom.xml
+++ b/microprofile/opentracing-smallrye/pom.xml
@@ -39,6 +39,10 @@
WildFly: MicroProfile OpenTracing with SmallRye
+
+ org.jboss.spec.javax.ws.rs
+ jboss-jaxrs-api_2.1_spec
+
io.opentracing.contrib
opentracing-jaxrs2
diff --git a/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracerDynamicFeature.java b/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracerDynamicFeature.java
new file mode 100644
index 000000000000..2d81e147bf51
--- /dev/null
+++ b/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracerDynamicFeature.java
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2018, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.wildfly.microprofile.opentracing.smallrye;
+
+import io.opentracing.Tracer;
+import io.opentracing.contrib.jaxrs2.server.OperationNameProvider;
+import io.opentracing.contrib.jaxrs2.server.ServerTracingDynamicFeature;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.container.DynamicFeature;
+import javax.ws.rs.container.ResourceInfo;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.FeatureContext;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class TracerDynamicFeature implements DynamicFeature {
+ @Context
+ ServletContext servletContext;
+
+ @Override
+ public void configure(ResourceInfo resourceInfo, FeatureContext context) {
+ Tracer tracer;
+
+ Object tracerObject = servletContext.getAttribute(TracerInitializer.SMALLRYE_OPENTRACING_TRACER);
+ if (tracerObject instanceof Tracer) {
+ tracer = (Tracer) tracerObject;
+ } else {
+ // should never happen, but if it does, there's something really wrong
+ // we log a warn-level message here then
+ TracingLogger.ROOT_LOGGER.noTracerAvailable();
+ return;
+ }
+
+ ServerTracingDynamicFeature delegate = new ServerTracingDynamicFeature.Builder(tracer)
+ .withOperationNameProvider(OperationNameProvider.ClassNameOperationName.newBuilder())
+ .withTraceSerialization(false)
+ .build();
+
+ delegate.configure(resourceInfo, context);
+ }
+
+}
diff --git a/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracerInitializer.java b/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracerInitializer.java
index 62fd9a471994..b83082ab8298 100644
--- a/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracerInitializer.java
+++ b/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracerInitializer.java
@@ -29,10 +29,9 @@
import io.opentracing.noop.NoopTracerFactory;
import io.opentracing.util.GlobalTracer;
-import javax.enterprise.event.Event;
-import javax.inject.Inject;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
+import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@@ -41,18 +40,10 @@
@WebListener
public class TracerInitializer implements ServletContextListener {
public static final String SMALLRYE_OPENTRACING_SERVICE_NAME = "smallrye.opentracing.serviceName";
-
- @Inject
- Event tracerInitialized;
+ public static final String SMALLRYE_OPENTRACING_TRACER = "smallrye.opentracing.tracer";
@Override
public void contextInitialized(ServletContextEvent sce) {
- if (null == tracerInitialized) {
- // Weld integration problems? This happens with the test org.jboss.as.test.integration.ws.injection.ejb.basic.InjectionTestCase
- TracingLogger.ROOT_LOGGER.noCdiEventSupport();
- return;
- }
-
if (GlobalTracer.isRegistered()) {
TracingLogger.ROOT_LOGGER.alreadyRegistered();
return;
@@ -72,12 +63,16 @@ public void contextInitialized(ServletContextEvent sce) {
}
TracingLogger.ROOT_LOGGER.registeringTracer(tracer.getClass().getName());
- tracerInitialized.fire(tracer);
+ sce.getServletContext().setAttribute(SMALLRYE_OPENTRACING_TRACER, tracer);
+ addJaxRsIntegration(sce.getServletContext(), tracer);
TracingLogger.ROOT_LOGGER.initializing(tracer.toString());
+ }
- FilterRegistration.Dynamic filterRegistration = sce.getServletContext()
- .addFilter(SpanFinishingFilter.class.getName(), new SpanFinishingFilter(tracer));
+ private void addJaxRsIntegration(ServletContext servletContext, Tracer tracer) {
+ servletContext.setInitParameter("resteasy.providers", TracerDynamicFeature.class.getName());
+ FilterRegistration.Dynamic filterRegistration = servletContext.addFilter(SpanFinishingFilter.class.getName(),
+ new SpanFinishingFilter(tracer));
filterRegistration.setAsyncSupported(true);
filterRegistration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "*");
}
diff --git a/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracerProducer.java b/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracerProducer.java
index 3be536bf6f24..cb8fc23a617d 100644
--- a/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracerProducer.java
+++ b/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracerProducer.java
@@ -25,19 +25,21 @@
import io.opentracing.Tracer;
import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
@ApplicationScoped
public class TracerProducer {
- private Tracer tracer;
+ @Inject
+ ServletContext servletContext;
@Produces
public Tracer getTracer() {
- return this.tracer;
- }
-
- public void onTracerInitialized(@Observes Tracer tracer) {
- this.tracer = tracer;
+ Object tracerObject = servletContext.getAttribute(TracerInitializer.SMALLRYE_OPENTRACING_TRACER);
+ if (tracerObject instanceof Tracer) {
+ return (Tracer) tracerObject;
+ }
+ return null;
}
}
diff --git a/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracingLogger.java b/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracingLogger.java
index 192d334b9bde..3eeee7ffb965 100644
--- a/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracingLogger.java
+++ b/microprofile/opentracing-smallrye/src/main/java/org/wildfly/microprofile/opentracing/smallrye/TracingLogger.java
@@ -51,15 +51,11 @@ public interface TracingLogger extends BasicLogger {
@Message(id = 4, value = "Registering %s as the OpenTracing Tracer")
void registeringTracer(String message);
- @LogMessage(level = DEBUG)
- @Message(id = 5, value = "CDI events are not supported for this deployment. Possible configuration issues? Skipping MicroProfile OpenTracing integration.")
- void noCdiEventSupport();
+ @LogMessage(level = WARN)
+ @Message(id = 5, value = "No tracer available to JAX-RS. Skipping MicroProfile OpenTracing configuration for JAX-RS")
+ void noTracerAvailable();
@LogMessage(level = DEBUG)
@Message(id = 6, value = "Extra Tracer bean found: %s. Vetoing it, please use TracerResolver to specify a custom tracer to use.")
void extraTracerBean(String clazz);
-
- @LogMessage(level = WARN)
- @Message(id = 7, value = "Multiple tracer resolvers found. Cannot properly determine which one to use.")
- void multipleTracerResolvers();
}
diff --git a/microprofile/opentracing-smallrye/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/microprofile/opentracing-smallrye/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
new file mode 100644
index 000000000000..89a57b36b9c2
--- /dev/null
+++ b/microprofile/opentracing-smallrye/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -0,0 +1 @@
+org.wildfly.microprofile.opentracing.smallrye.TracingCDIExtension
\ No newline at end of file
diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/microprofile/opentracing/EarOpenTracingTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/microprofile/opentracing/EarOpenTracingTestCase.java
index e81b54048081..2910bbf9119f 100644
--- a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/microprofile/opentracing/EarOpenTracingTestCase.java
+++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/microprofile/opentracing/EarOpenTracingTestCase.java
@@ -21,10 +21,6 @@
*/
package org.jboss.as.test.integration.microprofile.opentracing;
-import static org.wildfly.test.integration.microprofile.config.smallrye.HttpUtils.getContent;
-
-import java.net.URL;
-
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -43,10 +39,13 @@
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.net.URL;
+
+import static org.wildfly.test.integration.microprofile.config.smallrye.HttpUtils.getContent;
+
/**
* Test verifying the assumption that different services inside single EAR have different tracers.
*
@@ -75,13 +74,11 @@ public static Archive> deploy() {
return ear;
}
- @Ignore("Unignore when https://issues.jboss.org/browse/WFWIP-104") // TODO
@Test
public void testEarServicesUseDifferentTracers() throws Exception {
testHttpInvokation();
}
- @Ignore("Unignore when https://issues.jboss.org/browse/WFWIP-104") // TODO
@Test
public void testEarServicesUseDifferentTracersAfterReload() throws Exception {
//TODO the tracer instance is same after reload as before it - check whether this is correct or no
diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/microprofile/opentracing/ResourceTracedTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/microprofile/opentracing/ResourceTracedTestCase.java
index 990077627721..e828cede242e 100644
--- a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/microprofile/opentracing/ResourceTracedTestCase.java
+++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/microprofile/opentracing/ResourceTracedTestCase.java
@@ -17,8 +17,10 @@
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.wildfly.microprofile.opentracing.smallrye.TracerInitializer;
import javax.inject.Inject;
+import javax.servlet.ServletContext;
import java.net.URL;
import java.util.concurrent.TimeUnit;
@@ -30,6 +32,9 @@ public class ResourceTracedTestCase {
@ArquillianResource
private URL url;
+ @Inject
+ ServletContext servletContext;
+
@Deployment
public static Archive> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class);
@@ -57,6 +62,10 @@ public void tracedEndpointYieldsSpan() throws Exception {
performCall("opentracing/traced");
Assert.assertEquals(1, mockTracer.finishedSpans().size());
+ Assert.assertEquals(
+ (servletContext.getContextPath() + ".war").substring(1),
+ servletContext.getInitParameter(TracerInitializer.SMALLRYE_OPENTRACING_SERVICE_NAME)
+ );
}
private void performCall(String path) throws Exception {