Skip to content

Commit

Permalink
Crash only the universal profiling integration and not the agent on f…
Browse files Browse the repository at this point in the history
…ailure (#251)
  • Loading branch information
JonasKunz authored May 8, 2024
1 parent 74c9170 commit d8fa704
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ public void testAllSettings(@TempDir Path tempDir) {
.put(SOCKET_DIR_OPTION, tempDirAbs)) {
OpenTelemetry otel = GlobalOpenTelemetry.get();
List<SpanProcessor> processors = OtelReflectionUtils.getSpanProcessors(otel);
assertThat(processors)
.filteredOn(proc -> proc instanceof UniversalProfilingProcessor)
.hasSize(1);
UniversalProfilingProcessor processor =
(UniversalProfilingProcessor)
processors.stream()
Expand All @@ -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<SpanProcessor> processors = OtelReflectionUtils.getSpanProcessors(otel);
assertThat(processors).isNotEmpty();
assertThat(processors)
.filteredOn(proc -> proc instanceof UniversalProfilingProcessor)
.hasSize(0);
}
}
}

0 comments on commit d8fa704

Please sign in to comment.