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

Option to suppress controller and view spans #3865

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.api.config;

public final class ExperimentalConfig {

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

public static boolean suppressViewSpans() {
return Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-view-spans", false);
}

private ExperimentalConfig() {}
}
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,15 +7,20 @@

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 {

private static final String INSTRUMENTATION_NAME = "io.opentelemetry.dropwizard-views-0.7";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
ExperimentalConfig.suppressControllerSpans();

private static final Instrumenter<View, Void> INSTRUMENTER =
Instrumenter.<View, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, DropwizardSingletons::spanName)
.setDisabled(SUPPRESS_CONTROLLER_SPANS)
.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.suppressControllerSpans())
.newInstrumenter();
}

Expand Down