diff --git a/universal-profiling-integration/src/main/java/co/elastic/otel/UniversalProfilingProcessorAutoConfig.java b/universal-profiling-integration/src/main/java/co/elastic/otel/UniversalProfilingProcessorAutoConfig.java index aebb6300..f3aa1e55 100644 --- a/universal-profiling-integration/src/main/java/co/elastic/otel/UniversalProfilingProcessorAutoConfig.java +++ b/universal-profiling-integration/src/main/java/co/elastic/otel/UniversalProfilingProcessorAutoConfig.java @@ -26,6 +26,7 @@ import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.semconv.ResourceAttributes; +import java.util.logging.Level; import java.util.logging.Logger; @AutoService(ChainingSpanProcessorAutoConfiguration.class) @@ -69,12 +70,20 @@ public void registerSpanProcessors( PropertiesApplier props = new PropertiesApplier(properties); registerer.register( next -> { - UniversalProfilingProcessorBuilder builder = - UniversalProfilingProcessor.builder(next, resource); - builder.delayActivationAfterProfilerRegistration(enabled == EnabledOptions.AUTO); - props.applyInt(BUFFER_SIZE_OPTION, builder::bufferSize); - props.applyString(SOCKET_DIR_OPTION, builder::socketDir); - return builder.build(); + try { + UniversalProfilingProcessorBuilder builder = + UniversalProfilingProcessor.builder(next, resource); + builder.delayActivationAfterProfilerRegistration(enabled == EnabledOptions.AUTO); + props.applyInt(BUFFER_SIZE_OPTION, builder::bufferSize); + props.applyString(SOCKET_DIR_OPTION, builder::socketDir); + return builder.build(); + } catch (Exception e) { + logger.log( + Level.SEVERE, + "Failed to initialize universal profiling integration, the feature won't work", + e); + return next; + } }); } } diff --git a/universal-profiling-integration/src/test/java/co/elastic/otel/UniversalProfilingProcessorAutoConfigTest.java b/universal-profiling-integration/src/test/java/co/elastic/otel/UniversalProfilingProcessorAutoConfigTest.java index ef78b475..0f159810 100644 --- a/universal-profiling-integration/src/test/java/co/elastic/otel/UniversalProfilingProcessorAutoConfigTest.java +++ b/universal-profiling-integration/src/test/java/co/elastic/otel/UniversalProfilingProcessorAutoConfigTest.java @@ -86,9 +86,6 @@ public void testAllSettings(@TempDir Path tempDir) { .put(SOCKET_DIR_OPTION, tempDirAbs)) { OpenTelemetry otel = GlobalOpenTelemetry.get(); List processors = OtelReflectionUtils.getSpanProcessors(otel); - assertThat(processors) - .filteredOn(proc -> proc instanceof UniversalProfilingProcessor) - .hasSize(1); UniversalProfilingProcessor processor = (UniversalProfilingProcessor) processors.stream() @@ -101,4 +98,26 @@ public void testAllSettings(@TempDir Path tempDir) { assertThat(processor.correlator.delayedSpans.getBufferSize()).isEqualTo(256); } } + + @Test + public void testFailureDoesNotCrashAutoConfig() { + String badSockerPath = ""; + for (int i = 0; i < 1000; i++) { + badSockerPath += "abc"; + } + + try (AutoConfigTestProperties props = + new AutoConfigTestProperties() + .put("otel.service.name", "myservice") + .put(ENABLED_OPTION, "true") + .put(SOCKET_DIR_OPTION, badSockerPath)) { + + OpenTelemetry otel = GlobalOpenTelemetry.get(); + List processors = OtelReflectionUtils.getSpanProcessors(otel); + assertThat(processors).isNotEmpty(); + assertThat(processors) + .filteredOn(proc -> proc instanceof UniversalProfilingProcessor) + .hasSize(0); + } + } }