Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d572c69
add system properties bridge
zeitlinger Nov 17, 2025
2770d86
add system properties bridge
zeitlinger Nov 17, 2025
5a3c8dd
add tests
zeitlinger Nov 17, 2025
e29c7bb
add list
zeitlinger Nov 18, 2025
0626c95
refactor
zeitlinger Nov 18, 2025
efaef9f
refactor
zeitlinger Nov 18, 2025
bd9a69f
string
zeitlinger Nov 18, 2025
07cc6fa
string
zeitlinger Nov 18, 2025
7a64c91
string
zeitlinger Nov 18, 2025
cf01131
string
zeitlinger Nov 18, 2025
e3a1e60
string
zeitlinger Nov 18, 2025
8b22e17
string
zeitlinger Nov 18, 2025
73ec70c
string
zeitlinger Nov 18, 2025
f9f3df8
string
zeitlinger Nov 18, 2025
93f173f
javadoc
zeitlinger Nov 18, 2025
76b4683
add contract
zeitlinger Nov 18, 2025
cb3931b
add contract
zeitlinger Nov 18, 2025
f2fd6c4
remove contract
zeitlinger Nov 18, 2025
e7558dc
remove contract
zeitlinger Nov 18, 2025
1ee4e6d
inline method to avoid class not found exception for DeclarativeConfi…
zeitlinger Nov 18, 2025
8329a1e
pr review
zeitlinger Nov 25, 2025
aebd419
use optional instead of providing default for boolean
zeitlinger Nov 25, 2025
0bd5b32
use optional instead of providing default for int
zeitlinger Nov 25, 2025
65c7f44
use optional instead of providing default for list
zeitlinger Nov 25, 2025
eae795e
use optional instead of providing default for string
zeitlinger Nov 25, 2025
80e8567
fix
zeitlinger Nov 25, 2025
7e1f313
fix
zeitlinger Nov 25, 2025
7acb8d2
fix
zeitlinger Nov 25, 2025
77741fa
split pr
zeitlinger Nov 27, 2025
f3a6303
split pr
zeitlinger Nov 27, 2025
6b9fe65
fix
zeitlinger Nov 27, 2025
d4e6219
fix
zeitlinger Nov 27, 2025
165a99b
pr review
zeitlinger Dec 3, 2025
28c9472
revert aws test
zeitlinger Dec 3, 2025
5d845ac
use "/development" instead of "experimental" in declarative config
zeitlinger Dec 3, 2025
75a4c5f
use "/development" instead of "experimental" in declarative config
zeitlinger Dec 3, 2025
c6e8b7c
fix
zeitlinger Dec 3, 2025
7d33506
docs
zeitlinger Dec 3, 2025
b9695fc
avoid double bridge
zeitlinger Dec 4, 2025
dd9657d
normalize system props before lookup to avoid ambiguity of "experimen…
zeitlinger Dec 4, 2025
a390973
normalize system props before lookup to avoid ambiguity of "experimen…
zeitlinger Dec 4, 2025
a399bb8
normalize system props before lookup to avoid ambiguity of "experimen…
zeitlinger Dec 5, 2025
9c42e5a
normalize system props before lookup to avoid ambiguity of "experimen…
zeitlinger Dec 5, 2025
ee4d8ac
rename js snippet property
zeitlinger Dec 5, 2025
dbda350
normalize system props before lookup to avoid ambiguity of "experimen…
zeitlinger Dec 5, 2025
7bbf141
add changelog
zeitlinger Dec 7, 2025
e3fa175
format
zeitlinger Dec 7, 2025
ff31147
remove param that is always false
zeitlinger Dec 11, 2025
5dff2c2
remove performance optimization
zeitlinger Dec 11, 2025
753419e
remove performance optimization
zeitlinger Dec 11, 2025
708ff2a
avoid lambda in early phase
zeitlinger Dec 11, 2025
533555d
deprecated fallback
trask Dec 11, 2025
a6abcb6
cleanup
zeitlinger Dec 12, 2025
c5bfe9c
fix experimental in the middle
zeitlinger Dec 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

### ⚠️ Breaking Changes

- Rename `otel.experimental.javascript-snippet` to
`otel.instrumentation.servlet.experimental.javascript-snippet` to follow naming conventions
([#15339](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/15339))

### ⚠️ Breaking Changes

- ActiveMQ Classic JMX metrics: rename attributes and metrics to align
with semantic conventions (see PR description for specifics)
([#14996](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/14996))
Expand Down
6 changes: 3 additions & 3 deletions docs/advanced-configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ This feature is designed for integrating client-side monitoring.
We plan to integrate OpenTelemetry's own client-side monitoring solution by default once it's available
(see the [browser instrumentation proposal](https://github.com/open-telemetry/community/blob/main/projects/browser-phase-1.md)).

| System property | Environment variable | Purpose |
|--------------------------------------|--------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| otel.experimental.javascript-snippet | OTEL_EXPERIMENTAL_JAVASCRIPT_SNIPPET | Experimental setting to inject a JavaScript snippet into HTML responses after the opening `<head>` tag. The value should be a complete JavaScript snippet including `<script>` tags if needed, e.g. `-Dotel.experimental.javascript-snippet="<script>console.log('Hello world!');</script>"` |
| System property | Environment variable | Purpose |
|----------------------------------------------------------------|----------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `otel.instrumentation.servlet.experimental.javascript-snippet` | `OTEL_INSTRUMENTATION_SERVLET_EXPERIMENTAL_JAVASCRIPT_SNIPPET` | Experimental setting to inject a JavaScript snippet into HTML responses after the opening `<head>` tag. The value should be a complete JavaScript snippet including `<script>` tags if needed, e.g. `-Dotel.instrumentation.servlet.experimental.javascript-snippet="<script>console.log('Hello world!');</script>"` |

**Important notes:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ default List<String> getList(String name) {
/**
* Returns the {@link ConfigProvider} if declarative configuration is used.
*
* @return the {@link ConfigProvider} or {@code null} if no provider is available
* @return the {@link ConfigProvider} or {@code null} if declarative configuration is not used
*/
@Nullable
ConfigProvider getConfigProvider();
Expand Down
1 change: 1 addition & 0 deletions instrumentation-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
testImplementation("io.opentelemetry.javaagent:opentelemetry-testing-common")
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
testImplementation("io.opentelemetry:opentelemetry-exporter-common")
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-incubator")
testImplementation("org.junit-pioneer:junit-pioneer")

jmhImplementation(project(":instrumentation-api-incubator"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {

private static final Logger logger = Logger.getLogger(InstrumenterBuilder.class.getName());

private static final SpanSuppressionStrategy spanSuppressionStrategy =
SpanSuppressionStrategy.fromConfig(
ConfigPropertiesUtil.getString(
"otel.instrumentation.experimental.span-suppression-strategy"));

final OpenTelemetry openTelemetry;
final String instrumentationName;
SpanNameExtractor<? super REQUEST> spanNameExtractor;
Expand Down Expand Up @@ -373,8 +368,17 @@ private String getSchemaUrl() {
}

SpanSuppressor buildSpanSuppressor() {
// otel.instrumentation.experimental.* doesn't fit the usual pattern of configuration properties
// for instrumentations, so we need to handle both declarative and non-declarative configs here
String value =
ConfigPropertiesUtil.isDeclarativeConfig(openTelemetry)
? ConfigPropertiesUtil.getString(
openTelemetry, "common", "span_suppression_strategy/development")
.orElse(null)
: ConfigPropertiesUtil.getString(
"otel.instrumentation.experimental.span-suppression-strategy");
return new SpanSuppressors.ByContextKey(
spanSuppressionStrategy.create(getSpanKeysFromAttributesExtractors()));
SpanSuppressionStrategy.fromConfig(value).create(getSpanKeysFromAttributesExtractors()));
}

private Set<SpanKey> getSpanKeysFromAttributesExtractors() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@

package io.opentelemetry.instrumentation.api.internal;

import static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties.empty;
import static java.util.Collections.emptyList;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.incubator.ExtendedOpenTelemetry;
import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

Expand All @@ -17,11 +24,51 @@
*/
public final class ConfigPropertiesUtil {

private static final boolean supportsDeclarativeConfig = supportsDeclarativeConfig();

private static boolean supportsDeclarativeConfig() {
try {
Class.forName("io.opentelemetry.api.incubator.ExtendedOpenTelemetry");
return true;
} catch (ClassNotFoundException e) {
// The incubator module is not available.
// This only happens in OpenTelemetry API instrumentation tests, where an older version of
// OpenTelemetry API is used that does not have ExtendedOpenTelemetry.
// Having the incubator module without ExtendedOpenTelemetry class should still return false
// for those tests to avoid a ClassNotFoundException.
return false;
}
}

/**
* Returns the boolean value of the given property name from system properties and environment
* variables.
*
* <p>It's recommended to use {@link #getBoolean(OpenTelemetry, String...)} instead to support
* Declarative Config.
*/
public static boolean getBoolean(String propertyName, boolean defaultValue) {
String strValue = getString(propertyName);
return strValue == null ? defaultValue : Boolean.parseBoolean(strValue);
}

/**
* Returns the boolean value of the given property name from Declarative Config if available,
* otherwise falls back to system properties and environment variables.
*/
public static Optional<Boolean> getBoolean(OpenTelemetry openTelemetry, String... propertyName) {
DeclarativeConfigProperties node = getDeclarativeConfigNode(openTelemetry, propertyName);
if (node != null) {
return Optional.ofNullable(node.getBoolean(leaf(propertyName)));
}
String strValue = getString(toSystemProperty(propertyName));
return strValue == null ? Optional.empty() : Optional.of(Boolean.parseBoolean(strValue));
}

/**
* Returns the int value of the given property name from system properties and environment
* variables.
*/
public static int getInt(String propertyName, int defaultValue) {
String strValue = getString(propertyName);
if (strValue == null) {
Expand All @@ -34,26 +81,47 @@ public static int getInt(String propertyName, int defaultValue) {
}
}

/**
* Returns the string value of the given property name from system properties and environment
* variables.
*
* <p>It's recommended to use {@link #getString(OpenTelemetry, String...)} instead to support
* Declarative Config.
*/
@Nullable
public static String getString(String propertyName) {
String value = System.getProperty(propertyName);
if (value != null) {
return value;
}
return System.getenv(toEnvVarName(propertyName));
return ConfigUtil.getString(ConfigUtil.normalizePropertyKey(propertyName));
}

public static String getString(String propertyName, String defaultValue) {
String strValue = getString(propertyName);
return strValue == null ? defaultValue : strValue;
/**
* Returns the string value of the given property name from Declarative Config if available,
* otherwise falls back to system properties and environment variables.
*/
public static Optional<String> getString(OpenTelemetry openTelemetry, String... propertyName) {
DeclarativeConfigProperties node = getDeclarativeConfigNode(openTelemetry, propertyName);
if (node != null) {
return Optional.ofNullable(node.getString(leaf(propertyName)));
}
return Optional.ofNullable(getString(toSystemProperty(propertyName)));
}

public static List<String> getList(String propertyName, List<String> defaultValue) {
String value = getString(propertyName);
if (value == null) {
return defaultValue;
/**
* Returns the list of strings value of the given property name from Declarative Config if
* available, otherwise falls back to system properties and environment variables.
*/
public static List<String> getList(OpenTelemetry openTelemetry, String... propertyName) {
DeclarativeConfigProperties node = getDeclarativeConfigNode(openTelemetry, propertyName);
if (node != null) {
return node.getScalarList(leaf(propertyName), String.class, emptyList());
}
return filterBlanksAndNulls(value.split(","));
return Optional.ofNullable(getString(toSystemProperty(propertyName)))
.map(value -> filterBlanksAndNulls(value.split(",")))
.orElse(emptyList());
}

/** Returns true if the given OpenTelemetry instance supports Declarative Config. */
public static boolean isDeclarativeConfig(OpenTelemetry openTelemetry) {
return supportsDeclarativeConfig && openTelemetry instanceof ExtendedOpenTelemetry;
}

private static List<String> filterBlanksAndNulls(String[] values) {
Expand All @@ -63,8 +131,45 @@ private static List<String> filterBlanksAndNulls(String[] values) {
.collect(Collectors.toList());
}

private static String toEnvVarName(String propertyName) {
return propertyName.toUpperCase(Locale.ROOT).replace('-', '_').replace('.', '_');
private static String leaf(String[] propertyName) {
return propertyName[propertyName.length - 1];
}

@Nullable
private static DeclarativeConfigProperties getDeclarativeConfigNode(
OpenTelemetry openTelemetry, String... propertyName) {
if (isDeclarativeConfig(openTelemetry)) {
ExtendedOpenTelemetry extendedOpenTelemetry = (ExtendedOpenTelemetry) openTelemetry;
ConfigProvider configProvider = extendedOpenTelemetry.getConfigProvider();
return getConfigProperties(configProvider, propertyName);
}
return null;
}

/** Returns the DeclarativeConfigProperties node for the given property name parts. */
public static DeclarativeConfigProperties getConfigProperties(
ConfigProvider configProvider, String[] propertyName) {
DeclarativeConfigProperties instrumentationConfig = configProvider.getInstrumentationConfig();
if (instrumentationConfig == null) {
return empty();
}
DeclarativeConfigProperties node = instrumentationConfig.getStructured("java", empty());
// last part is the leaf property
for (int i = 0; i < propertyName.length - 1; i++) {
node = node.getStructured(propertyName[i], empty());
}
return node;
}

public static String toSystemProperty(String[] propertyName) {
for (int i = 0; i < propertyName.length; i++) {
String node = propertyName[i];
if (node.endsWith("/development")) {
String prefix = node.contains("experimental") ? "" : "experimental.";
propertyName[i] = prefix + node.substring(0, node.length() - 12);
}
}
return "otel.instrumentation." + String.join(".", propertyName).replace('_', '-');
}

private ConfigPropertiesUtil() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.api.internal;

import java.util.ConcurrentModificationException;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import javax.annotation.Nullable;

/**
* Configuration utilities.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*
* <p>Copied from <a
* href="https://github.com/open-telemetry/opentelemetry-java/blob/main/api/all/src/main/java/io/opentelemetry/api/internal/ConfigUtil.java">SDK</a>
* because some tests target an SDK version where this class does not exist.
*/
final class ConfigUtil {

private ConfigUtil() {}

/**
* Returns a copy of system properties which is safe to iterate over.
*
* <p>In java 8 and android environments, iterating through system properties may trigger {@link
* ConcurrentModificationException}. This method ensures callers can iterate safely without risk
* of exception. See https://github.com/open-telemetry/opentelemetry-java/issues/6732 for details.
*/
public static Properties safeSystemProperties() {
return (Properties) System.getProperties().clone();
}

/**
* Return the system property or environment variable for the {@code key}.
*
* <p>Normalize the {@code key} using {@link #normalizePropertyKey(String)}. Match to system
* property keys also normalized with {@link #normalizePropertyKey(String)}. Match to environment
* variable keys normalized with {@link #normalizeEnvironmentVariableKey(String)}. System
* properties take priority over environment variables.
*
* @param key the property key
* @return the system property if not null, or the environment variable if not null, or {@code
* null}
*/
@Nullable
public static String getString(String key) {
String normalizedKey = normalizePropertyKey(key);

for (Map.Entry<Object, Object> entry : safeSystemProperties().entrySet()) {
if (normalizedKey.equals(normalizePropertyKey(entry.getKey().toString()))) {
return entry.getValue().toString();
}
}

for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
if (normalizedKey.equals(normalizeEnvironmentVariableKey(entry.getKey()))) {
return entry.getValue();
}
}

return null;
}

/**
* Normalize an environment variable key by converting to lower case and replacing "_" with ".".
*/
public static String normalizeEnvironmentVariableKey(String key) {
return key.toLowerCase(Locale.ROOT).replace("_", ".");
}

/** Normalize a property key by converting to lower case and replacing "-" with ".". */
public static String normalizePropertyKey(String key) {
return key.toLowerCase(Locale.ROOT).replace("-", ".");
}
}
Loading
Loading