Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 3b31506

Browse files
Adam Lindenthalpavelbucek
authored andcommitted
Open tracing integration (incubator) and example
Change-Id: I39e6d39c288fab2a8fc967149a315edfac082d31
1 parent fad3602 commit 3b31506

File tree

14 files changed

+1615
-0
lines changed

14 files changed

+1615
-0
lines changed

examples/open-tracing/README.MD

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<!--
2+
3+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4+
5+
Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
6+
7+
The contents of this file are subject to the terms of either the GNU
8+
General Public License Version 2 only ("GPL") or the Common Development
9+
and Distribution License("CDDL") (collectively, the "License"). You
10+
may not use this file except in compliance with the License. You can
11+
obtain a copy of the License at
12+
http://glassfish.java.net/public/CDDL+GPL_1_1.html
13+
or packager/legal/LICENSE.txt. See the License for the specific
14+
language governing permissions and limitations under the License.
15+
16+
When distributing the software, include this License Header Notice in each
17+
file and include the License file at packager/legal/LICENSE.txt.
18+
19+
GPL Classpath Exception:
20+
Oracle designates this particular file as subject to the "Classpath"
21+
exception as provided by Oracle in the GPL Version 2 section of the License
22+
file that accompanied this code.
23+
24+
Modifications:
25+
If applicable, add the following below the License Header, with the fields
26+
enclosed by brackets [] replaced by your own identifying information:
27+
"Portions Copyright [year] [name of copyright owner]"
28+
29+
Contributor(s):
30+
If you wish your version of this file to be governed by only the CDDL or
31+
only the GPL Version 2, indicate your decision by adding "[Contributor]
32+
elects to include this software in this distribution under the [CDDL or GPL
33+
Version 2] license." If you don't indicate a single choice of license, a
34+
recipient has the option to distribute your version of this file under
35+
either the CDDL, the GPL Version 2 or to extend the choice of license to
36+
its licensees as provided above. However, if you add GPL Version 2 code
37+
and therefore, elected the GPL Version 2 license, then the option applies
38+
and therefore, elected the GPL Version 2 license, then the option applies
39+
only if the new code is made subject to such option by the copyright
40+
holder.
41+
42+
-->
43+
44+
Jersey OpenTracing Example
45+
==========================
46+
47+
This example demonstrates Jersey OpenTracing integration. The JAX-RS resource contains several resource method showing various
48+
possibilities.
49+
50+
This particular example is configured with Jaeger as the GlobalTracer, but can be easily adjusted to use any other tracer
51+
implementation.
52+
53+
Running the Example
54+
-------------------
55+
Example can be launched as is, but does not perform any interesting action out of the box.
56+
To be able to visualise the traces, it is recommended to start Jaeger (and th UI) locally, e.g. in Docker:
57+
58+
> docker run -d -p 5775:5775/udp -p 16686:16686 jaegertracing/all-in-one:travis-1278
59+
60+
Check the UI on [localhost:16686](http://localhost:16686), there should be no traces visible.
61+
62+
Run the example as follows:
63+
64+
> mvn clean compile exec:java
65+
66+
This deploys the example using [Grizzly](http://grizzly.java.net/) container.
67+
68+
Try to access resources using the URIs listed bellow and look into Jager UI what traces are produced.
69+
The first example should be visible in the Jaeger UI right after the example application is started. Others can be created by
70+
doing rest calls to the exposed resource.
71+
72+
1. On start, the example application sends one request demonstrating more complex tracing
73+
- jersey client (w/ registered OpenTracingFeature) creates the "jersey-client-GET" span
74+
- the span is propagated to server (via http headers), jersey server (w/ registered OpenTracinfFeature) automatically creates a
75+
child span of the client span
76+
- in the resource method, child span of the server span is manually created and propagated into managed client calls
77+
- the managed clients are also tracing-enabled, so each one creates its own child span, that is propagated to the server, and
78+
so on
79+
80+
2. No explicit (user-defined) spans.
81+
- one automatically created "root" span, that measures the processing on the Jersey side and one "resource-level" span to be
82+
used for logging events on the application level
83+
- the "root" contains several tags with request and response metadata, such as request headers, status code, etc
84+
- also, several technical Jersey-level events have been logged
85+
- to see this simple case, call
86+
> curl localhost:8080/opentracing/resource/defaultTrace
87+
88+
3. Explicit logging into resource-level span
89+
- same as above, but the "resource-level" span was resolved within the application logic, an event was logged and a tag was added
90+
> curl localhost:8080/opentracing/resource/appLevelLogging
91+
92+
- similar call with POST:
93+
> curl -X POST -d "Jersey Rocks" localhost:8080/opentracing/resource/appLevelPost
94+
95+
96+
4. Explicit child span creation
97+
- same as above, but instead of "resource-level" span, a child span was created and used for logging and adding tags
98+
- note, that such a span needs to be finished manually, otherwise it won't propagate (the tracing info will be lost)
99+
> curl localhost:8080/opentracing/resource/childSpan
100+
101+
102+
4. Client calls from the resource
103+
- more complex case, the resource method invokes two client calls using managed client
104+
- one request via managed client is triggered within the "provided", resource-level span
105+
- child span is created and another request via manged client is triggered within the child span
106+
- the span context needs to be propagated manually using the OpenTracingFeature.SPAN_CONTEXT_PROPERTY
107+
- in both cases, the span context is propagated using http headers to the server and back to the client
108+
- the child span (created in the resource) needs to be explicitly finished in the resource (or elsewhere, but needs to be finished)
109+
> curl localhost:8080/opentracing/resource/traceWithManagedClient
110+
111+
5. Asynchronous processing
112+
- either basic case, but using asynchronous request processing
113+
- there should be no practical difference visible in the tracing info
114+
> curl localhost:8080/opentracing/resource/async
115+
116+
6. Failing resource
117+
- demonstrates exception thrown in the resource method
118+
- Jaeger shows failed spans with the exclamation mark symbol and the exception is logged in the request span
119+
> curl localhost:8080/opentracing/resource/error

examples/open-tracing/pom.xml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5+
6+
Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
7+
8+
The contents of this file are subject to the terms of either the GNU
9+
General Public License Version 2 only ("GPL") or the Common Development
10+
and Distribution License("CDDL") (collectively, the "License"). You
11+
may not use this file except in compliance with the License. You can
12+
obtain a copy of the License at
13+
http://glassfish.java.net/public/CDDL+GPL_1_1.html
14+
or packager/legal/LICENSE.txt. See the License for the specific
15+
language governing permissions and limitations under the License.
16+
17+
When distributing the software, include this License Header Notice in each
18+
file and include the License file at packager/legal/LICENSE.txt.
19+
20+
GPL Classpath Exception:
21+
Oracle designates this particular file as subject to the "Classpath"
22+
exception as provided by Oracle in the GPL Version 2 section of the License
23+
file that accompanied this code.
24+
25+
Modifications:
26+
If applicable, add the following below the License Header, with the fields
27+
enclosed by brackets [] replaced by your own identifying information:
28+
"Portions Copyright [year] [name of copyright owner]"
29+
30+
Contributor(s):
31+
If you wish your version of this file to be governed by only the CDDL or
32+
only the GPL Version 2, indicate your decision by adding "[Contributor]
33+
elects to include this software in this distribution under the [CDDL or GPL
34+
Version 2] license." If you don't indicate a single choice of license, a
35+
recipient has the option to distribute your version of this file under
36+
either the CDDL, the GPL Version 2 or to extend the choice of license to
37+
its licensees as provided above. However, if you add GPL Version 2 code
38+
and therefore, elected the GPL Version 2 license, then the option applies
39+
only if the new code is made subject to such option by the copyright
40+
holder.
41+
42+
-->
43+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44+
<modelVersion>4.0.0</modelVersion>
45+
46+
<parent>
47+
<groupId>org.glassfish.jersey.examples</groupId>
48+
<artifactId>project</artifactId>
49+
<version>2.26-SNAPSHOT</version>
50+
</parent>
51+
52+
<artifactId>open-tracing</artifactId>
53+
<packaging>jar</packaging>
54+
<name>jersey-examples-open-tracing</name>
55+
56+
<description>Jersey OpenTracing example</description>
57+
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.glassfish.jersey.containers</groupId>
61+
<artifactId>jersey-container-grizzly2-http</artifactId>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>org.glassfish.jersey.incubator</groupId>
66+
<artifactId>jersey-open-tracing</artifactId>
67+
<!-- not a part of bom pom.xml as long as it resides in incubator -->
68+
<version>${project.version}</version>
69+
</dependency>
70+
71+
<dependency>
72+
<groupId>io.opentracing</groupId>
73+
<artifactId>opentracing-api</artifactId>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>io.opentracing</groupId>
78+
<artifactId>opentracing-util</artifactId>
79+
</dependency>
80+
81+
<dependency>
82+
<groupId>com.uber.jaeger</groupId>
83+
<artifactId>jaeger-core</artifactId>
84+
<version>0.20.0</version>
85+
</dependency>
86+
87+
88+
<dependency>
89+
<groupId>org.glassfish.jersey.test-framework</groupId>
90+
<artifactId>jersey-test-framework-util</artifactId>
91+
<scope>test</scope>
92+
</dependency>
93+
94+
<dependency>
95+
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
96+
<artifactId>jersey-test-framework-provider-bundle</artifactId>
97+
<type>pom</type>
98+
<scope>test</scope>
99+
</dependency>
100+
101+
<dependency>
102+
<groupId>org.glassfish.jersey.inject</groupId>
103+
<artifactId>jersey-hk2</artifactId>
104+
</dependency>
105+
106+
</dependencies>
107+
108+
<build>
109+
<plugins>
110+
<plugin>
111+
<groupId>org.codehaus.mojo</groupId>
112+
<artifactId>exec-maven-plugin</artifactId>
113+
<configuration>
114+
<mainClass>org.glassfish.jersey.examples.opentracing.App</mainClass>
115+
</configuration>
116+
</plugin>
117+
</plugins>
118+
</build>
119+
120+
<profiles>
121+
<profile>
122+
<id>release</id>
123+
<build>
124+
<plugins>
125+
<plugin>
126+
<groupId>org.apache.maven.plugins</groupId>
127+
<artifactId>maven-assembly-plugin</artifactId>
128+
</plugin>
129+
</plugins>
130+
</build>
131+
</profile>
132+
</profiles>
133+
134+
</project>

0 commit comments

Comments
 (0)