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
merged 9 commits into from
Aug 25, 2021
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 @@ -56,6 +56,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 @@ -136,6 +137,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,21 @@

import io.dropwizard.views.View;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.Config;
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 =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);
Copy link
Contributor

@anuraaga anuraaga Aug 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should somehow have this in the javaagent-api artifact rather than copying into every module I guess. Either a method on Config or something like JavaAgentConfig with all of them exposed rather than using the flags directly.


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,17 +6,23 @@
package io.opentelemetry.javaagent.instrumentation.grails;

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

public final class GrailsSingletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.grails-3.0";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);

private static final Instrumenter<HandlerData, Void> INSTRUMENTER;

static {
INSTRUMENTER =
Instrumenter.<HandlerData, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, HandlerData::spanName)
.setDisabled(SUPPRESS_CONTROLLER_SPANS)
.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.Config;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor;
Expand All @@ -20,6 +21,10 @@ public final class JaxrsSingletons {

private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jaxrs-1.0-common";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);

private static final Instrumenter<HandlerData, Void> INSTRUMENTER;

static {
Expand All @@ -32,6 +37,7 @@ public final class JaxrsSingletons {
Instrumenter.<HandlerData, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor)
.addAttributesExtractor(codeAttributesExtractor)
.setDisabled(SUPPRESS_CONTROLLER_SPANS)
.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.Config;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor;
Expand All @@ -20,6 +21,10 @@ public final class JaxrsSingletons {

private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jaxrs-2.0-common";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);

private static final Instrumenter<HandlerData, Void> INSTRUMENTER;

static {
Expand All @@ -32,6 +37,7 @@ public final class JaxrsSingletons {
Instrumenter.<HandlerData, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor)
.addAttributesExtractor(codeAttributesExtractor)
.setDisabled(SUPPRESS_CONTROLLER_SPANS)
.newInstrumenter();
}

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

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

public class Axis2Singletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jaxws-2.0-axis2-1.6";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);

private static final Instrumenter<Axis2Request, Void> INSTRUMENTER;

static {
INSTRUMENTER =
Instrumenter.<Axis2Request, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, Axis2Request::spanName)
.setDisabled(SUPPRESS_CONTROLLER_SPANS)
.newInstrumenter();
}

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

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

public class CxfSingletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jaxws-2.0-cxf-3.0";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);

private static final Instrumenter<CxfRequest, Void> INSTRUMENTER;

static {
INSTRUMENTER =
Instrumenter.<CxfRequest, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, CxfRequest::spanName)
.setDisabled(SUPPRESS_CONTROLLER_SPANS)
.newInstrumenter();
}

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

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

public class MetroSingletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jaxws-2.0-metro-2.2";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);

private static final Instrumenter<MetroRequest, Void> INSTRUMENTER;

static {
INSTRUMENTER =
Instrumenter.<MetroRequest, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, MetroRequest::spanName)
.setDisabled(SUPPRESS_CONTROLLER_SPANS)
.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.Config;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor;
Expand All @@ -14,6 +15,10 @@
public class JaxWsSingletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jaxws-common";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);

private static final Instrumenter<JaxWsRequest, Void> INSTRUMENTER;
private static final SpanNameExtractor<JaxWsRequest> SPAN_NAME_EXTRACTOR;

Expand All @@ -24,6 +29,7 @@ public class JaxWsSingletons {
Instrumenter.<JaxWsRequest, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, JaxWsRequest::spanName)
.addAttributesExtractor(codeAttributes)
.setDisabled(SUPPRESS_CONTROLLER_SPANS)
.newInstrumenter();
}

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

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

public class MojarraSingletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.mojarra-1.2";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);

private static final Instrumenter<JsfRequest, Void> INSTRUMENTER;

static {
INSTRUMENTER =
Instrumenter.<JsfRequest, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, JsfRequest::spanName)
.setErrorCauseExtractor(new JsfErrorCauseExtractor())
.setDisabled(SUPPRESS_CONTROLLER_SPANS)
.newInstrumenter();
}

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

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

public class MyFacesSingletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.myfaces-1.2";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);

private static final Instrumenter<JsfRequest, Void> INSTRUMENTER;

static {
INSTRUMENTER =
Instrumenter.<JsfRequest, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, JsfRequest::spanName)
.setErrorCauseExtractor(new MyFacesErrorCauseExtractor())
.setDisabled(SUPPRESS_CONTROLLER_SPANS)
.newInstrumenter();
}

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

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
import io.opentelemetry.javaagent.instrumentation.spring.webflux.SpringWebfluxConfig;

public final class WebfluxSingletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-webflux-5.0";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);

private static final Instrumenter<Object, Void> INSTRUMENTER;

static {
Expand All @@ -24,7 +29,7 @@ public final class WebfluxSingletons {
builder.addAttributesExtractor(new ExperimentalAttributesExtractor());
}

INSTRUMENTER = builder.newInstrumenter();
INSTRUMENTER = builder.setDisabled(SUPPRESS_CONTROLLER_SPANS).newInstrumenter();
}

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

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

public final class SpringWebMvcSingletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-webmvc-3.1";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);

private static final boolean SUPPRESS_VIEW_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-view-spans", false);

private static final Instrumenter<Object, Void> HANDLER_INSTRUMENTER;

private static final Instrumenter<ModelAndView, Void> MODEL_AND_VIEW_INSTRUMENTER;
Expand All @@ -20,6 +29,7 @@ public final class SpringWebMvcSingletons {
HANDLER_INSTRUMENTER =
Instrumenter.<Object, Void>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, new HandlerSpanNameExtractor())
.setDisabled(SUPPRESS_CONTROLLER_SPANS)
.newInstrumenter();

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

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

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeSpanNameExtractor;

public class SpringWsSingletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-ws-2.0";

private static final boolean SUPPRESS_CONTROLLER_SPANS =
Config.get()
.getBoolean("otel.instrumentation.common.experimental.suppress-controller-spans", false);

private static final Instrumenter<SpringWsRequest, Void> INSTRUMENTER;

static {
Expand All @@ -24,6 +29,7 @@ public class SpringWsSingletons {
INSTRUMENTATION_NAME,
CodeSpanNameExtractor.create(codeAttributes))
.addAttributesExtractor(codeAttributes)
.setDisabled(SUPPRESS_CONTROLLER_SPANS)
.newInstrumenter();
}

Expand Down
Loading