Skip to content

Commit

Permalink
No-op implementations for Propagator, Setter, and Getter
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 e98ffb7
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

import io.micrometer.common.lang.Nullable;
import io.micrometer.tracing.Span;
import io.micrometer.tracing.Span.Builder;
import io.micrometer.tracing.TraceContext;

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

/**
Expand All @@ -36,6 +38,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> 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 +106,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 +142,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 e98ffb7

Please sign in to comment.