1010import static org .assertj .core .api .Assertions .assertThat ;
1111
1212import io .opentelemetry .api .GlobalOpenTelemetry ;
13+ import io .opentelemetry .instrumentation .api .incubator .config .internal .DeclarativeConfigUtil ;
1314import io .opentelemetry .javaagent .tooling .OpenTelemetryInstaller ;
1415import io .opentelemetry .sdk .autoconfigure .AutoConfiguredOpenTelemetrySdk ;
15- import io .opentelemetry .sdk .autoconfigure .internal .AutoConfigureUtil ;
1616import io .opentelemetry .sdk .autoconfigure .spi .AutoConfigurationCustomizer ;
1717import io .opentelemetry .sdk .autoconfigure .spi .AutoConfigurationCustomizerProvider ;
1818import java .io .IOException ;
@@ -41,7 +41,7 @@ void setUp() {
4141 void fileConfigOverwritesUserPropertiesSupplier (@ TempDir Path tempDir ) throws IOException {
4242 // given
4343 Path configFile = tempDir .resolve ("test-config.properties" );
44- Files .write (configFile , singleton ("custom.key = 42" ));
44+ Files .write (configFile , singleton ("otel.instrumentation. custom.key = 42" ));
4545 System .setProperty (ConfigurationFile .CONFIGURATION_FILE_PROPERTY , configFile .toString ());
4646
4747 // when
@@ -50,16 +50,38 @@ void fileConfigOverwritesUserPropertiesSupplier(@TempDir Path tempDir) throws IO
5050 this .getClass ().getClassLoader (), EarlyInitAgentConfig .create ());
5151
5252 // then
53- assertThat (AutoConfigureUtil .getConfig (autoConfiguredSdk ).getString ("custom.key" ))
53+ assertThat (
54+ DeclarativeConfigUtil .getInstrumentationConfig (
55+ autoConfiguredSdk .getOpenTelemetrySdk (), "custom" )
56+ .getString ("key" ))
5457 .isEqualTo ("42" );
5558 }
5659
60+ // baseline for the test above to make sure UserCustomPropertiesSupplier
61+ // is actually working
62+ @ SetSystemProperty (key = "otel.sdk.disabled" , value = "true" ) // don't setup the SDK
63+ @ Test
64+ void userPropertiesSupplier () {
65+ // when
66+ AutoConfiguredOpenTelemetrySdk autoConfiguredSdk =
67+ OpenTelemetryInstaller .installOpenTelemetrySdk (
68+ this .getClass ().getClassLoader (), EarlyInitAgentConfig .create ());
69+
70+ // then
71+ assertThat (
72+ DeclarativeConfigUtil .getInstrumentationConfig (
73+ autoConfiguredSdk .getOpenTelemetrySdk (), "custom" )
74+ .getString ("key" ))
75+ .isEqualTo ("123" );
76+ }
77+
5778 // SPI used in test
5879 public static class UserCustomPropertiesSupplier implements AutoConfigurationCustomizerProvider {
5980
6081 @ Override
6182 public void customize (AutoConfigurationCustomizer autoConfiguration ) {
62- autoConfiguration .addPropertiesSupplier (() -> singletonMap ("custom.key" , "123" ));
83+ autoConfiguration .addPropertiesSupplier (
84+ () -> singletonMap ("otel.instrumentation.custom.key" , "123" ));
6385 }
6486 }
6587}
0 commit comments