Skip to content

feat(snuba): Allow customizing attribute sort (default or natural)#334

Open
phacops wants to merge 1 commit into
mainfrom
claude/customizable-sort-options-lznu85
Open

feat(snuba): Allow customizing attribute sort (default or natural)#334
phacops wants to merge 1 commit into
mainfrom
claude/customizable-sort-options-lznu85

Conversation

@phacops

@phacops phacops commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds an opt-in sort field to the OrderBy message on both
TraceItemAttributeNamesRequest and TraceItemAttributeValuesRequest, letting
callers choose between default (lexicographic) and natural ordering when
ordering attribute names/values alphabetically.

This is a follow-up to #316, which added opt-in order_by to these two
endpoints. That change let callers pick what to order by (name/value vs.
count); this change lets them pick how the textual ordering is applied.

What changed

A new nested Sort enum is added to each OrderBy message:

Value Meaning
SORT_UNSPECIFIED (0) Defaults to SORT_DEFAULT; preserves historical behaviour when unset
SORT_DEFAULT (1) Lexicographic ordering by Unicode code point (e.g. item10 before item2)
SORT_NATURAL (2) Natural ordering — embedded digit runs compared numerically (e.g. item2 before item10)

The sort field only applies to textual columns (COLUMN_NAME /
COLUMN_VALUE) and is ignored for COLUMN_COUNT.

Backwards compatibility

The change is purely additive (new enum + new field at tag 3 on each
OrderBy). Leaving sort unset keeps the existing lexicographic ordering, so
existing callers are unaffected. Verified with buf breaking --against main
(no breaking changes) and buf lint (clean).

Generated code & tests

  • Regenerated the committed Rust bindings (rust/src/sentry_protos.snuba.v1.rs)
    via make build-rust; cargo check passes. Cargo.lock picks up the
    already-bumped sentry_protos crate version (0.34.1 → 0.35.0).
  • Added Python example tests covering the natural-sort opt-in for both the
    names and values requests, including a serialization round-trip. Full
    Python suite passes (53 tests).

Test plan

  • make build-rust regenerates with no spurious diff; cargo check passes
  • python py/generate.py + pytest py/tests/ → 53 passed
  • buf lint → clean
  • buf breaking --against '.git#branch=main' → no breaking changes

🤖 Generated with Claude Code

https://claude.ai/code/session_017A2WYa5y2PyvFt99kpe4aa


Generated by Claude Code

Add an opt-in `sort` field to the OrderBy message on both
TraceItemAttributeNamesRequest and TraceItemAttributeValuesRequest so callers
can choose between default (lexicographic) and natural ordering when ordering
attribute names/values alphabetically.

The new `Sort` enum offers SORT_DEFAULT (lexicographic, e.g. "item10" before
"item2") and SORT_NATURAL (digit runs compared numerically, e.g. "item2"
before "item10"). The field is additive and backwards compatible: leaving
`sort` unset (SORT_UNSPECIFIED) preserves the historical lexicographic
ordering, so existing callers are unaffected. It only applies to textual
columns (COLUMN_NAME / COLUMN_VALUE) and is ignored for COLUMN_COUNT.

Regenerates the committed Rust bindings and adds Python example tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017A2WYa5y2PyvFt99kpe4aa
@phacops phacops requested a review from a team as a code owner June 28, 2026 21:21
@github-actions

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow ci / buf-checks (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJun 28, 2026, 9:22 PM

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.

2 participants