Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No-op implementations for Propagator, Setter, and Getter #118

Merged
merged 1 commit into from
Nov 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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