Skip to content

Add a span watchers for collecting extra search metrics on-demand#7532

Open
mapno wants to merge 13 commits into
grafana:mainfrom
mapno:span-pruning-telemetry
Open

Add a span watchers for collecting extra search metrics on-demand#7532
mapno wants to merge 13 commits into
grafana:mainfrom
mapno:span-pruning-telemetry

Conversation

@mapno

@mapno mapno commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

What this PR does:

Adds a framework for adding span watchers in the TraceQL engine for collecting extra query metrics on-demand. It works for both search and metrics queries.

Watchers are enabled per-tenant via the experimental span_pruning_awareness override (operator-controlled, not user-facing). Its only user checks whether the matched spans include span-pruning summary spans, i.e. spans carrying the aggregation.is_summary attribute. Example:

overrides:
  defaults:
    read:
      span_pruning_awareness: true

Checklist

  • Tests updated
  • Documentation added
  • Changelog entry added under .chloggen/ (run make chlog-new, or make chlog-new FILENAME=<name> to override the default branch-name file; see .chloggen/README.md)

Comment thread pkg/traceql/enum_hints.go Outdated
HintDebugDataFactor = "debug_data_factor" // performance testing hint to control the possibility of non-empty fake data
HintSkipASTTransformations = "skip_ast_transformations" // list of AST transformation names to skip; unsafe hint
HintNewFetch = "spanonly_fetch" // metrics: new fetch layer (only in vParquet5)
HintReportIsSummary = "report_is_summary"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it make sense to design the syntax with single parameter for multiple observers? e.g. observe=summary,.... This would match the implementation you already have

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do like this idea for multiple observers. But I wouldn't spend too much time thinking about it. The final vision for this is going to be a global config option, so that Tempo can be always aware of the span pruning aggregation data without the user having to do it in every query. In that case the hint won't be used, and actually might need to be the inverse, somehow to disable it, which would have to be a different set of hints.

@mapno mapno Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I've replaced it by a per-tenant report_attributes override.

Comment thread pkg/traceql/observe.go Outdated
Comment thread pkg/traceql/engine.go Outdated
@mapno mapno force-pushed the span-pruning-telemetry branch from 5b91a17 to acce810 Compare June 29, 2026 11:11
@mapno mapno changed the title Add a span observers for collecting extra search metrics on-demand Add a span watchers for collecting extra search metrics on-demand Jun 30, 2026
@mapno mapno marked this pull request as ready for review June 30, 2026 12:37
Copilot AI review requested due to automatic review settings June 30, 2026 12:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a span-watcher framework in the TraceQL engine to collect additional, on-demand per-query metrics based on operator-configured watched attributes (via the per-tenant watch_attributes override). It wires watchers into both TraceQL search and metrics query execution paths and exposes results via AdditionalMetrics.

Changes:

  • Add SpanWatcher abstractions plus an initial “attribute presence” watcher and watcher orchestration (spanWatchers).
  • Integrate watchers into TraceQL search execution and metrics query evaluation (including request-scoped aggregation across metrics sub-pipelines).
  • Add per-tenant override plumbing (watch_attributes) with docs, changelog entry, and tests.

Reviewed changes

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

Show a summary per file
File Description
pkg/traceql/watch.go Introduces watcher interfaces, attribute-presence watcher, and spanWatchers coordinator.
pkg/traceql/watch_test.go Unit tests for watcher behavior and search integration coverage.
pkg/traceql/storage.go Updates Condition.CallBack documentation used by storage predicates.
pkg/traceql/options.go Adds WithWatchers compile option and stores watchers in compile options.
pkg/traceql/engine.go Installs watchers for search and emits watcher-derived AdditionalMetrics.
pkg/traceql/engine_metrics.go Makes watchers request-scoped for metrics and reports watcher stats once across sub-pipelines.
pkg/traceql/engine_metrics_test.go Adds metrics watcher tests incl. “count once across sub-pipelines” coverage.
modules/querier/querier.go Appends watcher compile options for TraceQL backend search.
modules/querier/querier_query_range.go Appends watcher compile options for metrics query-range path.
modules/overrides/watchers.go Converts per-tenant WatchAttributes specs into TraceQL compile options (warn+skip invalid).
modules/overrides/runtime_config_overrides.go Exposes WatchAttributes from runtime overrides manager.
modules/overrides/interface.go Adds WatchAttributes(userID) to overrides interface.
modules/overrides/config.go Adds watch_attributes override schema and WatchAttribute struct.
modules/overrides/config_test.go Updates legacy overrides test data to include WatchAttributes.
modules/overrides/config_legacy.go Adds WatchAttributes to legacy/new override conversions.
modules/livestore/instance_search.go Appends watcher compile options for live-store search and query-range paths.
docs/sources/tempo/configuration/_index.md Documents watch_attributes override configuration.
.chloggen/span-pruning-telemetry.yaml Adds changelog entry describing watcher framework and config.

Comment thread pkg/traceql/watch.go
Comment thread pkg/traceql/watch.go Outdated
Comment thread pkg/traceql/storage.go Outdated
# attribute, queries that match a span carrying it report a metric keyed by the
# attribute name. Applies to search and metrics queries. Operator-controlled and
# not exposed to query authors.
watch_attributes:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thinking down the road, a list of plain watch attributes might not be too useful, because we probably will want specialized logic for each one? I like the structure of the watchers and callbacks in the engine, but a better config option might be a way to enforce hints by default, i.e. this one to report, or future ones like span_pruning_awareness or extrapolate. Thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wasn't very convinced about the config either. I've updated it to be span_pruning_awareness.

Comment thread pkg/traceql/storage.go Outdated
Co-authored-by: Martin Disibio <mdisibio@gmail.com>
Copilot AI review requested due to automatic review settings July 2, 2026 16:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Comment thread pkg/traceql/engine_metrics.go
Comment thread modules/overrides/watchers.go Outdated
Copilot AI review requested due to automatic review settings July 3, 2026 13:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread pkg/traceql/watch.go
Comment thread pkg/traceql/engine.go
Comment thread pkg/traceql/engine.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants