Skip to content

Commit

Permalink
Removed MDCSpanObserver and opentracing-contrib/java-api-extensions d…
Browse files Browse the repository at this point in the history
…ependency
  • Loading branch information
whiskeysierra committed Nov 25, 2019
1 parent 141cb40 commit 3f0402d
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 282 deletions.
28 changes: 1 addition & 27 deletions README.md
Expand Up @@ -127,30 +127,6 @@ The following table describes the contract how a flow id is propagated in differ
| e28a8414294acf36 | n/a | e28a8414294acf36 | n/a | e28a8414294acf36 |
| e28a8414294acf36 | REcCvlqMSReeo7adheiYFA | REcCvlqMSReeo7adheiYFA | REcCvlqMSReeo7adheiYFA | REcCvlqMSReeo7adheiYFA |

### Logging

```xml
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-api-extensions-tracer</artifactId>
<version>0.2.0</version>
</dependency>
```

*Tracer* comes with a very useful `SpanObserver` by default, the `MDCSpanObserver`:

```java
Tracer delegate = ...; // your OpenTracing implementation of choice
APIExtensionsTracer tracer = new APIExtensionsTracer(delegate);
tracer.addTracerObserver(new MDCSpanObserver());
```

It allows you to add the `trace_id`, `span_id` and/or `flow_id` to every log line:

```xml
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} [%X{trace_id}] [%X{flow_id}] - %msg%n"/>
```

## Servlet

On the server side is a single filter that you must be register in your filter chain. Make sure it runs very early — otherwise you might miss some crucial information when debugging.
Expand Down Expand Up @@ -183,17 +159,15 @@ OkHttpClient client = new OkHttpClient.Builder()

## Spring Boot Auto Configuration

*Tracer* comes with a convenient auto configuration for Spring Boot users that sets up aspect, servlet filter and MDC support automatically with sensible defaults:
*Tracer* comes with a convenient auto configuration for Spring Boot users that sets up aspect and servlet filter automatically with sensible defaults:

| Configuration | Description | Default |
|-------------------------------|-------------------------------------------|-----------------------------|
| `tracer.filter.enabled` | Enables the [`FlowFilter`](#servlet) | `true` |
| `tracer.mdc.enabled` | Enables the [`MDCSpanObserver`](#logging) | `true` |

```yaml
tracer:
filter.enabled: true
mdc.enabled: true
```

## Getting Help with Tracer
Expand Down
7 changes: 0 additions & 7 deletions pom.xml
Expand Up @@ -140,13 +140,6 @@
<version>${opentracing.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-api-extensions-tracer</artifactId>
<version>0.6.0</version>
<!-- Needed for pushing trace/span/flow id to MDC-->
<optional>true</optional>
</dependency>
<!-- javax -->
<dependency>
<groupId>javax.servlet</groupId>
Expand Down
4 changes: 0 additions & 4 deletions tracer-core/pom.xml
Expand Up @@ -15,10 +15,6 @@
<developerConnection>scm:git:git@github.com:zalando/tracer.git</developerConnection>
</scm>
<dependencies>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-api-extensions-tracer</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
Expand Down
Expand Up @@ -13,15 +13,15 @@
@AllArgsConstructor
final class CompositeExtractor implements Extractor {

private final Collection<Extractor> strategies;
private final Collection<Extractor> extractors;

CompositeExtractor(final Extractor... strategies) {
this(Arrays.asList(strategies));
CompositeExtractor(final Extractor... extractors) {
this(Arrays.asList(extractors));
}

@Override
public Optional<FlowId> extract(final Span span, final UnaryOperator<String> reader) {
return strategies.stream()
return extractors.stream()
.map(strategy -> strategy.extract(span, reader))
.filter(Optional::isPresent)
.findFirst()
Expand Down
57 changes: 0 additions & 57 deletions tracer-core/src/main/java/org/zalando/tracer/MDCSpanObserver.java

This file was deleted.

Expand Up @@ -11,6 +11,8 @@ final class TraceExtractor implements Extractor {
@Override
public Optional<FlowId> extract(final Span span, final UnaryOperator<String> reader) {
return Optional.of(span.context().toTraceId())
// "An empty String will be returned if the tracer does not support this functionality"
.filter(s -> !s.isEmpty())
.map(id -> new SimpleFlowId(id, Source.TRACE));
}

Expand Down
@@ -1,14 +1,12 @@
package org.zalando.tracer;

import io.opentracing.contrib.api.tracer.APIExtensionsTracer;
import io.opentracing.noop.NoopTracerFactory;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;

class DefaultFlowNoopTracerTest {
private final APIExtensionsTracer tracer = new APIExtensionsTracer(NoopTracerFactory.create());
private final Flow unit = Flow.create(tracer);
private final Flow unit = Flow.create(NoopTracerFactory.create());

@Test
void shouldThrowNoActiveSpanFoundException() {
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions tracer-spring-boot-autoconfigure/pom.xml
Expand Up @@ -27,10 +27,6 @@
<groupId>org.zalando</groupId>
<artifactId>tracer-servlet</artifactId>
</dependency>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-api-extensions-tracer</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down Expand Up @@ -109,6 +105,10 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
Expand Down
@@ -1,7 +1,6 @@
package org.zalando.tracer.autoconfigure;

import io.opentracing.Tracer;
import io.opentracing.contrib.api.tracer.APIExtensionsTracer;
import org.apiguardian.api.API;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
Expand All @@ -12,10 +11,8 @@
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.Ordered;
import org.zalando.tracer.Flow;
import org.zalando.tracer.MDCSpanObserver;
import org.zalando.tracer.httpclient.FlowHttpRequestInterceptor;
import org.zalando.tracer.servlet.FlowFilter;

Expand Down Expand Up @@ -48,16 +45,6 @@ public FlowHttpRequestInterceptor flowHttpRequestInterceptor(final Flow flow) {
return new FlowHttpRequestInterceptor(flow);
}

@API(status = INTERNAL)
@Bean
@Primary
@ConditionalOnProperty(name = "tracer.mdc.enabled", havingValue = "true", matchIfMissing = true)
public Tracer mdcTracer(final Tracer tracer) {
final APIExtensionsTracer extensionsTracer = new APIExtensionsTracer(tracer);
extensionsTracer.addTracerObserver(new MDCSpanObserver());
return extensionsTracer;
}

@Configuration
@ConditionalOnClass({Filter.class, FilterRegistrationBean.class})
@ConditionalOnWebApplication
Expand Down

This file was deleted.

0 comments on commit 3f0402d

Please sign in to comment.