Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ private static String translatePath(String path) {
return result.toString();
}

private static String translateName(String name) {
static String translateName(String name) {
if (name.endsWith("/development")) {
return "experimental."
+ name.substring(0, name.length() - "/development".length()).replace('_', '-');
String prefix = name.contains("experimental") ? "" : "experimental.";
return prefix + name.substring(0, name.length() - "/development".length()).replace('_', '-');
}
return name.replace('_', '-');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.config.bridge;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

class ConfigPropertiesBackedDeclarativeConfigPropertiesTest {

@ParameterizedTest
@MethodSource("translateNameTestCases")
void translateName(String input, String expected) {
assertThat(ConfigPropertiesBackedDeclarativeConfigProperties.translateName(input))
.isEqualTo(expected);
}

private static Stream<Arguments> translateNameTestCases() {
return Stream.of(
// Simple name with underscores
Arguments.of("simple_name", "simple-name"),
// Name with multiple underscores
Arguments.of("multiple_under_scores", "multiple-under-scores"),
// Name without underscores
Arguments.of("no-underscores", "no-underscores"),
// Name ending with /development without experimental
Arguments.of("some_name/development", "experimental.some-name"),
// Name ending with /development already containing experimental
Arguments.of("experimental_some_name/development", "experimental-some-name"),
// Name with underscores and hyphens ending with /development
Arguments.of("my_test_name/development", "experimental.my-test-name"),
// Name with experimental in middle ending with /development
Arguments.of("prefix_experimental_suffix/development", "prefix-experimental-suffix"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ instrumentation/development:
java:
http:
client:
emit_experimental_telemetry: true
emit_experimental_telemetry/development: true
url_template_rules:
- pattern: "http://localhost:.*/hello/.*"
template: "/hello/*"
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,16 @@ default List<String> getList(String name) {
*/
Map<String, String> getMap(String name, Map<String, String> defaultValue);

/** Returns {@code true} if declarative configuration is used in this configuration. */
boolean isDeclarative();

/**
* Returns a {@link DeclarativeConfigProperties} for the given node name, which is usually an
* instrumentation name
*
* <p>Call {@link #isDeclarative()} first to check if declarative configuration is used.
*
* <p>Declarative configuration is used to configure instrumentation properties in a declarative
* way, such as through YAML or JSON files.
*
* @param node the name of the instrumentation (e.g. "log4j"), the vendor name (e.g. "google"), or
* "common" for common Java settings that don't apply to other languages.
* @return the declarative configuration properties for the given node name
* @throws IllegalStateException if {@link #isDeclarative()} returns {@code false}
*/
DeclarativeConfigProperties getDeclarativeConfig(String node);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ public Map<String, String> getMap(String name, Map<String, String> defaultValue)
}
}

@Override
public boolean isDeclarative() {
return configProvider != null;
}

@Override
public DeclarativeConfigProperties getDeclarativeConfig(String node) {
DeclarativeConfigProperties config =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ public Map<String, String> getMap(String name, Map<String, String> defaultValue)
return defaultValue;
}

@Override
public boolean isDeclarative() {
return false;
}

@Override
public DeclarativeConfigProperties getDeclarativeConfig(String node) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ public Map<String, String> getMap(String name, Map<String, String> defaultValue)
}
}

@Override
public boolean isDeclarative() {
return configProvider != null;
}

@Override
public DeclarativeConfigProperties getDeclarativeConfig(String node) {
DeclarativeConfigProperties config =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import static java.util.logging.Level.WARNING;

import com.google.auto.service.AutoService;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.incubator.ExtendedOpenTelemetry;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.instrumentation.api.incubator.config.internal.InstrumentationConfig;
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
import io.opentelemetry.javaagent.tooling.BeforeAgentListener;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import java.util.logging.Logger;
Expand All @@ -26,15 +26,22 @@ public final class RegexUrlTemplateCustomizerInitializer implements BeforeAgentL

@Override
public void beforeAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) {
InstrumentationConfig config = AgentInstrumentationConfig.get();
DeclarativeConfigProperties instrumentationConfig =
((ExtendedOpenTelemetry) GlobalOpenTelemetry.get())
.getConfigProvider()
.getInstrumentationConfig();
DeclarativeConfigProperties configuration =
instrumentationConfig != null
? instrumentationConfig
.getStructured("java", empty())
.getStructured("http", empty())
.getStructured("client", empty())
: null;
// url template is emitted only when http client experimental telemetry is enabled
boolean urlTemplateEnabled =
config.getBoolean("otel.instrumentation.http.client.emit-experimental-telemetry", false);
if (!urlTemplateEnabled || !config.isDeclarative()) {
if (configuration == null
|| !configuration.getBoolean("emit_experimental_telemetry/development", false)) {
return;
}
DeclarativeConfigProperties configuration =
config.getDeclarativeConfig("http").getStructured("client", empty());
configuration
.getStructuredList("url_template_rules", emptyList())
.forEach(
Expand Down
Loading