Add spring webflux documentation (#916)
* add readme and rename springwebflux package * add readme and rename springwebflux package * fix bean type * fix readme * format * fix gradle * fix gradle * fix gradle * updated package name * clean up readme * Update README.md * Update instrumentation-core/spring/spring-webflux-5.0/README.md Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com> * Update instrumentation-core/spring/spring-webflux-5.0/README.md Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com> * format, clean up comments * clean ups * Update README.md * fix conflict * fix helper class names Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
This commit is contained in:
parent
5b114d0ac8
commit
56e1549378
|
@ -16,7 +16,7 @@
|
|||
|
||||
package io.opentelemetry.instrumentation.spring.autoconfigure.httpclients.webclient;
|
||||
|
||||
import io.opentelemetry.instrumentation.springwebflux.client.WebClientTracingFilter;
|
||||
import io.opentelemetry.instrumentation.spring.webflux.client.WebClientTracingFilter;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
|
|
@ -18,7 +18,7 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.httpclients.webcli
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import io.opentelemetry.instrumentation.springwebflux.client.WebClientTracingFilter;
|
||||
import io.opentelemetry.instrumentation.spring.webflux.client.WebClientTracingFilter;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
# Manual Instrumentation for Spring Webflux
|
||||
|
||||
Provides OpenTelemetry instrumentation for Spring's WebClient.
|
||||
|
||||
## Quickstart
|
||||
|
||||
### Add these dependencies to your project.
|
||||
|
||||
Replace `SPRING_VERSION` with the version of spring you're using.
|
||||
`Minimum version: 5.0`
|
||||
|
||||
Replace `OPENTELEMETRY_VERSION` with the latest stable [release](https://mvnrepository.com/artifact/io.opentelemetry).
|
||||
`Minimum version: 0.8.0`
|
||||
|
||||
|
||||
For Maven add to your `pom.xml`:
|
||||
|
||||
```xml
|
||||
<dependencies>
|
||||
<!-- opentelemetry instrumentation -->
|
||||
<dependency>
|
||||
<groupId>io.opentelemetry.instrumentation</groupId>
|
||||
<artifactId>opentelemetry-spring-webflux-5.0</artifactId>
|
||||
<version>OPENTELEMETRY_VERSION</version>
|
||||
</dependency>
|
||||
|
||||
<!-- opentelemetry exporter -->
|
||||
<!-- replace this default exporter with your opentelemetry exporter (ex. otlp/zipkin/jaeger/..) -->
|
||||
<dependency>
|
||||
<groupId>io.opentelemetry</groupId>
|
||||
<artifactId>opentelemetry-exporters-logging</artifactId>
|
||||
<version>OPENTELEMETRY_VERSION</version>
|
||||
</dependency>
|
||||
|
||||
<!-- required to instrument spring-webflux -->
|
||||
<!-- this artifact should already be present in your application -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webflux</artifactId>
|
||||
<version>SPRING_VERSION</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
For Gradle add to your dependencies:
|
||||
|
||||
```groovy
|
||||
// opentelemetry instrumentation
|
||||
implementation 'io.opentelemetry.instrumentation:opentelemetry-spring-webflux-5.0:OPENTELEMETRY_VERSION'
|
||||
|
||||
// opentelemetry exporter
|
||||
// replace this default exporter with your opentelemetry exporter (ex. otlp/zipkin/jaeger/..)
|
||||
implementation 'io.opentelemetry:opentelemetry-exporters-logging:OPENTELEMETRY_VERSION'
|
||||
|
||||
// required to instrument spring-webmvc
|
||||
// this artifact should already be present in your application
|
||||
implementation 'org.springframework:spring-webflux:SPRING_VERSION'
|
||||
```
|
||||
|
||||
### Features
|
||||
|
||||
#### WebClientTracingFilter
|
||||
|
||||
WebClientTracingFilter adds OpenTelemetry client spans to requests sent using WebClient by implementing the [ExchangeFilterFunction](https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/reactive/function/client/ExchangeFilterFunction.html)
|
||||
interface. An example is shown below:
|
||||
|
||||
##### Usage
|
||||
|
||||
```java
|
||||
|
||||
import io.opentelemetry.instrumentation.spring.webflux.client.WebClientTracingFilter
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
@Configuration
|
||||
public class WebClientConfig {
|
||||
|
||||
@Bean
|
||||
public WebClient.Builder webClient(Tracer tracer) {
|
||||
|
||||
WebClient webClient = WebClient.create();
|
||||
WebClientTracingFilter webClientTracingFilter = new WebClientTracingFilter(tracer);
|
||||
|
||||
return webClient.mutate().filter(webClientTracingFilter);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Starter Guide
|
||||
|
||||
Check out the opentelemetry [quick start](https://github.com/open-telemetry/opentelemetry-java/blob/master/QUICKSTART.md) to learn more about OpenTelemetry instrumentation.
|
|
@ -1,6 +1,6 @@
|
|||
ext {
|
||||
minJavaVersionForTests = JavaVersion.VERSION_1_8
|
||||
javaSubPackage = 'springwebflux.client'
|
||||
javaSubPackage = 'spring.webflux.client'
|
||||
}
|
||||
|
||||
apply from: "$rootDir/gradle/instrumentation-library.gradle"
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.springwebflux.client;
|
||||
package io.opentelemetry.instrumentation.spring.webflux.client;
|
||||
|
||||
import io.opentelemetry.context.propagation.HttpTextFormat;
|
||||
import org.springframework.http.HttpHeaders;
|
|
@ -14,11 +14,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.springwebflux.client;
|
||||
package io.opentelemetry.instrumentation.spring.webflux.client;
|
||||
|
||||
import static io.opentelemetry.OpenTelemetry.getPropagators;
|
||||
import static io.opentelemetry.OpenTelemetry.getTracerProvider;
|
||||
import static io.opentelemetry.instrumentation.springwebflux.client.HttpHeadersInjectAdapter.SETTER;
|
||||
import static io.opentelemetry.instrumentation.spring.webflux.client.HttpHeadersInjectAdapter.SETTER;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.instrumentation.api.decorator.HttpClientDecorator;
|
|
@ -14,10 +14,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.springwebflux.client;
|
||||
package io.opentelemetry.instrumentation.spring.webflux.client;
|
||||
|
||||
import static io.opentelemetry.instrumentation.springwebflux.client.SpringWebfluxHttpClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.instrumentation.springwebflux.client.SpringWebfluxHttpClientDecorator.TRACER;
|
||||
import static io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientDecorator.TRACER;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.context.Scope;
|
|
@ -14,9 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.auto.instrumentation.springwebflux.client;
|
||||
package io.opentelemetry.auto.instrumentation.spring.webflux.client;
|
||||
|
||||
import io.opentelemetry.instrumentation.springwebflux.client.WebClientTracingFilter;
|
||||
import io.opentelemetry.instrumentation.spring.webflux.client.WebClientTracingFilter;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.auto.instrumentation.springwebflux.client;
|
||||
package io.opentelemetry.auto.instrumentation.spring.webflux.client;
|
||||
|
||||
import static io.opentelemetry.auto.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static io.opentelemetry.auto.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
||||
|
@ -46,9 +46,9 @@ public class WebClientFilterInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
"io.opentelemetry.instrumentation.springwebflux.client.SpringWebfluxHttpClientDecorator",
|
||||
"io.opentelemetry.instrumentation.springwebflux.client.HttpHeadersInjectAdapter",
|
||||
"io.opentelemetry.instrumentation.springwebflux.client.WebClientTracingFilter"
|
||||
"io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxHttpClientDecorator",
|
||||
"io.opentelemetry.instrumentation.spring.webflux.client.HttpHeadersInjectAdapter",
|
||||
"io.opentelemetry.instrumentation.spring.webflux.client.WebClientTracingFilter"
|
||||
};
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.auto.instrumentation.springwebflux.server;
|
||||
package io.opentelemetry.auto.instrumentation.spring.webflux.server;
|
||||
|
||||
import io.opentelemetry.auto.tooling.Instrumenter;
|
||||
|
|
@ -14,9 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.auto.instrumentation.springwebflux.server;
|
||||
package io.opentelemetry.auto.instrumentation.spring.webflux.server;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.springwebflux.server.SpringWebfluxHttpServerDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.spring.webflux.server.SpringWebfluxHttpServerDecorator.DECORATE;
|
||||
import static io.opentelemetry.context.ContextUtils.withScopedContext;
|
||||
|
||||
import io.opentelemetry.context.Scope;
|
|
@ -14,10 +14,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.auto.instrumentation.springwebflux.server;
|
||||
package io.opentelemetry.auto.instrumentation.spring.webflux.server;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.springwebflux.server.SpringWebfluxHttpServerDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.springwebflux.server.SpringWebfluxHttpServerDecorator.TRACER;
|
||||
import static io.opentelemetry.auto.instrumentation.spring.webflux.server.SpringWebfluxHttpServerDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.spring.webflux.server.SpringWebfluxHttpServerDecorator.TRACER;
|
||||
import static io.opentelemetry.context.ContextUtils.withScopedContext;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.withSpan;
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.auto.instrumentation.springwebflux.server;
|
||||
package io.opentelemetry.auto.instrumentation.spring.webflux.server;
|
||||
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
|
@ -14,9 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.auto.instrumentation.springwebflux.server;
|
||||
package io.opentelemetry.auto.instrumentation.spring.webflux.server;
|
||||
|
||||
import static io.opentelemetry.auto.instrumentation.springwebflux.server.SpringWebfluxHttpServerDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.spring.webflux.server.SpringWebfluxHttpServerDecorator.DECORATE;
|
||||
import static io.opentelemetry.trace.TracingContextUtils.currentContextWith;
|
||||
|
||||
import io.grpc.Context;
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.auto.instrumentation.springwebflux.server;
|
||||
package io.opentelemetry.auto.instrumentation.spring.webflux.server;
|
||||
|
||||
import static io.opentelemetry.auto.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static io.opentelemetry.auto.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.auto.instrumentation.springwebflux.server;
|
||||
package io.opentelemetry.auto.instrumentation.spring.webflux.server;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.instrumentation.api.decorator.BaseTracer;
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.auto.instrumentation.springwebflux.server;
|
||||
package io.opentelemetry.auto.instrumentation.spring.webflux.server;
|
||||
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import org.springframework.web.reactive.function.server.HandlerFunction;
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.auto.instrumentation.springwebflux.server;
|
||||
package io.opentelemetry.auto.instrumentation.spring.webflux.server;
|
||||
|
||||
import static io.opentelemetry.auto.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static io.opentelemetry.auto.tooling.bytebuddy.matcher.AgentElementMatchers.extendsClass;
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.auto.instrumentation.springwebflux.server;
|
||||
package io.opentelemetry.auto.instrumentation.spring.webflux.server;
|
||||
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.instrumentation.api.decorator.ServerDecorator;
|
Loading…
Reference in New Issue