Skip to content

feat(metrics): Add trace metric enrichment with default and user attributes (RUST-169)#1031

Draft
szokeasaurusrex wants to merge 1 commit intoszokeasaurusrex/core-metrics-capturefrom
szokeasaurusrex/metrics-defaults
Draft

feat(metrics): Add trace metric enrichment with default and user attributes (RUST-169)#1031
szokeasaurusrex wants to merge 1 commit intoszokeasaurusrex/core-metrics-capturefrom
szokeasaurusrex/metrics-defaults

Conversation

@szokeasaurusrex
Copy link
Copy Markdown
Member

@szokeasaurusrex szokeasaurusrex commented Mar 9, 2026

Add metric enrichment in sentry-core so emitted trace metrics include:

  • Trace/span association: trace_id from active span or propagation
    context, span_id from active span when not explicitly set.
  • Default SDK attributes: sentry.environment, sentry.release,
    sentry.sdk.name, sentry.sdk.version, and server.address.
  • User PII attributes (user.id, user.name, user.email) gated by
    send_default_pii.
  • before_send_metric callback for filtering/modifying metrics.

Attribute merges use or_insert to preserve explicitly set metric
attributes, matching the behavior specified in
https://develop.sentry.dev/sdk/telemetry/metrics/#default-attributes
and https://develop.sentry.dev/sdk/telemetry/metrics/#user-attributes.

Scope and client enrichment logic is based on the approach from #997.

Co-authored-by: Joris Bayer joris.bayer@sentry.io

Closes #1024
Closes RUST-169

@linear-code
Copy link
Copy Markdown

linear-code bot commented Mar 9, 2026

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 9, 2026

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- Add trace metric enrichment with default and user attributes (RUST-169) ([#1031](https://github.com/getsentry/sentry-rust/pull/1031))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 4a95362

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/core-metrics-capture branch 2 times, most recently from edc47d5 to a16e498 Compare March 16, 2026 13:49
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-defaults branch 2 times, most recently from 66bb8f1 to 4f8e195 Compare March 18, 2026 17:13
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/core-metrics-capture branch 2 times, most recently from 1111bcc to 21cd8f2 Compare April 13, 2026 13:03
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-defaults branch 3 times, most recently from 1f6f1d8 to 669a78d Compare April 14, 2026 14:20
# This is the 1st commit message:

feat(metrics): Add trace metric enrichment with default and user attributes (RUST-169)

Add metric enrichment in sentry-core so emitted trace metrics include:

- Trace/span association: trace_id from active span or propagation
  context, span_id from active span when not explicitly set.
- Default SDK attributes: sentry.environment, sentry.release,
  sentry.sdk.name, sentry.sdk.version, and server.address.
- User PII attributes (user.id, user.name, user.email) gated by
  send_default_pii.
- before_send_metric callback for filtering/modifying metrics.

Attribute merges use or_insert to preserve explicitly set metric
attributes, matching the behavior specified in
https://develop.sentry.dev/sdk/telemetry/metrics/#default-attributes
and https://develop.sentry.dev/sdk/telemetry/metrics/#user-attributes.

Scope and client enrichment logic is based on the approach from #997.

Co-authored-by: Joris Bayer <joris.bayer@sentry.io>

Closes #1024
Closes [RUST-169](https://linear.app/getsentry/issue/RUST-169/add-trace-metric-default-and-user-attribute-enrichment-in-sentry-core)
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-defaults branch from b0c0361 to 4a95362 Compare April 15, 2026 12:40
szokeasaurusrex added a commit that referenced this pull request Apr 15, 2026
Prepare metrics through scope trace association before enqueueing them so metric capture inherits the current tracing context.

Set metric trace_id from the active span when present and otherwise from the propagation context, and set span_id from the active span. Keep the matching no-op scope API and the propagation-context metric test, while excluding the default attribute, user enrichment, and callback changes from [#1031](#1031).

Co-authored-by: Joris Bayer <joris.bayer@sentry.io>
Closes #1058
Closes [RUST-186](https://linear.app/getsentry/issue/RUST-186/add-trace-metric-tracing-association-in-sentry-core)
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.

1 participant