Skip to content

Commit

Permalink
No-op implementations for Propagator, Setter, and Getter (#118)
Browse files Browse the repository at this point in the history
Add no-op implementations for Propagator and its Setter and Getter.
  • Loading branch information
ttddyy committed Nov 13, 2022
1 parent 34f5b55 commit 7dae272
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.micrometer.tracing.Span;
import io.micrometer.tracing.TraceContext;

import java.util.Collections;
import java.util.List;

/**
Expand All @@ -36,6 +37,29 @@
*/
public interface Propagator {

/**
* A noop implementation.
* <p>
* This implementation could be used with sender/receiver that do not need any
* propagation. e.g. database access
*/
Propagator NOOP = new Propagator() {
@Override
public List<String> fields() {
return Collections.emptyList();
}

@Override
public <C> void inject(TraceContext context, C carrier, Setter<C> setter) {

}

@Override
public <C> Span.Builder extract(C carrier, Getter<C> getter) {
return Span.Builder.NOOP;
}
};

/**
* @return collection of headers that contain tracing information
*/
Expand Down Expand Up @@ -81,6 +105,13 @@ public interface Propagator {
*/
interface Setter<C> {

/**
* A noop implementation.
*/
@SuppressWarnings("rawtypes")
Setter NOOP = (carrier, key, value) -> {
};

/**
* Replaces a propagated field with the given value.
*
Expand Down Expand Up @@ -110,6 +141,12 @@ interface Setter<C> {
*/
interface Getter<C> {

/**
* A noop implementation.
*/
@SuppressWarnings("rawtypes")
Getter NOOP = (carrier, key) -> null;

/**
* Returns the first value of the given propagation {@code key} or returns
* {@code null}.
Expand Down

0 comments on commit 7dae272

Please sign in to comment.