Skip to content

Commit

Permalink
Fix Calling shutdown() multiple times warning in spring starter (#10222)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Jan 18, 2024
1 parent 9e208c8 commit 61e2987
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public MapConverter mapConverter() {
return new MapConverter();
}

@Bean
@Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance
@ConditionalOnMissingBean
public SdkTracerProvider sdkTracerProvider(
SamplerProperties samplerProperties,
Expand All @@ -94,7 +94,7 @@ public SdkTracerProvider sdkTracerProvider(
.build();
}

@Bean
@Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance
@ConditionalOnMissingBean
public SdkLoggerProvider sdkLoggerProvider(
ObjectProvider<List<LogRecordExporter>> loggerExportersProvider, Resource otelResource) {
Expand All @@ -112,7 +112,7 @@ public SdkLoggerProvider sdkLoggerProvider(
return loggerProviderBuilder.build();
}

@Bean
@Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance
@ConditionalOnMissingBean
public SdkMeterProvider sdkMeterProvider(
MetricExportProperties properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@ConditionalOnClass(LoggingMetricExporter.class)
public class LoggingMetricExporterAutoConfiguration {

@Bean
@Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance
public LoggingMetricExporter otelLoggingMetricExporter() {
return LoggingMetricExporter.create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@ConditionalOnClass(LoggingSpanExporter.class)
public class LoggingSpanExporterAutoConfiguration {

@Bean
@Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance
@ConditionalOnMissingBean
public LoggingSpanExporter otelLoggingSpanExporter() {
return LoggingSpanExporter.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@ConditionalOnClass(OtlpGrpcLogRecordExporter.class)
public class OtlpLoggerExporterAutoConfiguration {

@Bean
@Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance
@ConditionalOnMissingBean({OtlpGrpcLogRecordExporter.class, OtlpHttpLogRecordExporter.class})
public LogRecordExporter otelOtlpLogRecordExporter(OtlpExporterProperties properties) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@ConditionalOnClass(OtlpGrpcMetricExporter.class)
public class OtlpMetricExporterAutoConfiguration {

@Bean
@Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance
@ConditionalOnMissingBean({OtlpGrpcMetricExporter.class, OtlpHttpMetricExporter.class})
public MetricExporter otelOtlpMetricExporter(OtlpExporterProperties properties) {
return OtlpExporterUtil.applySignalProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public OtlpHttpSpanExporterBuilder otelOtlpHttpSpanExporterBuilder() {
return OtlpHttpSpanExporter.builder();
}

@Bean
@Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance
@ConditionalOnMissingBean({OtlpGrpcSpanExporter.class, OtlpHttpSpanExporter.class})
public SpanExporter otelOtlpSpanExporter(
OtlpExporterProperties properties, OtlpHttpSpanExporterBuilder otlpHttpSpanExporterBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@ConditionalOnClass(ZipkinSpanExporter.class)
public class ZipkinSpanExporterAutoConfiguration {

@Bean
@Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance
@ConditionalOnMissingBean
public ZipkinSpanExporter otelZipkinSpanExporter(ZipkinSpanExporterProperties properties) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@ void initializeOpenTelemetryWithCustomProviders() {
.withBean(
"customTracerProvider",
SdkTracerProvider.class,
() -> SdkTracerProvider.builder().build())
() -> SdkTracerProvider.builder().build(),
bd -> bd.setDestroyMethodName(""))
.withBean(
"customMeterProvider", SdkMeterProvider.class, () -> SdkMeterProvider.builder().build())
"customMeterProvider",
SdkMeterProvider.class,
() -> SdkMeterProvider.builder().build(),
bd -> bd.setDestroyMethodName(""))
.withBean(
"customLoggerProvider",
SdkLoggerProvider.class,
() -> SdkLoggerProvider.builder().build())
() -> SdkLoggerProvider.builder().build(),
bd -> bd.setDestroyMethodName(""))
.withConfiguration(AutoConfigurations.of(OpenTelemetryAutoConfiguration.class))
.run(
context ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ void useHttpWhenAnUnknownProtocolIsSet() {
@DisplayName("logging exporter can still be configured")
void loggingExporter() {
this.contextRunner
.withBean(LoggingSpanExporter.class, LoggingSpanExporter::create)
.withBean(
LoggingSpanExporter.class,
LoggingSpanExporter::create,
bd -> bd.setDestroyMethodName(""))
.run(
context ->
assertThat(
Expand Down

0 comments on commit 61e2987

Please sign in to comment.