Skip to content

Commit 0ac36c3

Browse files
csabakosgeoand
authored andcommitted
Add Spring WebFlux and WebClient tracing. (#95)
1 parent b15a762 commit 0ac36c3

File tree

73 files changed

+2739
-155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2739
-155
lines changed

.settings.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2016-2019 The OpenTracing Authors
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+
-->
217
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
318
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
419
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0

README.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,32 @@
22

33
# OpenTracing Spring Web Instrumentation
44

5-
This library provides instrumentation for Spring Web applications (Boot and MVC). It creates tracing data for
6-
server requests and also client requests (`RestTemplate` and `AsyncRestTemplate`).
5+
This library provides instrumentation for Spring Web applications (Boot, MVC and WebFlux). It creates tracing data for
6+
server requests and also client requests (`RestTemplate`, `AsyncRestTemplate` and `WebClient`).
77

88
## Use [opentracing-spring-cloud](https://github.com/opentracing-contrib/java-spring-cloud) instead
99

1010
As it was mentioned above this library traces only inbound/outbound HTTP requests. If you would like to
1111
get automatically traced different set of technologies e.g. `spring-cloud-netflix`, JMS or even more then
1212
use project [opentracing-spring-cloud](https://github.com/opentracing-contrib/java-spring-cloud) instead.
1313

14+
For reactive applications, it is especially recommended to use `reactor` tracing from
15+
[opentracing-spring-cloud](https://github.com/opentracing-contrib/java-spring-cloud), as that will ensure
16+
that the `Span` is activated in reactor handler functions. (Without that, one would have to extract the
17+
`Span` from the subscriber context.)
18+
1419
## How does the server tracing work?
1520

21+
### Servlet
1622
Server span is started in [Web Servlet Filter](https://github.com/opentracing-contrib/java-web-servlet-filter),
1723
then tracing interceptor adds spring related tags and logs. There are use case when spring boot invokes a handler after
1824
a request processing in filter finished, in this case interceptor starts a new span as `followsFrom`
1925
which references the initial span created in the servlet filter.
2026

27+
### Reactive
28+
Server span is started in [TracingWebFilter](opentracing-spring-web/src/main/java/io/opentracing/contrib/spring/web/webfilter/TracingWebFilter.java)
29+
(upon subscription), then `onNext()`, `onError()`, etc. handlers add Spring WebFlux related tags and logs.
30+
2131
## Library versions
2232

2333
Versions 1.x.y of the library are meant to target Spring Framework 5.x and Spring Boot 2.x while versions 0.x.y are meant to be used with Spring Framework 4.3 and Spring Boot 1.5
@@ -36,11 +46,11 @@ If you are using Spring Boot the easiest way how to configure OpenTracing instru
3646

3747
```
3848
Just provide an OpenTracing tracer bean and all required configuration is automatically
39-
done for you. It also instruments all `RestTemplate` and `AsyncRestTemplate` beans.
49+
done for you. It also instruments all `RestTemplate`, `AsyncRestTemplate`, `WebClient` and `WebClient.Builder` beans.
4050

4151
### Manual configuration
4252

43-
#### Server
53+
#### Servlet and MVC Server
4454
Configuration needs to add `TracingFilter` and `TracingHandlerInterceptor`. Both of these classes
4555
are required!
4656

@@ -77,6 +87,25 @@ public class MVCConfiguration extends WebMvcConfigurerAdapter {
7787

7888
XML based configuration can be used too. Filter can be also directly defined in `web.xml`.
7989

90+
#### Reactive Server
91+
Configuration needs to add the `TracingWebFilter` bean.
92+
93+
```java
94+
@Configuration
95+
class TracingConfiguration {
96+
@Bean
97+
public TracingWebFilter tracingWebFilter(Tracer tracer) {
98+
return new TracingWebFilter(
99+
tracer,
100+
Integer.MIN_VALUE, // Order
101+
Pattern.compile(""), // Skip pattern
102+
Collections.singletonList("/*"), // URL patterns
103+
Arrays.asList(new WebFluxSpanDecorator.StandardTags(), new WebFluxSpanDecorator.WebFluxTags())
104+
);
105+
}
106+
}
107+
```
108+
80109
#### Client
81110
```java
82111
RestTemplate restTemplate = new RestTemplate();
@@ -85,6 +114,13 @@ restTemplate.setInterceptors(Collections.singletonList(new TracingRestTemplateIn
85114
// the same applies for AsyncRestTemplate
86115
```
87116

117+
#### Reactive Client
118+
```java
119+
WebClient webClient = WebClient.builder()
120+
.filter(new TracingExchangeFilterFunction(tracer, Collections.singletonList(new WebClientSpanDecorator.StandardTags())))
121+
.build();
122+
```
123+
88124
## Access server span
89125
```java
90126
@RequestMapping("/hello")

header.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Copyright ${license.git.copyrightYears} The OpenTracing Authors
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4+
in compliance with the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License
9+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10+
or implied. See the License for the specific language governing permissions and limitations under
11+
the License.

opentracing-spring-web-itest/boot/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2016-2019 The OpenTracing Authors
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+
-->
217
<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">
318
<modelVersion>4.0.0</modelVersion>
419
<parent>
@@ -9,6 +24,10 @@
924

1025
<artifactId>opentracing-spring-web-itest-boot</artifactId>
1126

27+
<properties>
28+
<main.basedir>${project.basedir}/../..</main.basedir>
29+
</properties>
30+
1231
<dependencies>
1332
<dependency>
1433
<groupId>${project.groupId}</groupId>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
<%--
2+
3+
Copyright 2016-2019 The OpenTracing Authors
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6+
in compliance with the License. You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software distributed under the License
11+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
or implied. See the License for the specific language governing permissions and limitations under
13+
the License.
14+
15+
--%>
116
<!DOCTYPE html>
217
<body/>
318
</html>

opentracing-spring-web-itest/boot/src/test/java/io/opentracing/contrib/spring/web/interceptor/itest/boot/BootITest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* Copyright 2016-2019 The OpenTracing Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
114
package io.opentracing.contrib.spring.web.interceptor.itest.boot;
215

316
import org.junit.runner.RunWith;

opentracing-spring-web-itest/boot/src/test/java/io/opentracing/contrib/spring/web/interceptor/itest/boot/SpringBootConfiguration.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* Copyright 2016-2019 The OpenTracing Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
114
package io.opentracing.contrib.spring.web.interceptor.itest.boot;
215

316
import java.util.Collections;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1+
#
2+
# Copyright 2016-2019 The OpenTracing Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
# in compliance with the License. You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software distributed under the License
10+
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
# or implied. See the License for the specific language governing permissions and limitations under
12+
# the License.
13+
#
14+
115
spring.mvc.view.prefix: WEB-INF/jsp/
216
spring.mvc.view.suffix: .jsp

opentracing-spring-web-itest/common/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2016-2019 The OpenTracing Authors
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+
-->
217
<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">
318
<modelVersion>4.0.0</modelVersion>
419
<parent>
@@ -9,6 +24,10 @@
924

1025
<artifactId>opentracing-spring-web-itest-common</artifactId>
1126

27+
<properties>
28+
<main.basedir>${project.basedir}/../..</main.basedir>
29+
</properties>
30+
1231
<dependencies>
1332
<dependency>
1433
<groupId>${project.groupId}</groupId>

opentracing-spring-web-itest/common/src/test/java/io/opentracing/contrib/spring/web/interceptor/itest/common/AbstractBaseITests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* Copyright 2016-2019 The OpenTracing Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
114
package io.opentracing.contrib.spring.web.interceptor.itest.common;
215

316
import io.opentracing.contrib.spring.web.interceptor.HandlerInterceptorSpanDecorator;

0 commit comments

Comments
 (0)