Instrumentation mode cleanup (#14641)

This commit is contained in:
Gregor Zeitlinger 2025-09-12 15:48:13 +02:00 committed by GitHub
parent 2a05236a56
commit 6cbef730e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 7 deletions

View File

@ -76,19 +76,19 @@ public final class OpenTelemetryInstaller {
return true; return true;
} }
String profile = String mode =
instrumentationConfig instrumentationConfig
.getStructured("java", empty()) .getStructured("java", empty())
.getStructured("agent", empty()) .getStructured("agent", empty())
.getString("instrumentation_mode", "default"); .getString("instrumentation_mode", "default");
switch (profile) { switch (mode) {
case "none": case "none":
return false; return false;
case "default": case "default":
return true; return true;
default: default:
throw new ConfigurationException("Unknown instrumentation profile: " + profile); throw new ConfigurationException("Unknown instrumentation mode: " + mode);
} }
} }

View File

@ -51,14 +51,14 @@ class OpenTelemetryInstallerTest {
}) })
void defaultEnabledInDeclarativeConfigPropertiesBridge( void defaultEnabledInDeclarativeConfigPropertiesBridge(
String propertyValue, boolean expected, boolean fail) { String propertyValue, boolean expected, boolean fail) {
String profile = propertyValue == null ? "" : "instrumentation_mode: \"" + propertyValue + "\""; String mode = propertyValue == null ? "" : "instrumentation_mode: \"" + propertyValue + "\"";
String yaml = String yaml =
"file_format: \"1.0-rc.1\"\n" "file_format: \"1.0-rc.1\"\n"
+ "instrumentation/development:\n" + "instrumentation/development:\n"
+ " java:\n" + " java:\n"
+ " agent:\n" + " agent:\n"
+ " " + " "
+ profile; + mode;
Supplier<ConfigProperties> configPropertiesSupplier = Supplier<ConfigProperties> configPropertiesSupplier =
() -> () ->
@ -71,7 +71,7 @@ class OpenTelemetryInstallerTest {
if (fail) { if (fail) {
assertThatCode(() -> configPropertiesSupplier.get()) assertThatCode(() -> configPropertiesSupplier.get())
.isInstanceOf(ConfigurationException.class) .isInstanceOf(ConfigurationException.class)
.hasMessage("Unknown instrumentation profile: invalid"); .hasMessage("Unknown instrumentation mode: invalid");
} else { } else {
assertThat( assertThat(
configPropertiesSupplier configPropertiesSupplier

View File

@ -48,7 +48,11 @@ class DeclarativeConfigurationSmokeTest extends SmokeTest {
Collection<ExportTraceServiceRequest> traces = waitForTraces() Collection<ExportTraceServiceRequest> traces = waitForTraces()
then: "There is one trace" then: "There is one trace"
traces.size() > 0 traces.size() == 1
then: "There is one span (io.opentelemetry.opentelemetry-instrumentation-annotations-1.16 " +
"is not used, because instrumentation_mode=none)"
getSpanStream(traces).count() == 1
then: "explicitly set attribute is present" then: "explicitly set attribute is present"
hasResourceAttribute(traces, "service.name", "declarative-config-smoke-test") hasResourceAttribute(traces, "service.name", "declarative-config-smoke-test")

View File

@ -19,3 +19,10 @@ resource:
attributes: attributes:
- name: service.name - name: service.name
value: declarative-config-smoke-test value: declarative-config-smoke-test
instrumentation/development:
java:
agent:
instrumentation_mode: none
tomcat:
enabled: true