Skip to content

feat(explore): Add sentry conventions context to trace item attributes#117913

Merged
DominikB2014 merged 12 commits into
masterfrom
feat/trace-item-attribute-context-expand
Jun 18, 2026
Merged

feat(explore): Add sentry conventions context to trace item attributes#117913
DominikB2014 merged 12 commits into
masterfrom
feat/trace-item-attribute-context-expand

Conversation

@DominikB2014

@DominikB2014 DominikB2014 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends the GET /organizations/{org}/trace-items/attributes/ endpoint so each
returned attribute can carry a context object sourced from the sentry
conventions metadata (sentry_conventions.attributes.ATTRIBUTE_METADATA).

The context is only attached when:

  1. the caller passes expand=context, and
  2. the organizations:data-browsing-attribute-context feature flag is enabled.

When the flag is disabled, the request behaves exactly as before even if
expand=context is passed.

Response shape (when expanded):

{
  "key": "transaction",
  "name": "transaction",
  "attributeSource": { "source_type": "sentry" },
  "attributeType": "string",
  "context": {
    "brief": "The sentry transaction (segment name).",
    "details": ["..."],                  // longer-form notes (additional_context)
    "examples": ["GET /"],               // normalized to a list
    "isDeprecated": true,
    "replacementAttribute": "sentry.segment.name"
  }
}

Notes / decisions

  • The metadata lookup tries the public alias first, then falls back to the
    internal name
    , mirroring _update_attribute_definitions_with_deprecations
    in search/eap/spans/attributes.py — a convention may be keyed under either.
    This matters for ~44 span attributes (e.g. span.opsentry.op).
  • metadata.deprecation can be None (492/644 attributes), which the builder
    handles.

🤖 Generated with Claude Code

The trace item attributes endpoint can now expand each attribute with the
sentry conventions metadata (brief, details, examples, deprecation, and
replacement attribute) sourced from sentry_conventions.attributes.

The context is only attached when the caller passes expand=context and the
organizations:data-browsing-attribute-context feature is enabled; otherwise
the response is unchanged. Only fields actually present in ATTRIBUTE_METADATA
are included (e.g. last_received is intentionally omitted).

The metadata lookup falls back from the public alias to the internal name,
mirroring _update_attribute_definitions_with_deprecations, since a convention
may be keyed under either name.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 17, 2026

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0c23d14. Configure here.

Comment thread src/sentry/api/endpoints/organization_trace_item_attributes.py
DominikB2014 and others added 5 commits June 17, 2026 10:25
Use isDeprecated/replacementAttribute instead of snake_case to match the
camelCase response-body convention.

Co-Authored-By: Claude <noreply@anthropic.com>
A user-supplied tag can share a name with a sentry convention (e.g.
gen_ai.request.model). Gate the convention metadata lookup on
attributeSource.source_type == sentry so user attributes never pick up
convention metadata.

Co-Authored-By: Claude <noreply@anthropic.com>
…cstring

Co-Authored-By: Claude <noreply@anthropic.com>
…istration

The flag is already registered on master.

Co-Authored-By: Claude <noreply@anthropic.com>
DominikB2014 and others added 4 commits June 17, 2026 10:35
The expand=context param is internal-only (gated behind
data-browsing-attribute-context), so hide it from the public spec while
keeping it functional.

Co-Authored-By: Claude <noreply@anthropic.com>
context is only returned via the internal expand=context param, so it
should not appear in the public response example.

Co-Authored-By: Claude <noreply@anthropic.com>
brief is always present for a known convention (0/644 missing) and
isDeprecated is always derivable, so type them as required. details,
examples, and replacementAttribute remain optional.

Co-Authored-By: Claude <noreply@anthropic.com>
…on_context

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread src/sentry/api/endpoints/organization_trace_item_attributes.py Outdated
…xt builder

Mirror the example normalization: wrap a non-list additional_context in a
list instead of iterating it into characters. Defensive — the field is
always a list or None today, but this keeps it consistent with examples.

Co-Authored-By: Claude <noreply@anthropic.com>
@DominikB2014 DominikB2014 marked this pull request as ready for review June 17, 2026 16:42
@DominikB2014 DominikB2014 requested review from a team as code owners June 17, 2026 16:42

@wmak wmak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

Comment on lines +500 to +506
span_id=uuid4().hex[:16],
organization_id=self.organization.id,
parent_span_id=None,
timestamp=before_now(days=0, minutes=10).replace(microsecond=0),
transaction="foo",
duration=100,
exclusive_time=100,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

a lot of these parameters are already defaulted in the store_segment method and aren't needed

@linear-code

linear-code Bot commented Jun 17, 2026

Copy link
Copy Markdown

BROWSE-507

…lper

The span_id, parent_span_id, transaction, duration, and exclusive_time
arguments in _store_basic_segment all match store_segment defaults and
are not asserted on, so drop them to keep the helper minimal.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@DominikB2014 DominikB2014 merged commit 2be4c82 into master Jun 18, 2026
63 of 64 checks passed
@DominikB2014 DominikB2014 deleted the feat/trace-item-attribute-context-expand branch June 18, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants