├── contrib
├── src
│ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── beans.xml
│ │ └── java
│ │ └── io
│ │ └── smallrye
│ │ └── opentracing
│ │ └── contrib
│ │ ├── resolver
│ │ ├── TracerFactory.java
│ │ ├── TracerConverter.java
│ │ ├── PriorityComparator.java
│ │ └── TracerResolver.java
│ │ ├── jaxrs2
│ │ ├── internal
│ │ │ ├── CastUtils.java
│ │ │ ├── SpanWrapper.java
│ │ │ └── URIUtils.java
│ │ ├── client
│ │ │ ├── ClientHeadersInjectTextMap.java
│ │ │ ├── TracingProperties.java
│ │ │ ├── ClientTracingInterceptor.java
│ │ │ ├── ClientSpanDecorator.java
│ │ │ ├── ClientTracingFilter.java
│ │ │ └── ClientTracingFeature.java
│ │ ├── server
│ │ │ ├── ServerHeadersExtractTextMap.java
│ │ │ ├── ServerTracingInterceptor.java
│ │ │ ├── ServerSpanDecorator.java
│ │ │ ├── SpanFinishingFilter.java
│ │ │ ├── OperationNameProvider.java
│ │ │ ├── ServerTracingFilter.java
│ │ │ └── ServerTracingDynamicFeature.java
│ │ └── serialization
│ │ │ ├── InterceptorSpanDecorator.java
│ │ │ └── TracingInterceptor.java
│ │ ├── web
│ │ └── servlet
│ │ │ └── filter
│ │ │ ├── HttpServletRequestExtractAdapter.java
│ │ │ ├── decorator
│ │ │ └── ServletFilterHeaderSpanDecorator.java
│ │ │ ├── ServletFilterSpanDecorator.java
│ │ │ └── TracingFilter.java
│ │ └── interceptor
│ │ └── OpenTracingInterceptor.java
└── pom.xml
├── CODEOWNERS
├── .github
├── project.yml
├── dependabot.yml
└── workflows
│ └── build.yml
├── tck
├── src
│ └── test
│ │ ├── resources
│ │ ├── META-INF
│ │ │ └── services
│ │ │ │ └── org.jboss.arquillian.core.spi.LoadableExtension
│ │ └── arquillian.xml
│ │ ├── tck-suite.xml
│ │ └── java
│ │ └── io
│ │ └── smallrye
│ │ └── opentracing
│ │ └── tck
│ │ ├── ArquillianExtension.java
│ │ ├── TracerProducer.java
│ │ ├── ExceptionMapper.java
│ │ ├── DeploymentProcessor.java
│ │ ├── ResteasyClientTracingRegistrarProvider.java
│ │ ├── ServletContextTracingInstaller.java
│ │ └── TestApplication.java
└── pom.xml
├── implementation
├── src
│ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ └── org.eclipse.microprofile.rest.client.spi.RestClientListener
│ │ └── java
│ │ └── io
│ │ └── smallrye
│ │ └── opentracing
│ │ ├── SmallRyeLogging.java
│ │ ├── OpenTracingAsyncInterceptorFactory.java
│ │ ├── SmallRyeClientTracingFeature.java
│ │ ├── SmallRyeRestClientListener.java
│ │ ├── OpenTracingAsyncInterceptor.java
│ │ └── SmallRyeTracingDynamicFeature.java
└── pom.xml
├── .gitignore
├── release
└── pom.xml
├── README.adoc
├── pom.xml
└── LICENSE.md
/contrib/src/main/resources/META-INF/beans.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/CODEOWNERS:
--------------------------------------------------------------------------------
1 | .github @smallrye/opentracing-opentelemetry
2 |
--------------------------------------------------------------------------------
/.github/project.yml:
--------------------------------------------------------------------------------
1 | name: SmallRye OpenTracing
2 | release:
3 | current-version: 3.0.3
4 | next-version: 3.0.4-SNAPSHOT
5 |
--------------------------------------------------------------------------------
/tck/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension:
--------------------------------------------------------------------------------
1 | io.smallrye.opentracing.tck.ArquillianExtension
2 |
--------------------------------------------------------------------------------
/implementation/src/main/resources/META-INF/services/org.eclipse.microprofile.rest.client.spi.RestClientListener:
--------------------------------------------------------------------------------
1 | io.smallrye.opentracing.SmallRyeRestClientListener
2 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: maven
4 | directory: "/"
5 | schedule:
6 | interval: daily
7 | open-pull-requests-limit: 10
8 |
--------------------------------------------------------------------------------
/tck/src/test/tck-suite.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/tck/src/test/java/io/smallrye/opentracing/tck/ArquillianExtension.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing.tck;
2 |
3 | import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;
4 | import org.jboss.arquillian.core.spi.LoadableExtension;
5 |
6 | /**
7 | * @author Pavol Loffay
8 | */
9 | public class ArquillianExtension implements LoadableExtension {
10 |
11 | @Override
12 | public void register(ExtensionBuilder extensionBuilder) {
13 | extensionBuilder.service(ApplicationArchiveProcessor.class, DeploymentProcessor.class);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | !.mvn/wrapper/maven-wrapper.jar
16 | *.war
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 | target
22 |
23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24 | hs_err_pid*
25 |
26 | # Eclipse
27 | .project
28 | .classpath
29 | .settings
30 |
31 | .gitkeep
32 | .editorconfig
33 |
34 | # Intellij Idea
35 | *.iml
36 | .idea/
37 |
38 | # formatter cache directories
39 | .cache
40 |
--------------------------------------------------------------------------------
/tck/src/test/java/io/smallrye/opentracing/tck/TracerProducer.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing.tck;
2 |
3 | import jakarta.enterprise.context.ApplicationScoped;
4 | import jakarta.enterprise.inject.Default;
5 | import jakarta.enterprise.inject.Produces;
6 | import jakarta.inject.Singleton;
7 |
8 | import io.opentracing.Tracer;
9 | import io.opentracing.mock.MockTracer;
10 |
11 | /**
12 | * @author Pavol Loffay
13 | */
14 | @ApplicationScoped
15 | public class TracerProducer {
16 |
17 | @Default
18 | @Produces
19 | @Singleton
20 | public Tracer tracer() {
21 | return new MockTracer();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tck/src/test/resources/arquillian.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/tck/src/test/java/io/smallrye/opentracing/tck/ExceptionMapper.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing.tck;
2 |
3 | import jakarta.ws.rs.core.Response;
4 | import jakarta.ws.rs.core.Response.Status;
5 | import jakarta.ws.rs.ext.Provider;
6 |
7 | /**
8 | * Temporal fix to catch exceptions thrown in JAX-RS endpoints
9 | * See https://issues.jboss.org/browse/RESTEASY-1758
10 | *
11 | * @author Pavol Loffay
12 | */
13 | @Provider
14 | public class ExceptionMapper implements jakarta.ws.rs.ext.ExceptionMapper {
15 |
16 | @Override
17 | public Response toResponse(RuntimeException exception) {
18 | return Response.status(Status.INTERNAL_SERVER_ERROR).entity(exception.getMessage()).build();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/implementation/src/main/java/io/smallrye/opentracing/SmallRyeLogging.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing;
2 |
3 | import org.jboss.logging.Logger;
4 | import org.jboss.logging.annotations.LogMessage;
5 | import org.jboss.logging.annotations.Message;
6 | import org.jboss.logging.annotations.MessageLogger;
7 |
8 | @MessageLogger(projectCode = "SROPT", length = 5)
9 | public interface SmallRyeLogging {
10 |
11 | SmallRyeLogging log = Logger.getMessageLogger(SmallRyeLogging.class, SmallRyeLogging.class.getPackage().getName());
12 |
13 | @LogMessage(level = Logger.Level.WARN)
14 | @Message(id = 1000, value = "Provided operation name does not match http-path or class-method. Using default class-method.")
15 | void operationNameNotMatch();
16 | }
17 |
--------------------------------------------------------------------------------
/release/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | io.smallrye
7 | smallrye-opentracing-parent
8 | 3.1.4-SNAPSHOT
9 |
10 |
11 | smallrye-opentracing-release
12 |
13 | Empty Release Project to Avoid Maven Bug
14 | Empty Release Project to Avoid Maven Bug
15 |
16 | pom
17 |
18 |
--------------------------------------------------------------------------------
/implementation/src/main/java/io/smallrye/opentracing/OpenTracingAsyncInterceptorFactory.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing;
2 |
3 | import org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptor;
4 | import org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptorFactory;
5 |
6 | import io.opentracing.Tracer;
7 |
8 | /**
9 | * @author Pavol Loffay
10 | */
11 | public class OpenTracingAsyncInterceptorFactory implements AsyncInvocationInterceptorFactory {
12 |
13 | private Tracer tracer;
14 |
15 | public OpenTracingAsyncInterceptorFactory(Tracer tracer) {
16 | this.tracer = tracer;
17 | }
18 |
19 | @Override
20 | public AsyncInvocationInterceptor newInterceptor() {
21 | return new OpenTracingAsyncInterceptor(tracer);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/implementation/src/main/java/io/smallrye/opentracing/SmallRyeClientTracingFeature.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing;
2 |
3 | import jakarta.ws.rs.core.Feature;
4 | import jakarta.ws.rs.core.FeatureContext;
5 |
6 | import io.opentracing.Tracer;
7 | import io.smallrye.opentracing.contrib.jaxrs2.client.ClientTracingFeature;
8 |
9 | /**
10 | * @author Pavol Loffay
11 | */
12 | public class SmallRyeClientTracingFeature implements Feature {
13 |
14 | private final ClientTracingFeature delegate;
15 |
16 | public SmallRyeClientTracingFeature(Tracer tracer) {
17 | this.delegate = new ClientTracingFeature.Builder(tracer)
18 | .withTraceSerialization(false)
19 | .build();
20 | }
21 |
22 | @Override
23 | public boolean configure(FeatureContext context) {
24 | return this.delegate.configure(context);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tck/src/test/java/io/smallrye/opentracing/tck/DeploymentProcessor.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing.tck;
2 |
3 | import org.eclipse.microprofile.opentracing.ClientTracingRegistrarProvider;
4 | import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;
5 | import org.jboss.arquillian.test.spi.TestClass;
6 | import org.jboss.shrinkwrap.api.Archive;
7 | import org.jboss.shrinkwrap.api.spec.WebArchive;
8 |
9 | /**
10 | * @author Pavol Loffay
11 | */
12 | public class DeploymentProcessor implements ApplicationArchiveProcessor {
13 | @Override
14 | public void process(Archive> archive, TestClass testClass) {
15 | if (archive instanceof WebArchive) {
16 | WebArchive war = (WebArchive) archive;
17 | war.addClass(ServletContextTracingInstaller.class);
18 | war.addClass(TracerProducer.class);
19 | war.addAsServiceProvider(ClientTracingRegistrarProvider.class, ResteasyClientTracingRegistrarProvider.class);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/implementation/src/main/java/io/smallrye/opentracing/SmallRyeRestClientListener.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing;
2 |
3 | import jakarta.enterprise.inject.spi.CDI;
4 |
5 | import org.eclipse.microprofile.opentracing.Traced;
6 | import org.eclipse.microprofile.rest.client.RestClientBuilder;
7 | import org.eclipse.microprofile.rest.client.spi.RestClientListener;
8 |
9 | import io.opentracing.Tracer;
10 |
11 | /**
12 | * @author Pavol Loffay
13 | */
14 | public class SmallRyeRestClientListener implements RestClientListener {
15 |
16 | @Override
17 | public void onNewClient(Class> clientInterface, RestClientBuilder restClientBuilder) {
18 | Traced traced = clientInterface.getAnnotation(Traced.class);
19 | if (traced != null && !traced.value()) {
20 | // tracing is disabled
21 | return;
22 | }
23 |
24 | Tracer tracer = CDI.current().select(Tracer.class).get();
25 | restClientBuilder.register(new SmallRyeClientTracingFeature(tracer));
26 | restClientBuilder.register(new OpenTracingAsyncInterceptorFactory(tracer));
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tck/src/test/java/io/smallrye/opentracing/tck/ResteasyClientTracingRegistrarProvider.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing.tck;
2 |
3 | import java.util.concurrent.ExecutorService;
4 | import java.util.concurrent.Executors;
5 |
6 | import jakarta.enterprise.inject.spi.CDI;
7 | import jakarta.ws.rs.client.ClientBuilder;
8 |
9 | import org.eclipse.microprofile.opentracing.ClientTracingRegistrarProvider;
10 |
11 | import io.opentracing.Tracer;
12 | import io.opentracing.contrib.concurrent.TracedExecutorService;
13 | import io.smallrye.opentracing.SmallRyeClientTracingFeature;
14 |
15 | /**
16 | * @author Pavol Loffay
17 | */
18 | public class ResteasyClientTracingRegistrarProvider implements ClientTracingRegistrarProvider {
19 |
20 | public ClientBuilder configure(ClientBuilder clientBuilder) {
21 | return configure(clientBuilder, Executors.newFixedThreadPool(10));
22 | }
23 |
24 | public ClientBuilder configure(ClientBuilder clientBuilder, ExecutorService executorService) {
25 | Tracer tracer = CDI.current().select(Tracer.class).get();
26 | return clientBuilder.executorService(new TracedExecutorService(executorService, tracer))
27 | .register(new SmallRyeClientTracingFeature(tracer));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/implementation/src/main/java/io/smallrye/opentracing/OpenTracingAsyncInterceptor.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing;
2 |
3 | import java.util.concurrent.CountDownLatch;
4 |
5 | import org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptor;
6 |
7 | import io.opentracing.Scope;
8 | import io.opentracing.Span;
9 | import io.opentracing.Tracer;
10 |
11 | /**
12 | * @author Pavol Loffay
13 | */
14 | public class OpenTracingAsyncInterceptor implements AsyncInvocationInterceptor {
15 |
16 | private final Tracer tracer;
17 | private final CountDownLatch countDownLatch = new CountDownLatch(1);
18 | private Span span;
19 | private Scope scope;
20 |
21 | public OpenTracingAsyncInterceptor(Tracer tracer) {
22 | this.tracer = tracer;
23 | }
24 |
25 | @Override
26 | public void prepareContext() {
27 | span = tracer.activeSpan();
28 | countDownLatch.countDown();
29 | }
30 |
31 | @Override
32 | public void applyContext() {
33 | try {
34 | countDownLatch.await();
35 | } catch (InterruptedException e) {
36 | }
37 | if (span != null) {
38 | scope = tracer.scopeManager().activate(span);
39 | }
40 | }
41 |
42 | @Override
43 | public void removeContext() {
44 | if (scope != null) {
45 | scope.close();
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/resolver/TracerFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-2018 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-tracerresolver
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package io.smallrye.opentracing.contrib.resolver;
19 |
20 | import java.util.ServiceLoader;
21 |
22 | import io.opentracing.Tracer;
23 |
24 | /**
25 | * Represents a class that knows how to select and build an appropriate tracer. The factory is usually used in
26 | * conjunction with the {@link TracerResolver}, but other resolver implementations can also load factories via
27 | * Java's {@link ServiceLoader}
28 | */
29 | public interface TracerFactory {
30 |
31 | /**
32 | * Returns the concrete tracer implementation.
33 | *
34 | * @return the tracer instance
35 | */
36 | Tracer getTracer();
37 | }
38 |
--------------------------------------------------------------------------------
/tck/src/test/java/io/smallrye/opentracing/tck/ServletContextTracingInstaller.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing.tck;
2 |
3 | import java.util.EnumSet;
4 |
5 | import jakarta.servlet.DispatcherType;
6 | import jakarta.servlet.FilterRegistration.Dynamic;
7 | import jakarta.servlet.ServletContext;
8 | import jakarta.servlet.ServletContextEvent;
9 | import jakarta.servlet.ServletContextListener;
10 | import jakarta.servlet.annotation.WebListener;
11 |
12 | import io.smallrye.opentracing.SmallRyeTracingDynamicFeature;
13 | import io.smallrye.opentracing.contrib.jaxrs2.server.SpanFinishingFilter;
14 |
15 | /**
16 | * @author Pavol Loffay
17 | */
18 | @WebListener
19 | public class ServletContextTracingInstaller implements ServletContextListener {
20 |
21 | @Override
22 | public void contextInitialized(ServletContextEvent servletContextEvent) {
23 | ServletContext servletContext = servletContextEvent.getServletContext();
24 | servletContext.setInitParameter("resteasy.providers",
25 | SmallRyeTracingDynamicFeature.class.getName() + "," + ExceptionMapper.class.getName());
26 |
27 | // Span finishing filter
28 | Dynamic filterRegistration = servletContext.addFilter("tracingFilter", new SpanFinishingFilter());
29 | filterRegistration.setAsyncSupported(true);
30 | filterRegistration.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "*");
31 | }
32 |
33 | @Override
34 | public void contextDestroyed(ServletContextEvent servletContextEvent) {
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/jaxrs2/internal/CastUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2020 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-jaxrs
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 | * in compliance with the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software distributed under the License
12 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 | * or implied. See the License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package io.smallrye.opentracing.contrib.jaxrs2.internal;
17 |
18 | import java.util.logging.Logger;
19 |
20 | /**
21 | * @author Pavol Loffay
22 | */
23 | public class CastUtils {
24 | private static final Logger log = Logger.getLogger(CastUtils.class.getName());
25 |
26 | private CastUtils() {
27 | }
28 |
29 | /**
30 | * Casts given object to the given class.
31 | *
32 | * @param object
33 | * @param clazz
34 | * @param
35 | * @return casted object, or null if there is any error
36 | */
37 | public static T cast(Object object, Class clazz) {
38 | if (object == null || clazz == null) {
39 | return null;
40 | }
41 |
42 | try {
43 | return clazz.cast(object);
44 | } catch (ClassCastException ex) {
45 | log.severe("Cannot cast to " + clazz.getName());
46 | return null;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/jaxrs2/client/ClientHeadersInjectTextMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2020 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-jaxrs
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 | * in compliance with the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software distributed under the License
12 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 | * or implied. See the License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package io.smallrye.opentracing.contrib.jaxrs2.client;
17 |
18 | import java.util.Iterator;
19 | import java.util.Map;
20 |
21 | import jakarta.ws.rs.core.MultivaluedMap;
22 |
23 | import io.opentracing.propagation.TextMap;
24 |
25 | /**
26 | * Helper class used to add carrier data to HTTP headers.
27 | *
28 | * @author Pavol Loffay
29 | */
30 | public class ClientHeadersInjectTextMap implements TextMap {
31 |
32 | private final MultivaluedMap headers;
33 |
34 | public ClientHeadersInjectTextMap(MultivaluedMap headers) {
35 | this.headers = headers;
36 | }
37 |
38 | @Override
39 | public Iterator> iterator() {
40 | throw new UnsupportedOperationException(
41 | ClientHeadersInjectTextMap.class.getName() + " should only be used with Tracer.inject()");
42 | }
43 |
44 | @Override
45 | public void put(String key, String value) {
46 | headers.add(key, value);
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: SmallRye Build
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | paths-ignore:
8 | - '.gitignore'
9 | - 'CODEOWNERS'
10 | - 'LICENSE'
11 | - 'NOTICE'
12 | - 'README*'
13 | pull_request:
14 | paths-ignore:
15 | - '.gitignore'
16 | - 'CODEOWNERS'
17 | - 'LICENSE'
18 | - 'NOTICE'
19 | - 'README*'
20 |
21 | jobs:
22 | build:
23 | runs-on: ubuntu-latest
24 | strategy:
25 | matrix:
26 | java: [11, 17]
27 | name: build with jdk ${{matrix.java}}
28 |
29 | steps:
30 | - uses: actions/checkout@v4
31 | name: checkout
32 |
33 | - uses: actions/setup-java@v4
34 | name: set up jdk ${{matrix.java}}
35 | with:
36 | distribution: 'temurin'
37 | java-version: ${{matrix.java}}
38 | cache: 'maven'
39 | cache-dependency-path: '**/pom.xml'
40 |
41 | - name: build with maven
42 | run: mvn -B formatter:validate verify --file pom.xml
43 |
44 | - uses: actions/upload-artifact@v4
45 | name: tck-report
46 | with:
47 | name: tck-report-java-${{matrix.java}}
48 | path: tck/target/surefire-reports
49 |
50 | build-windows:
51 | runs-on: windows-latest
52 | strategy:
53 | matrix:
54 | java: [11, 17]
55 | name: build with jdk ${{matrix.java}} windows
56 |
57 | steps:
58 | - uses: actions/checkout@v4
59 | name: checkout
60 |
61 | - uses: actions/setup-java@v4
62 | name: set up jdk ${{matrix.java}}
63 | with:
64 | distribution: 'temurin'
65 | java-version: ${{matrix.java}}
66 | cache: 'maven'
67 | cache-dependency-path: '**/pom.xml'
68 |
69 | - name: build with maven
70 | run: mvn -B formatter:validate verify --file pom.xml
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/jaxrs2/client/TracingProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2020 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-jaxrs
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 | * in compliance with the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software distributed under the License
12 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 | * or implied. See the License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package io.smallrye.opentracing.contrib.jaxrs2.client;
17 |
18 | import io.opentracing.References;
19 |
20 | /**
21 | * @author Pavol Loffay
22 | */
23 | public class TracingProperties {
24 |
25 | private TracingProperties() {
26 | }
27 |
28 | /**
29 | * Denotes a parent span context {@link References#CHILD_OF}.
30 | * If it is not specified a new trace will be started.
31 | * Set on {@link jakarta.ws.rs.client.Invocation#property(String, Object)}.
32 | */
33 | public static final String CHILD_OF = ClientTracingFilter.class.getName() + "." + References.CHILD_OF;
34 |
35 | /**
36 | * Indicates whether request should be traced or not. If it is not
37 | * present and client is correctly configured request will be traced.
38 | * Value should be a boolean (trace disabled/enabled).
39 | * Set on {@link jakarta.ws.rs.client.Invocation#property(String, Object)}.
40 | */
41 | public static final String TRACING_DISABLED = ClientTracingFilter.class.getName() + ".tracingDisabled";
42 | }
43 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/jaxrs2/internal/SpanWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2020 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-jaxrs
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 | * in compliance with the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software distributed under the License
12 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 | * or implied. See the License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package io.smallrye.opentracing.contrib.jaxrs2.internal;
17 |
18 | import java.util.concurrent.atomic.AtomicBoolean;
19 |
20 | import io.opentracing.Scope;
21 | import io.opentracing.Span;
22 |
23 | /**
24 | * Wrapper class used for exchanging span between filters.
25 | *
26 | * @author Pavol Loffay
27 | */
28 | public class SpanWrapper {
29 |
30 | public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper";
31 |
32 | private Scope scope;
33 | private Span span;
34 | private AtomicBoolean finished = new AtomicBoolean();
35 |
36 | public SpanWrapper(Span span, Scope scope) {
37 | this.span = span;
38 | this.scope = scope;
39 |
40 | }
41 |
42 | public Span get() {
43 | return span;
44 | }
45 |
46 | public Scope getScope() {
47 | return scope;
48 | }
49 |
50 | public synchronized void finish() {
51 | if (!finished.get()) {
52 | finished.set(true);
53 | span.finish();
54 | }
55 | }
56 |
57 | public boolean isFinished() {
58 | return finished.get();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/jaxrs2/client/ClientTracingInterceptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2020 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-jaxrs
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 | * in compliance with the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software distributed under the License
12 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 | * or implied. See the License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package io.smallrye.opentracing.contrib.jaxrs2.client;
17 |
18 | import static io.smallrye.opentracing.contrib.jaxrs2.internal.SpanWrapper.PROPERTY_NAME;
19 |
20 | import java.util.List;
21 |
22 | import jakarta.annotation.Priority;
23 | import jakarta.ws.rs.Priorities;
24 | import jakarta.ws.rs.ext.InterceptorContext;
25 |
26 | import io.opentracing.Tracer;
27 | import io.smallrye.opentracing.contrib.jaxrs2.internal.CastUtils;
28 | import io.smallrye.opentracing.contrib.jaxrs2.internal.SpanWrapper;
29 | import io.smallrye.opentracing.contrib.jaxrs2.serialization.InterceptorSpanDecorator;
30 | import io.smallrye.opentracing.contrib.jaxrs2.serialization.TracingInterceptor;
31 |
32 | @Priority(Priorities.ENTITY_CODER)
33 | public class ClientTracingInterceptor extends TracingInterceptor {
34 |
35 | public ClientTracingInterceptor(Tracer tracer, List spanDecorators) {
36 | super(tracer, spanDecorators);
37 | }
38 |
39 | @Override
40 | protected SpanWrapper findSpan(InterceptorContext context) {
41 | return CastUtils.cast(context.getProperty(PROPERTY_NAME), SpanWrapper.class);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/jaxrs2/server/ServerHeadersExtractTextMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2020 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-jaxrs
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 | * in compliance with the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software distributed under the License
12 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 | * or implied. See the License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package io.smallrye.opentracing.contrib.jaxrs2.server;
17 |
18 | import java.util.Iterator;
19 | import java.util.Map;
20 |
21 | import jakarta.ws.rs.core.MultivaluedMap;
22 |
23 | import io.opentracing.propagation.TextMap;
24 | import io.smallrye.opentracing.contrib.web.servlet.filter.HttpServletRequestExtractAdapter;
25 |
26 | /**
27 | * Helper class used to iterate over HTTP headers.
28 | *
29 | * @author Pavol Loffay
30 | */
31 | public class ServerHeadersExtractTextMap implements TextMap {
32 |
33 | private final MultivaluedMap headers;
34 |
35 | public ServerHeadersExtractTextMap(MultivaluedMap headers) {
36 | this.headers = headers;
37 | }
38 |
39 | @Override
40 | public Iterator> iterator() {
41 | return new HttpServletRequestExtractAdapter.MultivaluedMapFlatIterator<>(headers.entrySet());
42 | }
43 |
44 | @Override
45 | public void put(String key, String value) {
46 | throw new UnsupportedOperationException(
47 | ServerHeadersExtractTextMap.class.getName() + " should only be used with Tracer.extract()");
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/jaxrs2/internal/URIUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2020 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-jaxrs
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 | * in compliance with the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software distributed under the License
12 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 | * or implied. See the License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package io.smallrye.opentracing.contrib.jaxrs2.internal;
17 |
18 | import java.net.MalformedURLException;
19 | import java.net.URI;
20 | import java.net.URL;
21 |
22 | /**
23 | * @author Pavol Loffay
24 | */
25 | public class URIUtils {
26 | private URIUtils() {
27 | }
28 |
29 | /**
30 | * Returns path of given URI. If the first character of path is '/' then it is removed.
31 | *
32 | * @param uri
33 | * @return path or null
34 | */
35 | public static String path(URI uri) {
36 | String path = uri.getPath();
37 | if (path != null && path.startsWith("/")) {
38 | path = path.substring(1);
39 | }
40 |
41 | return path;
42 | }
43 |
44 | /**
45 | * Returns string representation of supplied URL.
46 | *
47 | * @param uri
48 | * @return string URL or null
49 | */
50 | public static String url(URI uri) {
51 | String urlStr = null;
52 | try {
53 | URL url = uri.toURL();
54 | urlStr = url.toString();
55 | } catch (MalformedURLException e) {
56 | // ignoring returning null
57 | }
58 |
59 | return urlStr;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/jaxrs2/serialization/InterceptorSpanDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2020 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-jaxrs
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 | * in compliance with the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software distributed under the License
12 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 | * or implied. See the License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package io.smallrye.opentracing.contrib.jaxrs2.serialization;
17 |
18 | import jakarta.ws.rs.ext.InterceptorContext;
19 |
20 | import io.opentracing.Span;
21 |
22 | public interface InterceptorSpanDecorator {
23 |
24 | /**
25 | * Decorate spans by outgoing object.
26 | *
27 | * @param context
28 | * @param span
29 | */
30 | void decorateRead(InterceptorContext context, Span span);
31 |
32 | /**
33 | * Decorate spans by outgoing object.
34 | *
35 | * @param context
36 | * @param span
37 | */
38 | void decorateWrite(InterceptorContext context, Span span);
39 |
40 | /**
41 | * Adds tags: \"media.type\", \"entity.type\"
42 | */
43 | InterceptorSpanDecorator STANDARD_TAGS = new InterceptorSpanDecorator() {
44 | @Override
45 | public void decorateRead(InterceptorContext context, Span span) {
46 | span.setTag("media.type", context.getMediaType().toString());
47 | span.setTag("entity.type", context.getType().getName());
48 | }
49 |
50 | @Override
51 | public void decorateWrite(InterceptorContext context, Span span) {
52 | decorateRead(context, span);
53 | }
54 | };
55 | }
56 |
--------------------------------------------------------------------------------
/contrib/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | io.smallrye
6 | smallrye-opentracing-parent
7 | 3.1.4-SNAPSHOT
8 |
9 |
10 | smallrye-opentracing-contrib
11 | SmallRye: MicroProfile OpenTracing Contrib
12 | Fork of io.opentracing.contrib projects
13 |
14 |
15 |
16 |
17 | org.apache.maven.plugins
18 | maven-javadoc-plugin
19 |
20 | false
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | jakarta.enterprise
29 | jakarta.enterprise.cdi-api
30 | provided
31 |
32 |
33 | jakarta.ws.rs
34 | jakarta.ws.rs-api
35 | provided
36 |
37 |
38 | jakarta.servlet
39 | jakarta.servlet-api
40 |
41 |
42 | io.opentracing
43 | opentracing-api
44 |
45 |
46 | io.opentracing
47 | opentracing-noop
48 |
49 |
50 | io.opentracing
51 | opentracing-util
52 |
53 |
54 | io.opentracing.contrib
55 | opentracing-concurrent
56 |
57 |
58 | org.eclipse.microprofile.opentracing
59 | microprofile-opentracing-api
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/resolver/TracerConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-tracerresolver
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package io.smallrye.opentracing.contrib.resolver;
19 |
20 | import io.opentracing.Tracer;
21 |
22 | /**
23 | * Function converting an existing {@link Tracer}.
24 | *
25 | * This can be useful for wrapping tracers:
26 | *
27 | *
28 | *
29 | * public final class FooWrapperConverter implements TracerConverter {
30 | * public Tracer convert(Tracer existingTracer) {
31 | * return new FooTracerWrapper(existingTracer);
32 | * }
33 | * }
34 | *
35 | *
36 | *
37 | * If there are multiple {@linkplain TracerConverter} implementations resolved,
38 | * they will be applied in the order of their {@literal @}Priority annotation:
39 | *
40 | *
First, non-negative priority is applied in natural order (e.g. {@code 0}, {@code 1}, {@code 2}, ...).
41 | *
Next, objects without {@literal @}Priority annotation are applied
42 | * by assigning a default priority of {@link Integer#MAX_VALUE}.
43 | *
Finally, negative priority is applied in reverse-natural order (e.g. {@code -1}, {@code -2}, {@code -3}, ...).
44 | *
45 | *
46 | * The order of objects with equal (implicit) priority is undefined.
47 | *
48 | * @author Sjoerd Talsma
49 | */
50 | public interface TracerConverter {
51 |
52 | /**
53 | * Function that converts a {@link Tracer}.
54 | *
55 | * It may either manipulate the tracer or return an entirely new {@linkplain Tracer} instance.
56 | *
57 | * @param existingTracer The existing tracer to be converted.
58 | * @return The converted tracer.
59 | */
60 | Tracer convert(Tracer existingTracer);
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/implementation/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | io.smallrye
6 | smallrye-opentracing-parent
7 | 3.1.4-SNAPSHOT
8 |
9 |
10 | smallrye-opentracing
11 | SmallRye: MicroProfile OpenTracing Implementation
12 |
13 |
14 |
15 | org.eclipse.microprofile.opentracing
16 | microprofile-opentracing-api
17 |
18 |
19 | org.eclipse.microprofile.config
20 | microprofile-config-api
21 |
22 |
23 | org.eclipse.microprofile.rest.client
24 | microprofile-rest-client-api
25 |
26 |
27 |
28 | io.smallrye
29 | smallrye-opentracing-contrib
30 |
31 |
32 |
33 | jakarta.enterprise
34 | jakarta.enterprise.cdi-api
35 | provided
36 |
37 |
38 | jakarta.ws.rs
39 | jakarta.ws.rs-api
40 | provided
41 |
42 |
43 |
44 | org.jboss.logging
45 | jboss-logging
46 |
47 |
48 | org.jboss.logging
49 | jboss-logging-annotations
50 |
51 |
52 | org.jboss.logging
53 | jboss-logging-processor
54 |
55 |
56 |
57 |
58 |
59 | coverage
60 |
61 | @{jacocoArgLine}
62 |
63 |
64 |
65 |
66 | org.jacoco
67 | jacoco-maven-plugin
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/implementation/src/main/java/io/smallrye/opentracing/SmallRyeTracingDynamicFeature.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing;
2 |
3 | import java.util.Optional;
4 |
5 | import jakarta.enterprise.inject.Instance;
6 | import jakarta.enterprise.inject.spi.CDI;
7 | import jakarta.ws.rs.container.DynamicFeature;
8 | import jakarta.ws.rs.container.ResourceInfo;
9 | import jakarta.ws.rs.core.FeatureContext;
10 | import jakarta.ws.rs.ext.Provider;
11 |
12 | import org.eclipse.microprofile.config.Config;
13 | import org.eclipse.microprofile.config.ConfigProvider;
14 |
15 | import io.opentracing.Tracer;
16 | import io.smallrye.opentracing.contrib.jaxrs2.server.OperationNameProvider.ClassNameOperationName;
17 | import io.smallrye.opentracing.contrib.jaxrs2.server.OperationNameProvider.WildcardOperationName;
18 | import io.smallrye.opentracing.contrib.jaxrs2.server.ServerTracingDynamicFeature;
19 | import io.smallrye.opentracing.contrib.jaxrs2.server.ServerTracingDynamicFeature.Builder;
20 |
21 | /**
22 | * @author Pavol Loffay
23 | */
24 | @Provider
25 | public class SmallRyeTracingDynamicFeature implements DynamicFeature {
26 |
27 | private final ServerTracingDynamicFeature delegate;
28 |
29 | public SmallRyeTracingDynamicFeature() {
30 | Instance tracerInstance = CDI.current().select(Tracer.class);
31 | Config config = ConfigProvider.getConfig();
32 | Optional skipPattern = config.getOptionalValue("mp.opentracing.server.skip-pattern", String.class);
33 | Optional operationNameProvider = config.getOptionalValue("mp.opentracing.server.operation-name-provider",
34 | String.class);
35 |
36 | Builder builder = new Builder(tracerInstance.get())
37 | .withOperationNameProvider(ClassNameOperationName.newBuilder())
38 | .withTraceSerialization(false);
39 | if (skipPattern.isPresent()) {
40 | builder.withSkipPattern(skipPattern.get());
41 | }
42 | if (operationNameProvider.isPresent()) {
43 | if ("http-path".equalsIgnoreCase(operationNameProvider.get())) {
44 | builder.withOperationNameProvider(WildcardOperationName.newBuilder());
45 | } else if (!"class-method".equalsIgnoreCase(operationNameProvider.get())) {
46 | SmallRyeLogging.log.operationNameNotMatch();
47 | }
48 | }
49 | this.delegate = builder.build();
50 | }
51 |
52 | @Override
53 | public void configure(ResourceInfo resourceInfo, FeatureContext context) {
54 | this.delegate.configure(resourceInfo, context);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/jaxrs2/server/ServerTracingInterceptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2020 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-jaxrs
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 | * in compliance with the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software distributed under the License
12 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 | * or implied. See the License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package io.smallrye.opentracing.contrib.jaxrs2.server;
17 |
18 | import static io.smallrye.opentracing.contrib.jaxrs2.internal.SpanWrapper.PROPERTY_NAME;
19 |
20 | import java.util.List;
21 |
22 | import jakarta.annotation.Priority;
23 | import jakarta.servlet.http.HttpServletRequest;
24 | import jakarta.ws.rs.Priorities;
25 | import jakarta.ws.rs.core.Context;
26 | import jakarta.ws.rs.ext.InterceptorContext;
27 |
28 | import io.opentracing.Tracer;
29 | import io.smallrye.opentracing.contrib.jaxrs2.internal.CastUtils;
30 | import io.smallrye.opentracing.contrib.jaxrs2.internal.SpanWrapper;
31 | import io.smallrye.opentracing.contrib.jaxrs2.serialization.InterceptorSpanDecorator;
32 | import io.smallrye.opentracing.contrib.jaxrs2.serialization.TracingInterceptor;
33 |
34 | @Priority(Priorities.ENTITY_CODER)
35 | public class ServerTracingInterceptor extends TracingInterceptor {
36 | /**
37 | * Apache CFX does not seem to publish the PROPERTY_NAME into the Interceptor context.
38 | * Use the current HttpServletRequest to lookup the current span wrapper.
39 | */
40 | @Context
41 | private HttpServletRequest servletReq;
42 |
43 | public ServerTracingInterceptor(Tracer tracer, List spanDecorators) {
44 | super(tracer, spanDecorators);
45 | }
46 |
47 | @Override
48 | protected SpanWrapper findSpan(InterceptorContext context) {
49 | SpanWrapper spanWrapper = CastUtils.cast(context.getProperty(PROPERTY_NAME), SpanWrapper.class);
50 | if (spanWrapper == null && servletReq != null) {
51 | spanWrapper = CastUtils
52 | .cast(servletReq.getAttribute(PROPERTY_NAME), SpanWrapper.class);
53 | }
54 | return spanWrapper;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/jaxrs2/server/ServerSpanDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2020 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-jaxrs
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 | * in compliance with the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software distributed under the License
12 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 | * or implied. See the License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package io.smallrye.opentracing.contrib.jaxrs2.server;
17 |
18 | import jakarta.ws.rs.container.ContainerRequestContext;
19 | import jakarta.ws.rs.container.ContainerResponseContext;
20 |
21 | import io.opentracing.Span;
22 | import io.opentracing.tag.Tags;
23 | import io.smallrye.opentracing.contrib.jaxrs2.internal.URIUtils;
24 |
25 | /**
26 | * @author Pavol Loffay
27 | */
28 | public interface ServerSpanDecorator {
29 |
30 | /**
31 | * Decorate span by incoming object.
32 | *
33 | * @param requestContext
34 | * @param span
35 | */
36 | void decorateRequest(ContainerRequestContext requestContext, Span span);
37 |
38 | /**
39 | * Decorate spans by outgoing object.
40 | *
41 | * @param responseContext
42 | * @param span
43 | */
44 | void decorateResponse(ContainerResponseContext responseContext, Span span);
45 |
46 | /**
47 | * Adds standard tags: {@link Tags#SPAN_KIND},
48 | * {@link Tags#HTTP_METHOD}, {@link Tags#HTTP_URL} and
49 | * {@link Tags#HTTP_STATUS}
50 | */
51 | ServerSpanDecorator STANDARD_TAGS = new ServerSpanDecorator() {
52 | @Override
53 | public void decorateRequest(ContainerRequestContext requestContext, Span span) {
54 | Tags.COMPONENT.set(span, "jaxrs");
55 | Tags.HTTP_METHOD.set(span, requestContext.getMethod());
56 |
57 | String url = URIUtils.url(requestContext.getUriInfo().getRequestUri());
58 | if (url != null) {
59 | Tags.HTTP_URL.set(span, url);
60 | }
61 | }
62 |
63 | @Override
64 | public void decorateResponse(ContainerResponseContext responseContext, Span span) {
65 | Tags.HTTP_STATUS.set(span, responseContext.getStatus());
66 | }
67 | };
68 | }
69 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/jaxrs2/client/ClientSpanDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2020 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-jaxrs
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 | * in compliance with the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software distributed under the License
12 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 | * or implied. See the License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package io.smallrye.opentracing.contrib.jaxrs2.client;
17 |
18 | import jakarta.ws.rs.client.ClientRequestContext;
19 | import jakarta.ws.rs.client.ClientResponseContext;
20 |
21 | import io.opentracing.Span;
22 | import io.opentracing.tag.Tags;
23 | import io.smallrye.opentracing.contrib.jaxrs2.internal.URIUtils;
24 |
25 | /**
26 | * @author Pavol Loffay
27 | */
28 | public interface ClientSpanDecorator {
29 |
30 | /**
31 | * Decorate get by incoming object.
32 | *
33 | * @param requestContext
34 | * @param span
35 | */
36 | void decorateRequest(ClientRequestContext requestContext, Span span);
37 |
38 | /**
39 | * Decorate spans by outgoing object.
40 | *
41 | * @param responseContext
42 | * @param span
43 | */
44 | void decorateResponse(ClientResponseContext responseContext, Span span);
45 |
46 | /**
47 | * Adds standard tags: {@link Tags#SPAN_KIND},
48 | * {@link Tags#PEER_HOSTNAME}, {@link Tags#PEER_PORT},
49 | * {@link Tags#HTTP_METHOD}, {@link Tags#HTTP_URL} and
50 | * {@link Tags#HTTP_STATUS}
51 | */
52 | ClientSpanDecorator STANDARD_TAGS = new ClientSpanDecorator() {
53 | @Override
54 | public void decorateRequest(ClientRequestContext requestContext, Span span) {
55 | Tags.COMPONENT.set(span, "jaxrs");
56 | Tags.PEER_HOSTNAME.set(span, requestContext.getUri().getHost());
57 | Tags.PEER_PORT.set(span, requestContext.getUri().getPort());
58 |
59 | Tags.HTTP_METHOD.set(span, requestContext.getMethod());
60 |
61 | String url = URIUtils.url(requestContext.getUri());
62 | if (url != null) {
63 | Tags.HTTP_URL.set(span, url);
64 | }
65 | }
66 |
67 | @Override
68 | public void decorateResponse(ClientResponseContext responseContext, Span span) {
69 | Tags.HTTP_STATUS.set(span, responseContext.getStatus());
70 | }
71 | };
72 |
73 | /**
74 | * As operation name provides HTTP path. If there are path parameters used in URL then
75 | * spans for the same requests would have different operation names, therefore use carefully.
76 | */
77 | ClientSpanDecorator HTTP_PATH_OPERATION_NAME = new ClientSpanDecorator() {
78 | @Override
79 | public void decorateRequest(ClientRequestContext clientRequestContext, Span span) {
80 | span.setOperationName(URIUtils.path(clientRequestContext.getUri()));
81 | }
82 |
83 | @Override
84 | public void decorateResponse(ClientResponseContext response, Span span) {
85 | }
86 | };
87 | }
88 |
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | :ci: https://github.com/smallrye/smallrye-opentracing/actions/workflows/build.yml/
2 |
3 | image:https://github.com/smallrye/smallrye-opentracing/actions/workflows/build.yml/badge.svg?branch=main[link={ci}]
4 | image:https://img.shields.io/github/license/smallrye/smallrye-opentracing.svg["License", link="http://www.apache.org/licenses/LICENSE-2.0"]
5 | image:https://img.shields.io/maven-central/v/io.smallrye/smallrye-opentracing?color=green[]
6 |
7 | = SmallRye OpenTracing (Deprecated)
8 |
9 | OpenTracing is no longer under development and was replaced by OpenTelemetry Tracing. In the future,
10 | please refer to SmallRye OpenTelemetry: https://github.com/smallrye/smallrye-opentelemetry
11 |
12 | ___
13 |
14 | SmallRye OpenTracing is an implementation of https://github.com/eclipse/microprofile-opentracing meant
15 | to be reusable for different vendors.
16 |
17 | == How to use
18 |
19 | The following components have to be added to deployment to pass `microprofile-opentracing-tck`:
20 |
21 | === Server side JAX-RS
22 |
23 | Server side JAX-RS tracing integration is provided by JAX-RS `SmallRyeTracingDynamicFeature` and
24 | servlet filter `SpanFinishingFilter` which finishes the span started in JAX-RS filter.
25 |
26 | The installation is JAX-RS and server implementation specific.
27 | For example in RestEasy `DynamicFeature` it can be enabled by specifying
28 | `resteasy.providers` in servlet context init parameters. The following code snippet demonstrates
29 | possible installation.
30 |
31 | ```java
32 | public class ServletContextTracingInstaller implements ServletContextListener {
33 |
34 | @Override
35 | public void contextInitialized(ServletContextEvent servletContextEvent) {
36 | ServletContext servletContext = servletContextEvent.getServletContext();
37 | servletContext.setInitParameter("resteasy.providers", SmallRyeTracingDynamicFeature.class.getName());
38 |
39 | Dynamic filterRegistration = servletContext.addFilter("tracingFilter", new SpanFinishingFilter());
40 | filterRegistration.setAsyncSupported(true);
41 | filterRegistration.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "*");
42 | }
43 | }
44 | ```
45 |
46 | === Client side JAX-RS
47 |
48 | Vendor has to implement `ClientTracingRegistrarProvider` and specify it in
49 | `META-INF/services/org.eclipse.microprofile.opentracing.ClientTracingRegistrarProvider`.
50 |
51 | This project provides `SmallRyeClientTracingFeature` with tracing integration. The feature
52 | has to be registered to `ClientBuilder` in vendor specific implementation of `ClientTracingRegistrarProvider`.
53 | Client side tracing usually requires more components, for example OpenTracing-aware `AsyncExecutor`.
54 |
55 | === MicroProfile Rest Client
56 | The Rest Client instrumentation is provided in `SmallRyeRestClientListener` which has to be registered
57 | in `META-INF/services/org.eclipse.microprofile.rest.client.spi.RestClientListener`.
58 |
59 | === CDI
60 |
61 | The `@Traced` aspects of the specification is provided by the `OpenTracingInterceptor`, from the
62 | link:https://github.com/opentracing-contrib/java-interceptors[OpenTracing Contrib Java Interceptors] project.
63 |
64 | === Tracer producer
65 |
66 | Vendor has to provide CDI tracer producer. It is not provided by this library as the
67 | tracer resolution is not defined by MicroProfile specification.
68 |
69 | == Develop
70 |
71 | ```bash
72 | mvn clean install
73 | ```
74 |
75 | === Debug
76 |
77 | Debug of the deployment can be enabled in `arquillian.xml` configuration file.
78 |
79 | Run the following to debug tests on port `8788`.
80 | ```bash
81 | mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8788 -Xnoagent -Djava.compiler=NONE" test
82 | ```
83 |
--------------------------------------------------------------------------------
/tck/src/test/java/io/smallrye/opentracing/tck/TestApplication.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.opentracing.tck;
2 |
3 | import static jakarta.ws.rs.core.MediaType.TEXT_PLAIN;
4 |
5 | import java.io.IOException;
6 | import java.net.HttpURLConnection;
7 | import java.net.URL;
8 |
9 | import jakarta.enterprise.context.ApplicationScoped;
10 | import jakarta.enterprise.context.RequestScoped;
11 | import jakarta.enterprise.inject.spi.CDI;
12 | import jakarta.inject.Inject;
13 | import jakarta.servlet.annotation.WebServlet;
14 | import jakarta.servlet.http.HttpServlet;
15 | import jakarta.servlet.http.HttpServletRequest;
16 | import jakarta.servlet.http.HttpServletResponse;
17 | import jakarta.ws.rs.ApplicationPath;
18 | import jakarta.ws.rs.GET;
19 | import jakarta.ws.rs.Path;
20 | import jakarta.ws.rs.client.ClientBuilder;
21 | import jakarta.ws.rs.client.WebTarget;
22 | import jakarta.ws.rs.core.Response;
23 |
24 | import org.jboss.arquillian.container.test.api.Deployment;
25 | import org.jboss.arquillian.container.test.api.RunAsClient;
26 | import org.jboss.arquillian.test.api.ArquillianResource;
27 | import org.jboss.arquillian.testng.Arquillian;
28 | import org.jboss.shrinkwrap.api.ArchivePaths;
29 | import org.jboss.shrinkwrap.api.ShrinkWrap;
30 | import org.jboss.shrinkwrap.api.asset.EmptyAsset;
31 | import org.jboss.shrinkwrap.api.spec.WebArchive;
32 | import org.testng.Assert;
33 | import org.testng.annotations.Test;
34 |
35 | public class TestApplication extends Arquillian {
36 | /**
37 | * The base URL for the container under test
38 | */
39 | @ArquillianResource
40 | private URL baseURL;
41 |
42 | @Deployment
43 | public static WebArchive createDeployment() {
44 | return ShrinkWrap
45 | .create(WebArchive.class)
46 | .addClass(TestServlet.class)
47 | .addClass(RestApplication.class)
48 | .addClass(TestEndpoint.class)
49 | .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
50 | }
51 |
52 | @Test
53 | @RunAsClient
54 | public void servlet() {
55 | String uri = baseURL.toExternalForm() + "servlet";
56 | System.out.println("uri = " + uri);
57 | WebTarget echoEndpointTarget = ClientBuilder.newClient().target(uri);
58 | Response response = echoEndpointTarget.request(TEXT_PLAIN).get();
59 | Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
60 | }
61 |
62 | @Test
63 | @RunAsClient
64 | public void rest() {
65 | String uri = baseURL.toExternalForm() + "rest";
66 | System.out.println("uri = " + uri);
67 | WebTarget echoEndpointTarget = ClientBuilder.newClient().target(uri);
68 | Response response = echoEndpointTarget.request(TEXT_PLAIN).get();
69 | Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
70 | }
71 |
72 | @WebServlet(urlPatterns = "/servlet")
73 | public static class TestServlet extends HttpServlet {
74 | @Override
75 | protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
76 | resp.getWriter().write(CDI.current().select(HelloBean.class).get().hello());
77 | }
78 | }
79 |
80 | @ApplicationPath("/rest")
81 | public static class RestApplication extends jakarta.ws.rs.core.Application {
82 |
83 | }
84 |
85 | @RequestScoped
86 | @Path("/")
87 | public static class TestEndpoint {
88 | @Inject
89 | HelloBean helloBean;
90 |
91 | @GET
92 | public String hello() {
93 | return helloBean.hello();
94 | }
95 | }
96 |
97 | @ApplicationScoped
98 | public static class HelloBean {
99 | public String hello() {
100 | return "hello";
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/contrib/src/main/java/io/smallrye/opentracing/contrib/resolver/PriorityComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 The OpenTracing Authors
3 | * Copied from https://github.com/opentracing-contrib/java-tracerresolver
4 | * Intended only for Jakarta namespace migration
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package io.smallrye.opentracing.contrib.resolver;
19 |
20 | import static java.lang.Math.abs;
21 |
22 | import java.util.ArrayList;
23 | import java.util.Collections;
24 | import java.util.Comparator;
25 |
26 | /**
27 | * Comparator for classes that may or may not contain a {@literal @}Priority annotation
28 | * on their class or superclasses.
29 | *
30 | * The priority is applied as follows:
31 | *
32 | *
First, non-negative priority is applied in natural order (e.g. {@code 0}, {@code 1}, {@code 2}, ...).
33 | *
Next, objects without {@literal @}Priority annotation are applied
34 | * by assigning a {@link #UNDEFINED_PRIORITY default priority} of {@link Integer#MAX_VALUE}.
35 | *
Finally, negative priority is applied in reverse-natural order (e.g. {@code -1}, {@code -2}, {@code -3}, ...).
36 | *
37 | *
38 | * The order of objects with equal (implicit) priority is undefined.
39 | *
40 | * @author Sjoerd Talsma
41 | */
42 | final class PriorityComparator implements Comparator