Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ replay_pid*
.lycheecache

build-scan.txt


#Ignore vscode AI rules
.github/instructions/codacy.instructions.md
Comment thread
aviralgarg05 marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import java.util.HashMap;
import java.util.Map;

/**
* A {@link ConfigProvider} implementation backed by {@link ConfigProperties}.
Expand All @@ -20,13 +22,33 @@ public final class ConfigPropertiesBackedConfigProvider implements ConfigProvide
private final DeclarativeConfigProperties instrumentationConfig;

public static ConfigProvider create(ConfigProperties configProperties) {
return new ConfigPropertiesBackedConfigProvider(configProperties);
return new ConfigPropertiesBackedConfigProvider(
ConfigPropertiesBackedDeclarativeConfigProperties.createInstrumentationConfig(
configProperties));
}

private ConfigPropertiesBackedConfigProvider(ConfigProperties configProperties) {
this.instrumentationConfig =
ConfigPropertiesBackedDeclarativeConfigProperties.createInstrumentationConfig(
configProperties);
public static Builder builder() {
return new Builder();
}

private ConfigPropertiesBackedConfigProvider(DeclarativeConfigProperties instrumentationConfig) {
this.instrumentationConfig = instrumentationConfig;
}

public static final class Builder {
Comment thread
aviralgarg05 marked this conversation as resolved.
private final Map<String, String> mappings = new HashMap<>();

@com.google.errorprone.annotations.CanIgnoreReturnValue
Comment thread
aviralgarg05 marked this conversation as resolved.
Outdated
public Builder addMapping(String declarativeProperty, String configProperty) {
mappings.put(declarativeProperty, configProperty);
return this;
}

public ConfigProvider build(ConfigProperties configProperties) {
return new ConfigPropertiesBackedConfigProvider(
ConfigPropertiesBackedDeclarativeConfigProperties.createInstrumentationConfig(
configProperties, mappings));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,24 @@ public final class ConfigPropertiesBackedDeclarativeConfigProperties

private final ConfigProperties configProperties;
private final List<String> path;
private final Map<String, String> mappings;

public static DeclarativeConfigProperties createInstrumentationConfig(
ConfigProperties configProperties) {
return createInstrumentationConfig(configProperties, SPECIAL_MAPPINGS);
}

public static DeclarativeConfigProperties createInstrumentationConfig(
Comment thread
aviralgarg05 marked this conversation as resolved.
ConfigProperties configProperties, Map<String, String> mappings) {
return new ConfigPropertiesBackedDeclarativeConfigProperties(
configProperties, Collections.emptyList());
configProperties, Collections.emptyList(), mappings);
}

private ConfigPropertiesBackedDeclarativeConfigProperties(
ConfigProperties configProperties, List<String> path) {
ConfigProperties configProperties, List<String> path, Map<String, String> mappings) {
this.configProperties = configProperties;
this.path = path;
this.mappings = mappings;
}

@Nullable
Expand Down Expand Up @@ -151,7 +158,8 @@ public Long getLong(String name) {
if (duration != null) {
return duration.toMillis();
}
// If discovery delay has not been configured, have a peek at the metric export interval.
// If discovery delay has not been configured, have a peek at the metric export
// interval.
Comment thread
aviralgarg05 marked this conversation as resolved.
Outdated
// It makes sense for both of these values to be similar.
Duration fallback = configProperties.getDuration("otel.metric.export.interval");
if (fallback != null) {
Expand Down Expand Up @@ -179,7 +187,8 @@ public Double getDouble(String name) {
public DeclarativeConfigProperties getStructured(String name) {
List<String> newPath = new ArrayList<>(path);
newPath.add(name);
return new ConfigPropertiesBackedDeclarativeConfigProperties(configProperties, newPath);
return new ConfigPropertiesBackedDeclarativeConfigProperties(
configProperties, newPath, mappings);
}

@Nullable
Expand Down Expand Up @@ -221,7 +230,7 @@ private String resolvePropertyKey(String name) {
String fullPath = pathWithName(name);

// Check explicit property mappings first
String mappedKey = SPECIAL_MAPPINGS.get(fullPath);
String mappedKey = mappings.get(fullPath);
if (mappedKey != null) {
return mappedKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* string_key: value
* </pre>
*/
@Deprecated
final class DeclarativeConfigPropertiesBridge implements ConfigProperties {

private static final String OTEL_INSTRUMENTATION_PREFIX = "otel.instrumentation.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
/**
* A builder for {@link DeclarativeConfigPropertiesBridge} that allows adding translations and fixed
* values for properties.
*
* @deprecated Use {@link ConfigPropertiesBackedConfigProvider#builder()} instead.
Comment thread
aviralgarg05 marked this conversation as resolved.
Outdated
*/
@Deprecated
public class DeclarativeConfigPropertiesBridgeBuilder {
Comment thread
aviralgarg05 marked this conversation as resolved.
Outdated
/**
* order is important here, so we use LinkedHashMap - see {@link #addMapping(String, String)} for
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;

class ConfigPropertiesBackedConfigProviderTest {
@Test
void testBuilderWithMappings() {
Map<String, String> properties = new HashMap<>();
properties.put("my.custom.property", "custom-value");

// ConfigProperties has "my.custom.property"
// We want to map declarative "my.declarative.prop" to "my.custom.property"

ConfigProvider provider =
ConfigPropertiesBackedConfigProvider.builder()
.addMapping("my.declarative.prop", "my.custom.property")
.build(DefaultConfigProperties.createFromMap(properties));

DeclarativeConfigProperties config = provider.getInstrumentationConfig();

// DeclarativeConfigProperties structure lookup
// pathWithName("my.declarative.prop") should map to "my.custom.property"
// However, structure is hierarchical.
// getStructured("my").getStructured("declarative").getString("prop") ->
// "my.declarative.prop"

assertThat(config.getStructured("my").getStructured("declarative").getString("prop"))
.isEqualTo("custom-value");
}

@Test
void testCreateUsesDefaults() {
// Verify that create() still supports the default mappings (e.g.
// otel.instrumentation...)
// e.g. "java.common.http.known_methods" ->
// "otel.instrumentation.http.known-methods"

Map<String, String> properties = new HashMap<>();
properties.put("otel.instrumentation.http.known-methods", "GET,POST");

ConfigProvider provider =
ConfigPropertiesBackedConfigProvider.create(
DefaultConfigProperties.createFromMap(properties));

DeclarativeConfigProperties config = provider.getInstrumentationConfig();

assertThat(
config
.getStructured("java")
.getStructured("common")
.getStructured("http")
.getString("known_methods"))
.isEqualTo("GET,POST");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.mockito.MockedStatic;
import org.mockito.Mockito;

@SuppressWarnings("DoNotMockAutoValue")
@SuppressWarnings({"DoNotMockAutoValue", "deprecation"})
class DeclarativeConfigPropertiesBridgeBuilderTest {
@Test
void shouldUseConfigPropertiesForAutoConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

@SuppressWarnings("deprecation")
Comment thread
aviralgarg05 marked this conversation as resolved.
Outdated
class DeclarativeConfigPropertiesBridgeTest {

private ConfigProperties bridge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ plugins {
base.archivesName.set("opentelemetry-spring-boot-autoconfigure")
group = "io.opentelemetry.instrumentation"

tasks.withType<JavaCompile>().configureEach {
// Suppress deprecation warnings for DeclarativeConfigPropertiesBridgeBuilder usage
// This is intentional as we still support the deprecated API for backward compatibility
options.compilerArgs.add("-Xlint:-deprecation")
}

Comment thread
aviralgarg05 marked this conversation as resolved.
Outdated
val springBootVersion =
"2.7.18" // AutoConfiguration is added in 2.7.0, but can be used with older versions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
*
* <p>Updates the sampler probability for the configured {@link TracerProvider}.
*/
// Suppressing deprecation warnings for DeclarativeConfigPropertiesBridgeBuilder usage.
// This is safe because we're maintaining backward compatibility while transitioning to the new API.
@SuppressWarnings("deprecation")
@Configuration
public class OpenTelemetryAutoConfiguration {
private static final Logger logger =
Expand Down
6 changes: 6 additions & 0 deletions javaagent-tooling/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ plugins {

group = "io.opentelemetry.javaagent"

tasks.withType<JavaCompile>().configureEach {
// Suppress deprecation warnings for DeclarativeConfigPropertiesBridgeBuilder usage
// This is intentional as we still support the deprecated API for backward compatibility
options.compilerArgs.add("-Xlint:-deprecation")
}

Comment thread
aviralgarg05 marked this conversation as resolved.
Outdated
dependencies {
implementation(project(":javaagent-bootstrap"))
implementation(project(":javaagent-extension-api"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import io.opentelemetry.sdk.common.CompletableResultCode;
import java.util.Arrays;

// Suppressing deprecation warnings for DeclarativeConfigPropertiesBridgeBuilder usage.
// This is safe because we're maintaining backward compatibility while transitioning to the new API.
@SuppressWarnings("deprecation")
public final class OpenTelemetryInstaller {

/**
Expand Down
Loading