mirror of
https://github.com/iflytek/skillhub.git
synced 2026-08-28 11:25:00 +00:00
fix(observability): skip otlp exporter without endpoint
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
This commit is contained in:
parent
046132342f
commit
9290fe3ca2
3 changed files with 56 additions and 3 deletions
|
|
@ -19,7 +19,10 @@ public final class TracingModeAutoConfigurationImportFilter
|
|||
|
||||
private static final Set<String> OTEL_AUTO_CONFIGURATIONS = Set.of(
|
||||
"org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetryAutoConfiguration",
|
||||
"org.springframework.boot.actuate.autoconfigure.tracing.OpenTelemetryAutoConfiguration",
|
||||
"org.springframework.boot.actuate.autoconfigure.tracing.OpenTelemetryAutoConfiguration"
|
||||
);
|
||||
|
||||
private static final Set<String> OTLP_EXPORT_AUTO_CONFIGURATIONS = Set.of(
|
||||
"org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpAutoConfiguration"
|
||||
);
|
||||
|
||||
|
|
@ -34,12 +37,16 @@ public final class TracingModeAutoConfigurationImportFilter
|
|||
&& "otel-sdk".equalsIgnoreCase(
|
||||
environment.getProperty(TRACING_MODE_PROPERTY, "none")
|
||||
);
|
||||
boolean otlpExportEnabled = otelSdkEnabled
|
||||
&& hasText(environment.getProperty("management.otlp.tracing.endpoint"));
|
||||
boolean[] matches = new boolean[autoConfigurationClasses.length];
|
||||
for (int index = 0; index < autoConfigurationClasses.length; index++) {
|
||||
String autoConfigurationClass = autoConfigurationClasses[index];
|
||||
matches[index] = autoConfigurationClass != null
|
||||
&& (otelSdkEnabled
|
||||
|| !OTEL_AUTO_CONFIGURATIONS.contains(autoConfigurationClass));
|
||||
&& ((otelSdkEnabled
|
||||
|| !OTEL_AUTO_CONFIGURATIONS.contains(autoConfigurationClass))
|
||||
&& (otlpExportEnabled
|
||||
|| !OTLP_EXPORT_AUTO_CONFIGURATIONS.contains(autoConfigurationClass)));
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
|
@ -48,4 +55,8 @@ public final class TracingModeAutoConfigurationImportFilter
|
|||
public void setEnvironment(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
private static boolean hasText(String value) {
|
||||
return value != null && !value.isBlank();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,24 @@ class SkillHubTracingConfigurationTest {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void otelSdkModeWithEmptyEndpointShouldCreateInProcessTracerOnly() {
|
||||
contextRunner
|
||||
.withPropertyValues(
|
||||
"skillhub.observability.tracing-mode=otel-sdk",
|
||||
"management.otlp.tracing.endpoint=",
|
||||
"management.tracing.sampling.probability=1.0",
|
||||
"management.tracing.baggage.enabled=false",
|
||||
"management.tracing.propagation.type=W3C"
|
||||
)
|
||||
.run(context -> {
|
||||
assertThat(context).hasNotFailed();
|
||||
assertThat(context.getBean(Tracer.class)).isInstanceOf(OtelTracer.class);
|
||||
assertThat(context).hasSingleBean(OpenTelemetry.class);
|
||||
assertThat(context).doesNotHaveBean(OtlpHttpSpanExporter.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void otelSdkModeShouldCreateExporterOnlyWhenEndpointIsConfigured() {
|
||||
contextRunner
|
||||
|
|
|
|||
|
|
@ -47,9 +47,33 @@ class TracingModeAutoConfigurationImportFilterTest {
|
|||
"otel-sdk"
|
||||
));
|
||||
|
||||
assertThat(matches()).containsExactly(true, true, false, true, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldEnableOtlpExporterOnlyWhenEndpointHasText() {
|
||||
filter.setEnvironment(new MockEnvironment()
|
||||
.withProperty(
|
||||
TracingModeAutoConfigurationImportFilter.TRACING_MODE_PROPERTY,
|
||||
"otel-sdk"
|
||||
)
|
||||
.withProperty("management.otlp.tracing.endpoint", "http://127.0.0.1:4318/v1/traces"));
|
||||
|
||||
assertThat(matches()).containsExactly(true, true, true, true, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExcludeOtlpExporterWhenEndpointIsEmpty() {
|
||||
filter.setEnvironment(new MockEnvironment()
|
||||
.withProperty(
|
||||
TracingModeAutoConfigurationImportFilter.TRACING_MODE_PROPERTY,
|
||||
"otel-sdk"
|
||||
)
|
||||
.withProperty("management.otlp.tracing.endpoint", ""));
|
||||
|
||||
assertThat(matches()).containsExactly(true, true, false, true, false);
|
||||
}
|
||||
|
||||
private boolean[] matches() {
|
||||
return filter.match(
|
||||
new String[]{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue