Skip to content

[processor/spanpruning] Add span pruning conditions#49026

Open
portertech wants to merge 16 commits into
open-telemetry:mainfrom
portertech:conditions
Open

[processor/spanpruning] Add span pruning conditions#49026
portertech wants to merge 16 commits into
open-telemetry:mainfrom
portertech:conditions

Conversation

@portertech

@portertech portertech commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Add OTTL condition filtering to span pruning processor

Description

This PR adds optional OTTL conditions filtering to the span pruning processor, letting users restrict pruning to only the traces they care about instead of pruning everything. It builds on the existing core pruning, parent recursion, histogram buckets, attribute-loss analysis, and outlier analysis.

Changes

New feature: Selective pruning with OTTL conditions

By default the processor prunes every trace. This feature lets you scope pruning to a subset of traces using OTTL span-context expressions, so you can target noisy services while leaving the rest of your trace data untouched.

  • Matching: a trace is pruned when at least one span in it matches any configured condition (OR semantics across conditions and spans)
  • Default behavior preserved: when conditions is empty or unset, all traces are pruned exactly as before
  • Validation: blank/whitespace-only condition entries are rejected at config time, and OTTL syntax is compiled and validated at factory time
  • Self-contained OTTL wiring: conditions are compiled with ottlspan using only public pkg/ottl APIs (StandardConverters plus IsRootSpan), avoiding the internal filterottl package

Visibility is provided through:

  1. Counter metric:
    • otelcol_processor_spanpruning_traces_skipped - total traces skipped because no span matched the configured conditions

Configuration options:

processors:
  spanpruning:
    # OTTL conditions to select which traces to prune.
    # When empty, all traces are pruned (default behavior).
    # When set, only traces where at least one span matches any condition are pruned.
    conditions:
      - 'resource.attributes["service.name"] == "loki-query-engine"'
      - 'attributes["db.system"] == "postgresql"'

When conditions is empty, behavior is unchanged.

Testing

  • Unit tests for the OTTL helpers (span function parsing, including the IsRootSpan function, and newBoolExprForSpan condition compilation)
  • Config validation tests for conditions (blank-entry rejection and nil-slice defaults)
  • Processor tests covering the condition-filtering behavior: matching traces are pruned, non-matching traces pass through unchanged, multiple conditions OR together, empty conditions still prune all traces, and the traces_skipped metric is recorded for skipped traces
  • go test ./..., go vet ./..., gofmt -l ., and golangci-lint run are all passing/clean

Documentation

Updated README with an OTTL condition filtering section (behavior table, syntax, common examples, and use cases), the new config field, and the traces_skipped metric; added the counter to metadata.yaml and the generated documentation.md. Added the pkg/ottl dependency and crosslink replaces to go.mod/go.sum.

@portertech portertech marked this pull request as ready for review June 11, 2026 23:50
@portertech portertech requested a review from a team as a code owner June 11, 2026 23:50
@portertech portertech requested a review from braydonk June 11, 2026 23:50
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.

2 participants