Skip to content

Commit

Permalink
Option to suppress controller and view spans (#3865)
Browse files Browse the repository at this point in the history
* Add option to suppress controller and view spans

* Apply to all existing Instrumenters

* Introduce ExperimentalConfig

* Singleton?

* No need for lazy
  • Loading branch information
trask committed Aug 25, 2021
1 parent eb1a28c commit 6f22d90
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static Config get() {
if (instance == null) {
// this should only happen in library instrumentation
//
// no need to synchronize because worst case is creating INSTANCE more than once
// no need to synchronize because worst case is creating instance more than once
instance = newBuilder().readEnvironmentVariables().readSystemProperties().build();
}
return instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.api.config;

public final class ExperimentalConfig {

private static final ExperimentalConfig instance = new ExperimentalConfig(Config.get());

private final Config config;

/** Returns the global agent configuration. */
public static ExperimentalConfig get() {
return instance;
}

public ExperimentalConfig(Config config) {
this.config = config;
}

public boolean suppressControllerSpans() {
return config.getBoolean(
"otel.instrumentation.common.experimental.suppress-controller-spans", false);
}

public boolean suppressViewSpans() {
return config.getBoolean("otel.instrumentation.common.experimental.suppress-view-spans", false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public static <REQUEST, RESPONSE> InstrumenterBuilder<REQUEST, RESPONSE> newBuil
private final ErrorCauseExtractor errorCauseExtractor;
@Nullable private final StartTimeExtractor<REQUEST> startTimeExtractor;
@Nullable private final EndTimeExtractor<RESPONSE> endTimeExtractor;
private final boolean disabled;
private final SpanSuppressionStrategy spanSuppressionStrategy;

Instrumenter(InstrumenterBuilder<REQUEST, RESPONSE> builder) {
Expand All @@ -88,6 +89,7 @@ public static <REQUEST, RESPONSE> InstrumenterBuilder<REQUEST, RESPONSE> newBuil
this.errorCauseExtractor = builder.errorCauseExtractor;
this.startTimeExtractor = builder.startTimeExtractor;
this.endTimeExtractor = builder.endTimeExtractor;
this.disabled = builder.disabled;
this.spanSuppressionStrategy = builder.getSpanSuppressionStrategy();
}

Expand All @@ -98,6 +100,9 @@ public static <REQUEST, RESPONSE> InstrumenterBuilder<REQUEST, RESPONSE> newBuil
* without calling those methods.
*/
public boolean shouldStart(Context parentContext, REQUEST request) {
if (disabled) {
return false;
}
SpanKind spanKind = spanKindExtractor.extract(request);
boolean suppressed = spanSuppressionStrategy.shouldSuppress(parentContext, spanKind);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
ErrorCauseExtractor errorCauseExtractor = ErrorCauseExtractor.jdk();
@Nullable StartTimeExtractor<REQUEST> startTimeExtractor = null;
@Nullable EndTimeExtractor<RESPONSE> endTimeExtractor = null;
boolean disabled = false;

private boolean enableSpanSuppressionByType = ENABLE_SPAN_SUPPRESSION_BY_TYPE;

Expand Down Expand Up @@ -135,6 +136,11 @@ public InstrumenterBuilder<REQUEST, RESPONSE> setTimeExtractors(
return this;
}

public InstrumenterBuilder<REQUEST, RESPONSE> setDisabled(boolean disabled) {
this.disabled = disabled;
return this;
}

// visible for tests
/**
* Enables suppression based on client instrumentation type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.dropwizard.views.View;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;

public final class DropwizardSingletons {
Expand All @@ -16,6 +17,7 @@ public final class DropwizardSingletons {
private static final Instrumenter<View, Void> INSTRUMENTER =
Instrumenter.<View, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, DropwizardSingletons::spanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();

private static String spanName(View view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.grails;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;

public final class GrailsSingletons {
Expand All @@ -17,6 +18,7 @@ public final class GrailsSingletons {
INSTRUMENTER =
Instrumenter.<HandlerData, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, HandlerData::spanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.jaxrs.v1_0;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor;
Expand All @@ -32,6 +33,7 @@ public final class JaxrsSingletons {
Instrumenter.<HandlerData, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor)
.addAttributesExtractor(codeAttributesExtractor)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor;
Expand All @@ -32,6 +33,7 @@ public final class JaxrsSingletons {
Instrumenter.<HandlerData, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor)
.addAttributesExtractor(codeAttributesExtractor)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.axis2;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;

public class Axis2Singletons {
Expand All @@ -17,6 +18,7 @@ public class Axis2Singletons {
INSTRUMENTER =
Instrumenter.<Axis2Request, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, Axis2Request::spanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.cxf;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;

public class CxfSingletons {
Expand All @@ -17,6 +18,7 @@ public class CxfSingletons {
INSTRUMENTER =
Instrumenter.<CxfRequest, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, CxfRequest::spanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.metro;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;

public class MetroSingletons {
Expand All @@ -17,6 +18,7 @@ public class MetroSingletons {
INSTRUMENTER =
Instrumenter.<MetroRequest, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, MetroRequest::spanName)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.jaxws.common;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor;
Expand All @@ -24,6 +25,7 @@ public class JaxWsSingletons {
Instrumenter.<JaxWsRequest, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, JaxWsRequest::spanName)
.addAttributesExtractor(codeAttributes)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.mojarra;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.jsf.JsfErrorCauseExtractor;
import io.opentelemetry.instrumentation.jsf.JsfRequest;
Expand All @@ -20,6 +21,7 @@ public class MojarraSingletons {
Instrumenter.<JsfRequest, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, JsfRequest::spanName)
.setErrorCauseExtractor(new JsfErrorCauseExtractor())
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.myfaces;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.jsf.JsfRequest;

Expand All @@ -19,6 +20,7 @@ public class MyFacesSingletons {
Instrumenter.<JsfRequest, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, JsfRequest::spanName)
.setErrorCauseExtractor(new MyFacesErrorCauseExtractor())
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.spring.webflux.server;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
import io.opentelemetry.javaagent.instrumentation.spring.webflux.SpringWebfluxConfig;
Expand All @@ -24,7 +25,8 @@ public final class WebfluxSingletons {
builder.addAttributesExtractor(new ExperimentalAttributesExtractor());
}

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

public static Instrumenter<Object, Void> instrumenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.springwebmvc;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import org.springframework.web.servlet.ModelAndView;

Expand All @@ -20,6 +21,7 @@ public final class SpringWebMvcSingletons {
HANDLER_INSTRUMENTER =
Instrumenter.<Object, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, new HandlerSpanNameExtractor())
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.spring.ws;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeSpanNameExtractor;
Expand All @@ -24,6 +25,7 @@ public class SpringWsSingletons {
INSTRUMENTATION_NAME,
CodeSpanNameExtractor.create(codeAttributes))
.addAttributesExtractor(codeAttributes)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.opensymphony.xwork2.ActionInvocation;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeSpanNameExtractor;
Expand All @@ -25,6 +26,7 @@ public class StrutsSingletons {
INSTRUMENTATION_NAME,
CodeSpanNameExtractor.create(codeAttributes))
.addAttributesExtractor(codeAttributes)
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.tapestry;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
import io.opentelemetry.instrumentation.api.instrumenter.ErrorCauseExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import org.apache.tapestry5.runtime.ComponentEventException;
Expand All @@ -26,6 +27,7 @@ public class TapestrySingletons {
}
return ErrorCauseExtractor.jdk().extractCause(error);
})
.setDisabled(ExperimentalConfig.get().suppressControllerSpans())
.newInstrumenter();
}

Expand Down

0 comments on commit 6f22d90

Please sign in to comment.