Skip to content

Extend TraceRedactor interface and add ErrTraceHidden - #6811

Merged
stoewer merged 9 commits into
grafana:mainfrom
stoewer:extend-trace-redactor-interface
Apr 7, 2026
Merged

Extend TraceRedactor interface and add ErrTraceHidden#6811
stoewer merged 9 commits into
grafana:mainfrom
stoewer:extend-trace-redactor-interface

Conversation

@stoewer

@stoewer stoewer commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

What this PR does:
The method TraceRedactor.RedactTraceAttributes() can now return an error. When the error is ErrTraceHidden, this signals that the trace should not be returned. Endpoints should return 404 (not found) instead.

This allows TraceRedactor implementation to support a wider range of redaction modes.

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
Copilot AI review requested due to automatic review settings March 27, 2026 11:40
@stoewer
stoewer force-pushed the extend-trace-redactor-interface branch 2 times, most recently from 0b62d10 to bee854b Compare March 27, 2026 11:42
@stoewer stoewer changed the title Extend TraceRedactor interface and add ErrTraceHidden Mar 27, 2026

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 two main enhancements: (1) extends the frontend TraceRedactor hook to return errors (including a sentinel ErrTraceHidden to translate to 404/NotFound), and (2) adds a typed “extensions” mechanism to the per-tenant overrides configuration with registry-backed validation and legacy flat-key compatibility.

Changes:

  • Update TraceRedactor.RedactTraceAttributes to return error, add ErrTraceHidden, and translate it to HTTP 404 / gRPC NotFound in combiners.
  • Add an overrides extension registry (RegisterExtension) plus decoding/validation logic for YAML/JSON and legacy flat-key conversion.
  • Update config/runtime-config unmarshalling behavior to properly distinguish new-format extension errors vs legacy fallback, and add extensive tests for overrides extensions.

Reviewed changes

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

Show a summary per file
File Description
modules/overrides/runtime_config_overrides.go Adjust legacy-fallback logic to avoid swallowing extension-related errors.
modules/overrides/extension.go Introduce extension registry + typed decode/validate + legacy flat-key processing.
modules/overrides/extension_test.go Add coverage for extension registration, JSON/YAML marshal/unmarshal, and legacy conversions.
modules/overrides/config.go Add Overrides.Extensions support; JSON/YAML marshal/unmarshal hooks; legacy fallback adjustments.
modules/overrides/config_legacy.go Add LegacyOverrides.Extensions and JSON/YAML flattening/unflattening for legacy wire format.
modules/overrides/config_test.go Update config tag tests and field-population helper for new Extensions field.
modules/frontend/combiner/common.go Add ErrTraceHidden, update TraceRedactor interface, and map hidden traces to NotFound.
modules/frontend/combiner/trace_by_id.go Handle ErrTraceHidden as HTTP 404 for v1 trace-by-id responses.
modules/frontend/combiner/trace_by_id_v2.go Propagate redactor errors so genericCombiner can translate ErrTraceHidden.
CHANGELOG.md Add changelog entry for overrides extension mechanism.
Comment thread modules/frontend/combiner/common.go
Comment thread modules/frontend/combiner/trace_by_id.go
@stoewer
stoewer force-pushed the extend-trace-redactor-interface branch from bee854b to cb2600e Compare March 31, 2026 09:56
@stoewer
stoewer requested a review from Copilot March 31, 2026 09:59

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 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread modules/frontend/combiner/common.go Outdated
Comment thread modules/frontend/combiner/common.go Outdated
Comment thread modules/frontend/combiner/common.go
Comment thread modules/frontend/combiner/trace_by_id_v2.go
Comment thread modules/frontend/combiner/common.go

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 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread modules/frontend/combiner/trace_by_id_v2.go Outdated
Comment thread modules/frontend/combiner/trace_by_id.go
@stoewer
stoewer force-pushed the extend-trace-redactor-interface branch from 73b201c to f19bbf0 Compare March 31, 2026 10:52
Copilot AI review requested due to automatic review settings March 31, 2026 11:06

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 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread modules/frontend/combiner/common.go
Comment thread modules/frontend/combiner/common.go
Comment thread modules/frontend/combiner/trace_by_id.go Outdated
@stoewer stoewer changed the title [WIP] Extend TraceRedactor interface and add ErrTraceHidden Mar 31, 2026
@stoewer
stoewer marked this pull request as ready for review March 31, 2026 12:14
Copilot AI review requested due to automatic review settings March 31, 2026 12:14
@stoewer
stoewer requested review from mapno and mdisibio as code owners March 31, 2026 12:14

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 6 out of 6 changed files in this pull request and generated 1 comment.

Comment on lines +132 to +140
err := c.traceRedactor.RedactTraceAttributes(traceResult)
if err != nil {
if errors.Is(err, ErrTraceHidden) {
return &http.Response{
StatusCode: http.StatusNotFound,
Body: http.NoBody,
Header: http.Header{},
}, nil
}

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

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

When ErrTraceHidden is returned, HTTPFinal returns a 404 response but doesn't update the combiner's internal c.code / c.statusMessage. That means StatusCode() can still report 200 after a hidden-trace response, which is inconsistent with genericCombiner (it sets httpStatusCode = 404) and may confuse any callers relying on StatusCode() for metrics/control flow. Consider setting c.code = http.StatusNotFound (and clearing c.statusMessage) before returning the 404 response here.

Copilot uses AI. Check for mistakes.
@stoewer
stoewer merged commit 750299b into grafana:main Apr 7, 2026
26 checks passed
mattdurham pushed a commit to mattdurham/tempo that referenced this pull request Jun 18, 2026
* Add ErrTraceHidden to combiner and handle it correctly

* Reuse ErrTraceHidden text

* Use http.NoBody for empty responses

* Set internal httpStatusCode consistently in combiner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants