Skip to content

make span stacktrace ignore inferred spans by default#2803

Merged
jaydeluca merged 2 commits into
open-telemetry:mainfrom
SylvainJuge:span-stacktrace-filter-inferred-spans
May 5, 2026
Merged

make span stacktrace ignore inferred spans by default#2803
jaydeluca merged 2 commits into
open-telemetry:mainfrom
SylvainJuge:span-stacktrace-filter-inferred-spans

Conversation

@SylvainJuge
Copy link
Copy Markdown
Contributor

The span stacktrace span processor captures the current thread stack trace when the span ends.

However, the inferred spans span processor produces spans that are not executed when the span is active as they are artificially generated from sampling data.

When the span stacktrace span processor is executed before the inferred spans, the inferred spans are naturally excluded, however when the stacktrace span processor is after then we have to explicitly exclude such spans. We can argue that this may be a mis-configuration in the span processor pipeline, but this creates an extra burden on user.

This is why the span stacktrace processor was created with the ability to provide a custom filter. The only known usage and filter implementation in that I'm aware of is in the Elastic (EDOT) distribution which is using the is_inferred span attribute to filter inferred spans.

With this change:

  • inferred-spans are ignored by default for span stacktraces, hence making it easier for users
  • we remove the need to use the is_inferred span attribute to detect span attributes, we can rely on the scope name (in a sense we trade one implementation detail to another)
  • this exclusion is being tested in unit tests

Possible follow-up tasks

  • remove the is_inferred span attribute in inferred spans: it is not part of semconv and should not be used by anyone after this change is effective
  • deprecate the filter option in span stacktrace span processor.

@SylvainJuge SylvainJuge self-assigned this Apr 29, 2026
@SylvainJuge SylvainJuge marked this pull request as ready for review April 29, 2026 16:12
@SylvainJuge SylvainJuge requested a review from a team as a code owner April 29, 2026 16:12
Copilot AI review requested due to automatic review settings April 29, 2026 16:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the span-stacktrace processor to skip stacktrace capture for inferred spans (which are synthesized from sampling data rather than executed on an active thread), and adds coverage to ensure this behavior.

Changes:

  • Skip stacktrace capture when the span’s instrumentation scope name indicates it was produced by the inferred-spans processor.
  • Extend unit tests to simulate spans with an inferred-spans instrumentation scope and assert stacktraces are not captured.
  • Clean up dependencies (remove duplicate entry; add a test-only dependency used by the new test).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
span-stacktrace/src/main/java/io/opentelemetry/contrib/stacktrace/StackTraceSpanProcessor.java Adds an early-return to ignore inferred spans during onEnding stacktrace capture.
span-stacktrace/src/test/java/io/opentelemetry/contrib/stacktrace/StackTraceSpanProcessorTest.java Updates helpers to allow varying tracer/scope name and adds a test asserting inferred spans are ignored.
span-stacktrace/build.gradle.kts Removes a duplicate dependency declaration and adds a test-only dependency for inferred-spans.

Comment on lines +59 to +63
if (!filterPredicate.test(span)) {
return;
}

// inferred spans are generated from sampling, thus the span processor is not actually called
Comment on lines +68 to +69
boolean isInferred = span.getInstrumentationScopeInfo().getName().equals("inferred-spans");
if (isInferred) {
Comment on lines 116 to +120
private static void checkSpanWithoutStackTrace(
Class<? extends Predicate<?>> predicateClass,
String minDurationString,
long spanDurationNanos) {
long spanDurationNanos,
String scopeName) {
Copy link
Copy Markdown
Contributor

@JonasKunz JonasKunz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions github-actions Bot requested a review from JonasKunz April 30, 2026 09:09
@jaydeluca jaydeluca added this pull request to the merge queue May 5, 2026
Merged via the queue into open-telemetry:main with commit bd36eea May 5, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants