Skip to content

Commit

Permalink
Rename view and controller suppression config properties (#5747)
Browse files Browse the repository at this point in the history
* Rename view and controller suppression config properties

* code review comments
  • Loading branch information
Mateusz Rzeszutek authored Apr 5, 2022
1 parent 27e8201 commit 39e1fcb
Show file tree
Hide file tree
Showing 23 changed files with 68 additions and 34 deletions.
4 changes: 2 additions & 2 deletions docs/contributing/using-instrumenter-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ method.
### Disable the instrumentation

In some rare cases it may be useful to completely disable the constructed `Instrumenter`, for
example, based on a configuration property. The `InstrumenterBuilder` exposes a `setDisabled()`
method for that: passing `true` will turn the newly created `Instrumenter` into a no-op instance.
example, based on a configuration property. The `InstrumenterBuilder` exposes a `setEnabled()`
method for that: passing `false` will turn the newly created `Instrumenter` into a no-op instance.

### Finally, set the span kind with the `SpanKindExtractor` and get a new `Instrumenter`!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ public ExperimentalConfig(Config config) {
this.config = config;
}

public boolean suppressControllerSpans() {
public boolean controllerTelemetryEnabled() {
// TODO: remove that `suppress...` flag after 1.13 release
boolean suppressControllerSpans =
config.getBoolean(
"otel.instrumentation.common.experimental.suppress-controller-spans", false);
return config.getBoolean(
"otel.instrumentation.common.experimental.suppress-controller-spans", false);
"otel.instrumentation.common.experimental.controller-telemetry.enabled",
!suppressControllerSpans);
}

public boolean suppressViewSpans() {
return config.getBoolean("otel.instrumentation.common.experimental.suppress-view-spans", false);
public boolean viewTelemetryEnabled() {
// TODO: remove that `suppress...` flag after 1.13 release
boolean suppressViewSpans =
config.getBoolean("otel.instrumentation.common.experimental.suppress-view-spans", false);
return config.getBoolean(
"otel.instrumentation.common.experimental.view-telemetry.enabled", !suppressViewSpans);
}

public boolean messagingReceiveInstrumentationEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static <REQUEST, RESPONSE> InstrumenterBuilder<REQUEST, RESPONSE> builder
private final List<? extends RequestListener> requestListeners;
private final ErrorCauseExtractor errorCauseExtractor;
@Nullable private final TimeExtractor<REQUEST, RESPONSE> timeExtractor;
private final boolean disabled;
private final boolean enabled;
private final SpanSuppressionStrategy spanSuppressionStrategy;

Instrumenter(InstrumenterBuilder<REQUEST, RESPONSE> builder) {
Expand All @@ -123,7 +123,7 @@ public static <REQUEST, RESPONSE> InstrumenterBuilder<REQUEST, RESPONSE> builder
this.requestListeners = new ArrayList<>(builder.requestListeners);
this.errorCauseExtractor = builder.errorCauseExtractor;
this.timeExtractor = builder.timeExtractor;
this.disabled = builder.disabled;
this.enabled = builder.enabled;
this.spanSuppressionStrategy = builder.getSpanSuppressionStrategy();
}

Expand All @@ -134,7 +134,7 @@ public static <REQUEST, RESPONSE> InstrumenterBuilder<REQUEST, RESPONSE> builder
* without calling those methods.
*/
public boolean shouldStart(Context parentContext, REQUEST request) {
if (disabled) {
if (!enabled) {
return false;
}
SpanKind spanKind = spanKindExtractor.extract(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
SpanStatusExtractor.getDefault();
ErrorCauseExtractor errorCauseExtractor = ErrorCauseExtractor.jdk();
@Nullable TimeExtractor<REQUEST, RESPONSE> timeExtractor = null;
boolean disabled = false;
boolean enabled = true;

private boolean enableSpanSuppressionByType = ENABLE_SPAN_SUPPRESSION_BY_TYPE;

Expand Down Expand Up @@ -159,11 +159,25 @@ public InstrumenterBuilder<REQUEST, RESPONSE> setTimeExtractor(
return this;
}

public InstrumenterBuilder<REQUEST, RESPONSE> setDisabled(boolean disabled) {
this.disabled = disabled;
/**
* Allows enabling/disabling the {@link Instrumenter} based on the {@code enabled} value passed as
* parameter. All instrumenters are enabled by default.
*/
public InstrumenterBuilder<REQUEST, RESPONSE> setEnabled(boolean enabled) {
this.enabled = enabled;
return this;
}

/**
* Allows to disable the {@link Instrumenter}.
*
* @deprecated Use {@link #setEnabled(boolean)} instead.
*/
@Deprecated
public InstrumenterBuilder<REQUEST, RESPONSE> setDisabled(boolean disabled) {
return setEnabled(!disabled);
}

// visible for tests
/**
* Enables CLIENT nested span suppression based on the instrumentation type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,17 @@ void shouldUseContextCustomizer() {
assertThat(context.get(testKey)).isEqualTo("testVal");
}

@Test
void shouldDisableInstrumenter() {
Instrumenter<String, String> instrumenter =
Instrumenter.<String, String>builder(
otelTesting.getOpenTelemetry(), "test", request -> "test span")
.setEnabled(false)
.newInstrumenter();

assertThat(instrumenter.shouldStart(Context.root(), "request")).isFalse();
}

@Test
void clientNestedSpansSuppressed_whenInstrumentationTypeDisabled() {
// this test depends on default config option for InstrumentationType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class DropwizardSingletons {
private static final Instrumenter<View, Void> INSTRUMENTER =
Instrumenter.<View, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, DropwizardSingletons::spanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();

private static String spanName(View view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class GrailsSingletons {
INSTRUMENTER =
Instrumenter.<HandlerData, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, HandlerData::spanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class JaxrsSingletons {
INSTRUMENTATION_NAME,
CodeSpanNameExtractor.create(codeAttributesGetter))
.addAttributesExtractor(CodeAttributesExtractor.create(codeAttributesGetter))
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class JaxrsSingletons {
INSTRUMENTATION_NAME,
CodeSpanNameExtractor.create(codeAttributesGetter))
.addAttributesExtractor(CodeAttributesExtractor.create(codeAttributesGetter))
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Axis2Singletons {
INSTRUMENTER =
Instrumenter.<Axis2Request, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, Axis2Request::spanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CxfSingletons {
INSTRUMENTER =
Instrumenter.<CxfRequest, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, CxfRequest::spanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MetroSingletons {
INSTRUMENTER =
Instrumenter.<MetroRequest, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, MetroRequest::spanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class JaxWsSingletons {
INSTRUMENTATION_NAME,
CodeSpanNameExtractor.create(codeAttributesGetter))
.addAttributesExtractor(CodeAttributesExtractor.create(codeAttributesGetter))
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static Instrumenter<MessageWithDestination, Void> buildConsumerInstrumen
MessagingSpanNameExtractor.create(getter, operation))
.addAttributesExtractor(MessagingAttributesExtractor.create(getter, operation))
.setTimeExtractor(new JmsMessageTimeExtractor())
.setDisabled(!ExperimentalConfig.get().messagingReceiveInstrumentationEnabled())
.setEnabled(ExperimentalConfig.get().messagingReceiveInstrumentationEnabled())
.newInstrumenter(SpanKindExtractor.alwaysConsumer());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MojarraSingletons {
Instrumenter.<JsfRequest, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, JsfRequest::spanName)
.setErrorCauseExtractor(new JsfErrorCauseExtractor())
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MyFacesSingletons {
Instrumenter.<JsfRequest, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, JsfRequest::spanName)
.setErrorCauseExtractor(new MyFacesErrorCauseExtractor())
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static Instrumenter<ReceivedRecords, Void> createConsumerReceiveInstrumen
.addAttributesExtractor(MessagingAttributesExtractor.create(getter, operation))
.addAttributesExtractors(extractors)
.setTimeExtractor(new KafkaConsumerTimeExtractor())
.setDisabled(!ExperimentalConfig.get().messagingReceiveInstrumentationEnabled())
.setEnabled(ExperimentalConfig.get().messagingReceiveInstrumentationEnabled())
.newInstrumenter(SpanKindExtractor.alwaysConsumer());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class WebfluxSingletons {
}

INSTRUMENTER =
builder.setDisabled(ExperimentalConfig.get().suppressControllerSpans()).newInstrumenter();
builder.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled()).newInstrumenter();
}

public static Instrumenter<Object, Void> instrumenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class SpringWebMvcSingletons {
HANDLER_INSTRUMENTER =
Instrumenter.<Object, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, new HandlerSpanNameExtractor())
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();

MODEL_AND_VIEW_INSTRUMENTER =
Expand All @@ -30,7 +30,7 @@ public final class SpringWebMvcSingletons {
INSTRUMENTATION_NAME,
new ModelAndViewSpanNameExtractor())
.addAttributesExtractor(new ModelAndViewAttributesExtractor())
.setDisabled(ExperimentalConfig.get().suppressViewSpans())
.setEnabled(ExperimentalConfig.get().viewTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SpringWsSingletons {
INSTRUMENTATION_NAME,
CodeSpanNameExtractor.create(codeAttributesGetter))
.addAttributesExtractor(CodeAttributesExtractor.create(codeAttributesGetter))
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class StrutsSingletons {
INSTRUMENTATION_NAME,
CodeSpanNameExtractor.create(codeAttributesGetter))
.addAttributesExtractor(CodeAttributesExtractor.create(codeAttributesGetter))
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class TapestrySingletons {
}
return ErrorCauseExtractor.jdk().extractCause(error);
})
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public class VaadinSingletons {
GlobalOpenTelemetry.get(),
INSTRUMENTATION_NAME,
CodeSpanNameExtractor.create(clientCallableAttributesGetter))
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.addAttributesExtractor(CodeAttributesExtractor.create(clientCallableAttributesGetter))
.newInstrumenter();

REQUEST_HANDLER_INSTRUMENTER =
Instrumenter.<VaadinHandlerRequest, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, VaadinHandlerRequest::getSpanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
// add context for tracking nested request handler calls
.addContextCustomizer(
(context, vaadinHandlerRequest, startAttributes) ->
Expand All @@ -53,13 +53,13 @@ public class VaadinSingletons {
RPC_INSTRUMENTER =
Instrumenter.<VaadinRpcRequest, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, VaadinSingletons::rpcSpanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
.newInstrumenter();

SERVICE_INSTRUMENTER =
Instrumenter.<VaadinServiceRequest, Void>builder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, VaadinServiceRequest::getSpanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
// add context for tracking whether any request handler handled the request
.addContextCustomizer(
(context, vaadinServiceRequest, startAttributes) ->
Expand Down

0 comments on commit 39e1fcb

Please sign in to comment.