Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ endif::[]
[[release-notes-1.27.1]]
==== 1.27.1 - YYYY/MM/DD

[float]
===== Features
* Added support to selectively enable instrumentations - {pull}2292[#2292]

[float]
===== Bug fixes
* Fixing missing Micrometer metrics in Spring boot due to premature initialization - {pull}2255[#2255]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,21 @@ private static boolean isIncluded(ElasticApmInstrumentation advice, CoreConfigur
if (disabledInstrumentations.contains("incubating")) {
disabledInstrumentations.add("experimental");
}
return !isGroupDisabled(disabledInstrumentations, advice.getInstrumentationGroupNames()) && isInstrumentationEnabled(advice, coreConfiguration);
return isGroupEnabled(coreConfiguration.getEnabledInstrumentations(), advice.getInstrumentationGroupNames()) &&
!isGroupDisabled(disabledInstrumentations, advice.getInstrumentationGroupNames()) &&
isInstrumentationEnabled(advice, coreConfiguration);
}

private static boolean isGroupEnabled(Collection<String> enabledInstrumentations, Collection<String> instrumentationGroupNames) {
if (enabledInstrumentations.isEmpty()) {
return true;
}
for (String instrumentationGroupName : instrumentationGroupNames) {
if (enabledInstrumentations.contains(instrumentationGroupName)) {
return true;
}
}
return false;
}

private static boolean isGroupDisabled(Collection<String> disabledInstrumentations, Collection<String> instrumentationGroupNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,19 @@ public class CoreConfiguration extends ConfigurationOptionProvider {
WildcardMatcher.valueOf("set-cookie")
));

private final ConfigurationOption<Collection<String>> enabledInstrumentations = ConfigurationOption.stringsOption()
.key("enable_instrumentations")
.aliasKeys("enabled_instrumentations")
.configurationCategory(CORE_CATEGORY)
.description("A list of instrumentations which should be enabled.\n" +
"Valid options are ${allInstrumentationGroupNames}.\n" +
"An instrumentation is enabled if this configuration is empty or contains the instrumentation and the instrumentation is not disabled.\n" +
"\n" +
"NOTE: Changing this value at runtime can slow down the application temporarily.")
.dynamic(true)
.tags("added[1.28.0]")
.buildWithDefault(Collections.<String>emptyList());

private final ConfigurationOption<Collection<String>> disabledInstrumentations = ConfigurationOption.stringsOption()
.key("disable_instrumentations")
.aliasKeys("disabled_instrumentations")
Expand Down Expand Up @@ -635,7 +648,7 @@ public boolean isInstrument() {
}

public List<ConfigurationOption<?>> getInstrumentationOptions() {
return Arrays.asList(instrument, traceMethods, disabledInstrumentations, enableExperimentalInstrumentations);
return Arrays.asList(instrument, traceMethods, enabledInstrumentations, disabledInstrumentations, enableExperimentalInstrumentations);
}

public String getServiceName() {
Expand Down Expand Up @@ -686,6 +699,10 @@ public List<WildcardMatcher> getSanitizeFieldNames() {
return sanitizeFieldNames.get();
}

public Collection<String> getEnabledInstrumentations() {
return enabledInstrumentations.get();
}

public Collection<String> getDisabledInstrumentations() {
List<String> disabled = new ArrayList<>(disabledInstrumentations.get());
if (enableExperimentalInstrumentations.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public static <REQUEST, RESPONSE, HTTPREQUEST, HTTPRESPONSE, CONTEXT> Object onS

ret = transaction;
} else if (!helper.isAsyncDispatcherType(servletRequest) &&
(coreConfig.getEnabledInstrumentations().isEmpty() || coreConfig.getEnabledInstrumentations().contains(Constants.SERVLET_API_DISPATCH)) &&
!coreConfig.getDisabledInstrumentations().contains(Constants.SERVLET_API_DISPATCH)) {
final AbstractSpan<?> parent = tracer.getActive();
if (parent != null) {
Expand Down
40 changes: 40 additions & 0 deletions docs/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Click on a key to get more information.
** <<config-transaction-sample-rate>>
** <<config-transaction-max-spans>>
** <<config-sanitize-field-names>>
** <<config-enable-instrumentations>>
** <<config-disable-instrumentations>>
** <<config-enable-experimental-instrumentations>>
** <<config-unnest-exceptions>>
Expand Down Expand Up @@ -707,6 +708,33 @@ you should add an additional entry to this list (make sure to also include the d
| `elastic.apm.sanitize_field_names` | `sanitize_field_names` | `ELASTIC_APM_SANITIZE_FIELD_NAMES`
|============

// This file is auto generated. Please make your changes in *Configuration.java (for example CoreConfiguration.java) and execute ConfigurationExporter
[float]
[[config-enable-instrumentations]]
==== `enable_instrumentations` (added[1.28.0])

A list of instrumentations which should be enabled.
Valid options are `annotations`, `apache-commons-exec`, `apache-httpclient`, `asynchttpclient`, `cassandra`, `concurrent`, `dubbo`, `elasticsearch-restclient`, `exception-handler`, `executor`, `executor-collection`, `experimental`, `fork-join`, `grails`, `grpc`, `hibernate-search`, `http-client`, `javalin`, `jax-rs`, `jax-ws`, `jdbc`, `jdk-httpclient`, `jdk-httpserver`, `jedis`, `jms`, `jsf`, `kafka`, `lettuce`, `log4j1-ecs`, `log4j2-ecs`, `log4j2-error`, `logback-ecs`, `logging`, `micrometer`, `mongodb-client`, `okhttp`, `opentracing`, `process`, `public-api`, `quartz`, `rabbitmq`, `reactor`, `redis`, `redisson`, `render`, `scala-future`, `scheduled`, `servlet-api`, `servlet-api-async`, `servlet-api-dispatch`, `servlet-input-stream`, `slf4j-error`, `sparkjava`, `spring-amqp`, `spring-mvc`, `spring-resttemplate`, `spring-service-name`, `spring-view-render`, `spring-webflux`, `ssl-context`, `struts`, `timer-task`, `urlconnection`, `vertx`, `vertx-web`, `vertx-webclient`.
An instrumentation is enabled if this configuration is empty or contains the instrumentation and the instrumentation is not disabled.

NOTE: Changing this value at runtime can slow down the application temporarily.

<<configuration-dynamic, image:./images/dynamic-config.svg[] >>


[options="header"]
|============
| Default | Type | Dynamic
| `<none>` | Collection | true
|============


[options="header"]
|============
| Java System Properties | Property file | Environment
| `elastic.apm.enable_instrumentations` | `enable_instrumentations` | `ELASTIC_APM_ENABLE_INSTRUMENTATIONS`
|============

// This file is auto generated. Please make your changes in *Configuration.java (for example CoreConfiguration.java) and execute ConfigurationExporter
[float]
[[config-disable-instrumentations]]
Expand Down Expand Up @@ -2912,6 +2940,18 @@ The default unit for this option is `ms`.
#
# sanitize_field_names=password,passwd,pwd,secret,*key,*token*,*session*,*credit*,*card*,authorization,set-cookie

# A list of instrumentations which should be enabled.
# Valid options are `annotations`, `apache-commons-exec`, `apache-httpclient`, `asynchttpclient`, `cassandra`, `concurrent`, `dubbo`, `elasticsearch-restclient`, `exception-handler`, `executor`, `executor-collection`, `experimental`, `fork-join`, `grails`, `grpc`, `hibernate-search`, `http-client`, `javalin`, `jax-rs`, `jax-ws`, `jdbc`, `jdk-httpclient`, `jdk-httpserver`, `jedis`, `jms`, `jsf`, `kafka`, `lettuce`, `log4j1-ecs`, `log4j2-ecs`, `log4j2-error`, `logback-ecs`, `logging`, `micrometer`, `mongodb-client`, `okhttp`, `opentracing`, `process`, `public-api`, `quartz`, `rabbitmq`, `reactor`, `redis`, `redisson`, `render`, `scala-future`, `scheduled`, `servlet-api`, `servlet-api-async`, `servlet-api-dispatch`, `servlet-input-stream`, `slf4j-error`, `sparkjava`, `spring-amqp`, `spring-mvc`, `spring-resttemplate`, `spring-service-name`, `spring-view-render`, `spring-webflux`, `ssl-context`, `struts`, `timer-task`, `urlconnection`, `vertx`, `vertx-web`, `vertx-webclient`.
# An instrumentation is enabled if this configuration is empty or contains the instrumentation and the instrumentation is not disabled.
#
# NOTE: Changing this value at runtime can slow down the application temporarily.
#
# This setting can be changed at runtime
# Type: comma separated list
# Default value:
#
# enable_instrumentations=

# A list of instrumentations which should be disabled.
# Valid options are `annotations`, `apache-commons-exec`, `apache-httpclient`, `asynchttpclient`, `cassandra`, `concurrent`, `dubbo`, `elasticsearch-restclient`, `exception-handler`, `executor`, `executor-collection`, `experimental`, `fork-join`, `grails`, `grpc`, `hibernate-search`, `http-client`, `javalin`, `jax-rs`, `jax-ws`, `jdbc`, `jdk-httpclient`, `jdk-httpserver`, `jedis`, `jms`, `jsf`, `kafka`, `lettuce`, `log4j1-ecs`, `log4j2-ecs`, `log4j2-error`, `logback-ecs`, `logging`, `micrometer`, `mongodb-client`, `okhttp`, `opentracing`, `process`, `public-api`, `quartz`, `rabbitmq`, `reactor`, `redis`, `redisson`, `render`, `scala-future`, `scheduled`, `servlet-api`, `servlet-api-async`, `servlet-api-dispatch`, `servlet-input-stream`, `slf4j-error`, `sparkjava`, `spring-amqp`, `spring-mvc`, `spring-resttemplate`, `spring-service-name`, `spring-view-render`, `spring-webflux`, `ssl-context`, `struts`, `timer-task`, `urlconnection`, `vertx`, `vertx-web`, `vertx-webclient`.
# For version `1.25.0` and later, use <<config-enable-experimental-instrumentations>> to enable experimental instrumentations.
Expand Down