1111import com .fasterxml .jackson .core .JsonProcessingException ;
1212import com .fasterxml .jackson .databind .ObjectMapper ;
1313import com .google .common .collect .ImmutableMap ;
14+ import io .opentelemetry .api .incubator .config .ConfigProvider ;
1415import io .opentelemetry .api .incubator .config .DeclarativeConfigProperties ;
1516import io .opentelemetry .api .incubator .config .InstrumentationConfigUtil ;
16- import io .opentelemetry .sdk .autoconfigure .internal .ComponentLoader ;
17- import io .opentelemetry .sdk .autoconfigure .internal .SpiHelper ;
1817import io .opentelemetry .sdk .extension .incubator .fileconfig .DeclarativeConfiguration ;
19- import io .opentelemetry .sdk .extension .incubator .fileconfig .YamlDeclarativeConfigProperties ;
18+ import io .opentelemetry .sdk .extension .incubator .fileconfig .SdkConfigProvider ;
19+ import io .opentelemetry .sdk .extension .incubator .fileconfig .internal .model .ExperimentalLanguageSpecificInstrumentationModel ;
20+ import io .opentelemetry .sdk .extension .incubator .fileconfig .internal .model .InstrumentationModel ;
21+ import io .opentelemetry .sdk .extension .incubator .fileconfig .internal .model .OpenTelemetryConfigurationModel ;
2022import java .io .ByteArrayInputStream ;
2123import java .nio .charset .StandardCharsets ;
2224import java .util .Arrays ;
2729import java .util .Objects ;
2830import org .junit .jupiter .api .Test ;
2931
30- class ConvertToModelTest {
32+ class InstrumentationConfigUtilTest {
3133
3234 private static final ObjectMapper MAPPER = new ObjectMapper ();
3335
@@ -58,17 +60,31 @@ void toMap_RoundTrip() throws JsonProcessingException {
5860 }
5961
6062 @ Test
61- void convertToModel_Empty () {
62- DeclarativeConfigProperties properties = ofMap ( Collections . emptyMap ()) ;
63+ void getInstrumentationConfigModel_UnsetConfig () {
64+ ConfigProvider configProvider = () -> null ;
6365
64- assertThat (InstrumentationConfigUtil .convertToModel (MAPPER , properties , Model .class ))
66+ assertThat (
67+ InstrumentationConfigUtil .getInstrumentationConfigModel (
68+ configProvider , "my_instrumentation_library" , MAPPER , Model .class ))
69+ .isEqualTo (null );
70+ }
71+
72+ @ Test
73+ void getInstrumentationConfigModel_EmptyConfig () {
74+ ConfigProvider configProvider =
75+ withInstrumentationConfig ("my_instrumentation_library" , Collections .emptyMap ());
76+
77+ assertThat (
78+ InstrumentationConfigUtil .getInstrumentationConfigModel (
79+ configProvider , "my_instrumentation_library" , MAPPER , Model .class ))
6580 .isEqualTo (new Model ());
6681 }
6782
6883 @ Test
69- void convertToModel_KitchenSink () {
70- DeclarativeConfigProperties properties =
71- ofMap (
84+ void getInstrumentationConfigModel_KitchenSink () {
85+ ConfigProvider configProvider =
86+ withInstrumentationConfig (
87+ "my_instrumentation_library" ,
7288 ImmutableMap .<String , Object >builder ()
7389 .put ("string_property" , "value" )
7490 .put ("boolean_property" , true )
@@ -84,6 +100,7 @@ void convertToModel_KitchenSink() {
84100 Collections .singletonList (
85101 ImmutableMap .of ("key" , "the_key" , "value" , "the_value" )))
86102 .build ());
103+
87104 Model expected = new Model ();
88105 expected .stringProperty = "value" ;
89106 expected .booleanProperty = true ;
@@ -99,15 +116,21 @@ void convertToModel_KitchenSink() {
99116 listEntryModel .value = "the_value" ;
100117 expected .structuredListProperty = Collections .singletonList (listEntryModel );
101118
102- assertThat (InstrumentationConfigUtil .convertToModel (MAPPER , properties , Model .class ))
119+ assertThat (
120+ InstrumentationConfigUtil .getInstrumentationConfigModel (
121+ configProvider , "my_instrumentation_library" , MAPPER , Model .class ))
103122 .isEqualTo (expected );
104123 }
105124
106- private static final ComponentLoader componentLoader =
107- SpiHelper .serviceComponentLoader (ConvertToModelTest .class .getClassLoader ());
125+ private static ConfigProvider withInstrumentationConfig (
126+ String instrumentationName , Map <String , Object > instrumentationConfig ) {
127+ ExperimentalLanguageSpecificInstrumentationModel javaConfig =
128+ new ExperimentalLanguageSpecificInstrumentationModel ();
129+ javaConfig .setAdditionalProperty (instrumentationName , instrumentationConfig );
108130
109- private static YamlDeclarativeConfigProperties ofMap (Map <String , Object > map ) {
110- return YamlDeclarativeConfigProperties .create (map , componentLoader );
131+ return SdkConfigProvider .create (
132+ new OpenTelemetryConfigurationModel ()
133+ .withInstrumentationDevelopment (new InstrumentationModel ().withJava (javaConfig )));
111134 }
112135
113136 private static class Model {
0 commit comments