Skip to content

Commit

Permalink
Allow full disabling of the span-stacktrace feature (#317)
Browse files Browse the repository at this point in the history
* Allow full disabling of the span-stacktrace feature

* Fix testing span capture procedure
  • Loading branch information
JonasKunz authored Jul 8, 2024
1 parent b4643c6 commit afe5aea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public void registerSpanProcessors(
ConfigProperties properties, ChainingSpanProcessorRegisterer registerer) {

Duration minDuration = properties.getDuration(MIN_DURATION_CONFIG_OPTION, Duration.ofMillis(5));
if (minDuration.isNegative()) {
return;
}
registerer.register(
next ->
new StackTraceSpanProcessor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.contrib.stacktrace.StackTraceSpanProcessor;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes;
import java.util.List;
Expand Down Expand Up @@ -65,6 +66,18 @@ void checkStackTracePresent() {
}
}

@Test
void featureCanBeDisabled() {
try (AutoConfigTestProperties testProps =
new AutoConfigTestProperties()
.put(SpanStackTraceProcessorAutoConfig.MIN_DURATION_CONFIG_OPTION, "-1")) {
OpenTelemetry otel = GlobalOpenTelemetry.get();

assertThat(OtelReflectionUtils.getSpanProcessors(otel))
.noneSatisfy(proc -> assertThat(proc).isInstanceOf(StackTraceSpanProcessor.class));
}
}

@Test
void checkMinDurationRespected() {
try (AutoConfigTestProperties testProps =
Expand All @@ -80,7 +93,9 @@ void checkMinDurationRespected() {
tracer.spanBuilder("my-span").startSpan().end();

List<SpanData> spans = AutoConfiguredDataCapture.getSpans();
assertThat(spans).hasSize(0);
assertThat(spans).hasSize(1);
assertThat(spans.get(0).getAttributes().get(CodeIncubatingAttributes.CODE_STACKTRACE))
.isNull();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@AutoService(AutoConfigurationCustomizerProvider.class)
public class AutoConfiguredDataCapture implements AutoConfigurationCustomizerProvider {

private static final InMemorySpanExporter inMemorySpanExporter = InMemorySpanExporter.create();
private static volatile InMemorySpanExporter inMemorySpanExporter = InMemorySpanExporter.create();

/*
Returns the spans which have been exported by the autoconfigured global OpenTelemetry SDK.
Expand All @@ -46,7 +46,7 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
// we piggy-back onto the autoconfigured logging exporter for now,
// because that one uses a SimpleSpanProcessor which does not impose a batching delay
if (spanExporter instanceof LoggingSpanExporter) {
inMemorySpanExporter.reset();
inMemorySpanExporter = InMemorySpanExporter.create();
return SpanExporter.composite(inMemorySpanExporter, spanExporter);
}
return spanExporter;
Expand Down

0 comments on commit afe5aea

Please sign in to comment.