File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed
main/java/io/opentelemetry/api/incubator/config
test/java/io/opentelemetry/api/incubator
sdk-extensions/autoconfigure/src/testIncubating/java/io/opentelemetry/sdk/autoconfigure Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,23 @@ default DeclarativeConfigProperties getJavaInstrumentationConfig(String name) {
4848 return config .getStructured ("java" , empty ()).getStructured (name , empty ());
4949 }
5050
51+ /**
52+ * Returns the {@link DeclarativeConfigProperties} for general instrumentation config by name. If
53+ * no configuration is available for the given name, an empty {@link DeclarativeConfigProperties}
54+ * is returned.
55+ *
56+ * @param name the name of the general instrumentation config
57+ * @return the {@link DeclarativeConfigProperties} for the given general instrumentation config
58+ * name
59+ */
60+ default DeclarativeConfigProperties getGeneralInstrumentationConfig (String name ) {
61+ DeclarativeConfigProperties config = getInstrumentationConfig ();
62+ if (config == null ) {
63+ return empty ();
64+ }
65+ return config .getStructured ("general" , empty ()).getStructured (name , empty ());
66+ }
67+
5168 /** Returns a no-op {@link ConfigProvider}. */
5269 static ConfigProvider noop () {
5370 return () -> null ;
Original file line number Diff line number Diff line change @@ -17,4 +17,12 @@ void noopEquality() {
1717 ConfigProvider noop = ConfigProvider .noop ();
1818 assertThat (ConfigProvider .noop ()).isSameAs (noop );
1919 }
20+
21+ @ Test
22+ void instrumentationConfigFallback () {
23+ ConfigProvider configProvider = ConfigProvider .noop ();
24+ assertThat (configProvider .getInstrumentationConfig ()).isNull ();
25+ assertThat (configProvider .getJavaInstrumentationConfig ("servlet" )).isNotNull ();
26+ assertThat (configProvider .getGeneralInstrumentationConfig ("http" )).isNotNull ();
27+ }
2028}
Original file line number Diff line number Diff line change 55
66package io .opentelemetry .sdk .autoconfigure ;
77
8+ import static io .opentelemetry .api .incubator .config .DeclarativeConfigProperties .empty ;
89import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .assertThat ;
910import static java .util .Collections .singletonMap ;
1011import static org .assertj .core .api .Assertions .assertThatCode ;
@@ -232,8 +233,14 @@ void configFile_ConfigProvider() {
232233 .isNotNull ()
233234 .satisfies (exampleConfig -> assertThat (exampleConfig .getString ("key" )).isEqualTo ("value" ));
234235
235- // shortcut to get specific instrumentation config
236+ // shortcuts to get specific instrumentation config
236237 assertThat (globalConfigProvider .getJavaInstrumentationConfig ("example" ).getString ("key" ))
237238 .isEqualTo ("value" );
239+ assertThat (
240+ globalConfigProvider
241+ .getGeneralInstrumentationConfig ("http" )
242+ .getStructured ("client" , empty ())
243+ .getScalarList ("request_captured_headers" , String .class ))
244+ .isEqualTo (Arrays .asList ("Content-Type" , "Accept" ));
238245 }
239246}
You can’t perform that action at this time.
0 commit comments