Skip to content

Commit

Permalink
Remove illegal hyphen in span stacktrace config option (#433)
Browse files Browse the repository at this point in the history
* Remove illegal hyphen in config option

* Added back support for legacy config option

* spotless
  • Loading branch information
JonasKunz authored Oct 16, 2024
1 parent 9cddccb commit 55abd19
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@
@AutoService(ChainingSpanProcessorAutoConfiguration.class)
public class SpanStackTraceProcessorAutoConfig implements ChainingSpanProcessorAutoConfiguration {

static final String LEGACY_DURATION_CONFIG_OPTION =
"elastic.otel.java.span-stacktrace.min.duration";
// TODO replace this with upstream config once it's stable
static final String MIN_DURATION_CONFIG_OPTION = "elastic.otel.java.span-stacktrace.min.duration";
static final String MIN_DURATION_CONFIG_OPTION = "elastic.otel.java.span.stacktrace.min.duration";

@Override
public void registerSpanProcessors(
ConfigProperties properties, ChainingSpanProcessorRegisterer registerer) {

Duration minDuration = properties.getDuration(MIN_DURATION_CONFIG_OPTION, Duration.ofMillis(5));
Duration legacyMinDuration =
properties.getDuration(LEGACY_DURATION_CONFIG_OPTION, Duration.ofMillis(5));
Duration minDuration = properties.getDuration(MIN_DURATION_CONFIG_OPTION, legacyMinDuration);
if (minDuration.isNegative()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@ void featureCanBeDisabled() {
}
}

@Test
void legacyConfigOptionSupported() {
try (AutoConfigTestProperties testProps =
new AutoConfigTestProperties()
.put(SpanStackTraceProcessorAutoConfig.LEGACY_DURATION_CONFIG_OPTION, "0ms")) {
OpenTelemetry otel = GlobalOpenTelemetry.get();

// TODO: cleanup other extensions (Breakdown) so that this is not required:
ElasticExtension.INSTANCE.registerOpenTelemetry(otel);

Tracer tracer = otel.getTracer("test-tracer");

tracer.spanBuilder("my-span").startSpan().end();

List<SpanData> spans = AutoConfiguredDataCapture.getSpans();

assertThat(spans).hasSize(1);
assertThat(spans.get(0))
.hasName("my-span")
.hasAttribute(
satisfies(CodeIncubatingAttributes.CODE_STACKTRACE, att -> att.isNotBlank()));
}
}

@Test
void checkMinDurationRespected() {
try (AutoConfigTestProperties testProps =
Expand Down

0 comments on commit 55abd19

Please sign in to comment.