Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package io.micrometer.tracing;

import io.micrometer.common.lang.Nullable;

import java.io.Closeable;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;

import io.micrometer.common.lang.Nullable;

/**
* This API was heavily influenced by Brave. Parts of its documentation were taken
* directly from Brave.
Expand All @@ -35,6 +35,50 @@
*/
public interface CurrentTraceContext {

/**
* A noop implementation.
*/
CurrentTraceContext NOOP = new CurrentTraceContext() {
@Override
public TraceContext context() {
return TraceContext.NOOP;
}

@Override
public Scope newScope(TraceContext context) {
return () -> {

};
}

@Override
public Scope maybeScope(TraceContext context) {
return () -> {

};
}

@Override
public <C> Callable<C> wrap(Callable<C> task) {
return task;
}

@Override
public Runnable wrap(Runnable task) {
return task;
}

@Override
public Executor wrap(Executor delegate) {
return delegate;
}

@Override
public ExecutorService wrap(ExecutorService delegate) {
return delegate;
}
};

/**
* @return current {@link TraceContext} or {@code null} if not set.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,46 @@
*/
public interface ScopedSpan {

/**
* A noop implementation.
*/
ScopedSpan NOOP = new ScopedSpan() {
@Override
public boolean isNoop() {
return true;
}

@Override
public TraceContext context() {
return TraceContext.NOOP;
}

@Override
public ScopedSpan name(String name) {
return this;
}

@Override
public ScopedSpan tag(String key, String value) {
return this;
}

@Override
public ScopedSpan event(String value) {
return this;
}

@Override
public ScopedSpan error(Throwable throwable) {
return this;
}

@Override
public void end() {

}
};

/**
* @return {@code true} when no recording is done and nothing is reported to an
* external system. However, this span should still be injected into outgoing
Expand Down
134 changes: 132 additions & 2 deletions micrometer-tracing/src/main/java/io/micrometer/tracing/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package io.micrometer.tracing;

import java.util.concurrent.TimeUnit;

import io.micrometer.tracing.propagation.Propagator;

import java.util.concurrent.TimeUnit;

/**
* This API was heavily influenced by Brave. Parts of its documentation were taken
* directly from Brave.
Expand All @@ -32,6 +32,76 @@
*/
public interface Span extends io.micrometer.tracing.SpanCustomizer {

/**
* A noop implementation.
*/
Span NOOP = new Span() {
@Override
public boolean isNoop() {
return true;
}

@Override
public TraceContext context() {
return TraceContext.NOOP;
}

@Override
public Span start() {
return this;
}

@Override
public Span name(String name) {
return this;
}

@Override
public Span event(String value) {
return this;
}

@Override
public Span event(String value, long time, TimeUnit timeUnit) {
return this;
}

@Override
public Span tag(String key, String value) {
return this;
}

@Override
public Span error(Throwable throwable) {
return this;
}

@Override
public void end() {

}

@Override
public void end(long time, TimeUnit timeUnit) {

}

@Override
public void abandon() {

}

@Override
public Span remoteServiceName(String remoteServiceName) {
return this;
}

@Override
public Span remoteIpAndPort(String ip, int port) {
return this;
}
};

/**
* @return {@code true} when no recording is done and nothing is reported to an
* external system. However, this span should still be injected into outgoing
Expand Down Expand Up @@ -168,6 +238,66 @@ enum Kind {
*/
interface Builder {

/**
* A noop implementation.
*/
Builder NOOP = new Builder() {
@Override
public Builder setParent(TraceContext context) {
return this;
}

@Override
public Builder setNoParent() {
return this;
}

@Override
public Builder name(String name) {
return this;
}

@Override
public Builder event(String value) {
return this;
}

@Override
public Builder tag(String key, String value) {
return this;
}

@Override
public Builder error(Throwable throwable) {
return this;
}

@Override
public Builder kind(Kind spanKind) {
return this;
}

@Override
public Builder remoteServiceName(String remoteServiceName) {
return this;
}

@Override
public Builder remoteIpAndPort(String ip, int port) {
return this;
}

@Override
public Builder startTimestamp(long startTimestamp, TimeUnit unit) {
return this;
}

@Override
public Span start() {
return Span.NOOP;
}
};

/**
* Sets the parent of the built span.
* @param context parent's context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@
*/
public interface SpanCustomizer {

/**
* A noop implementation.
*/
SpanCustomizer NOOP = new SpanCustomizer() {
@Override
public SpanCustomizer name(String name) {
return this;
}

@Override
public SpanCustomizer tag(String key, String value) {
return this;
}

@Override
public SpanCustomizer event(String value) {
return this;
}
};

/**
* Sets a name on a span.
* @param name name to set on a span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@
*/
public interface TraceContext {

/**
* A noop implementation.
*/
TraceContext NOOP = new TraceContext() {
@Override
public String traceId() {
return "";
}

@Override
public String parentId() {
return null;
}

@Override
public String spanId() {
return "";
}

@Override
public Boolean sampled() {
return null;
}
};

/**
* Trace id.
* @return trace id of a span
Expand Down Expand Up @@ -57,6 +82,36 @@ public interface TraceContext {
*/
interface Builder {

/**
* A noop implementation.
*/
Builder NOOP = new Builder() {
@Override
public Builder traceId(String traceId) {
return this;
}

@Override
public Builder parentId(String parentId) {
return this;
}

@Override
public Builder spanId(String spanId) {
return this;
}

@Override
public Builder sampled(Boolean sampled) {
return this;
}

@Override
public TraceContext build() {
return TraceContext.NOOP;
}
};

/**
* Sets trace id on the trace context.
* @param traceId trace id
Expand Down
Loading