feat(metrics): Attach default SDK attributes to metrics#1062
Open
szokeasaurusrex wants to merge 1 commit intoszokeasaurusrex/metrics-pub-functionsfrom
Open
feat(metrics): Attach default SDK attributes to metrics#1062szokeasaurusrex wants to merge 1 commit intoszokeasaurusrex/metrics-pub-functionsfrom
szokeasaurusrex wants to merge 1 commit intoszokeasaurusrex/metrics-pub-functionsfrom
Conversation
bf6da5b to
d0adf84
Compare
d0adf84 to
c95db91
Compare
c95db91 to
68a5482
Compare
|
68a5482 to
0ebbcf6
Compare
e2abb12 to
9f8e156
Compare
0ebbcf6 to
efcf784
Compare
9f8e156 to
3d71e21
Compare
efcf784 to
8a5dd6f
Compare
3d71e21 to
045da81
Compare
szokeasaurusrex
added a commit
that referenced
this pull request
Apr 21, 2026
Set these metric attributes by default: - `sentry.environment` - `sentry.release` - `sentry.sdk.name` - `sentry.sdk.version` - `server.address` Preserve explicitly set metric attributes when applying those defaults. Stacked on #1061 Co-authored-by: Joris Bayer <joris.bayer@sentry.io> Closes #1059 Closes [RUST-187](https://linear.app/getsentry/issue/RUST-187/add-trace-metric-default-attribute-enrichment-in-sentry-core)
8a5dd6f to
2b6b592
Compare
045da81 to
3da189d
Compare
szokeasaurusrex
added a commit
that referenced
this pull request
Apr 21, 2026
Set these metric attributes by default: - `sentry.environment` - `sentry.release` - `sentry.sdk.name` - `sentry.sdk.version` - `server.address` Preserve explicitly set metric attributes when applying those defaults. Stacked on #1061 Co-authored-by: Joris Bayer <joris.bayer@sentry.io> Closes #1059 Closes [RUST-187](https://linear.app/getsentry/issue/RUST-187/add-trace-metric-default-attribute-enrichment-in-sentry-core)
2b6b592 to
092db6b
Compare
3da189d to
1b0c9be
Compare
szokeasaurusrex
added a commit
that referenced
this pull request
Apr 21, 2026
Set these metric attributes by default: - `sentry.environment` - `sentry.release` - `sentry.sdk.name` - `sentry.sdk.version` - `server.address` Preserve explicitly set metric attributes when applying those defaults. Stacked on #1061 Co-authored-by: Joris Bayer <joris.bayer@sentry.io> Closes #1059 Closes [RUST-187](https://linear.app/getsentry/issue/RUST-187/add-trace-metric-default-attribute-enrichment-in-sentry-core)
092db6b to
9838831
Compare
fda826a to
1b0c9be
Compare
szokeasaurusrex
added a commit
that referenced
this pull request
Apr 22, 2026
Set these metric attributes by default: - `sentry.environment` - `sentry.release` - `sentry.sdk.name` - `sentry.sdk.version` - `server.address` Preserve explicitly set metric attributes when applying those defaults. Stacked on #1061 Co-authored-by: Joris Bayer <joris.bayer@sentry.io> Closes #1059 Closes [RUST-187](https://linear.app/getsentry/issue/RUST-187/add-trace-metric-default-attribute-enrichment-in-sentry-core)
9838831 to
60371a2
Compare
Comment on lines
+579
to
585
|
|
||
| for (key, val) in &self.default_metric_attributes { | ||
| metric.attributes.entry(key.clone()).or_insert(val.clone()); | ||
| } | ||
|
|
||
| Some(metric) | ||
| } |
There was a problem hiding this comment.
Bug: capture_metric performs unnecessary work in prepare_metric even when metrics are disabled, as it lacks an early return guard to check if enable_metrics is false.
Severity: MEDIUM
Suggested Fix
Add an early return guard at the beginning of the capture_metric function to check the self.options.enable_metrics flag. If it's false, the function should return immediately, similar to how capture_log handles disabled logs. This will prevent the unnecessary execution of prepare_metric.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: sentry-core/src/client.rs#L579-L585
Potential issue: When `enable_metrics` is set to `false` in `ClientOptions`, the
`capture_metric` function is still called and proceeds to execute `prepare_metric`. This
function performs non-trivial work, including applying scope data, cloning attributes,
and inserting them into the metric. However, since the `metrics_batcher` is `None` when
metrics are disabled, the prepared metric is immediately discarded. This results in
wasteful CPU and memory usage in production scenarios where metrics are disabled at
runtime. This behavior is inconsistent with `capture_log`, which includes an early guard
for its corresponding feature flag.
Did we get this right? 👍 / 👎 to inform future reviews.
93692bd to
cd20001
Compare
szokeasaurusrex
added a commit
that referenced
this pull request
Apr 23, 2026
Set these metric attributes by default: - `sentry.environment` - `sentry.release` - `sentry.sdk.name` - `sentry.sdk.version` - `server.address` Preserve explicitly set metric attributes when applying those defaults. Stacked on #1061 Co-authored-by: Joris Bayer <joris.bayer@sentry.io> Closes #1059 Closes [RUST-187](https://linear.app/getsentry/issue/RUST-187/add-trace-metric-default-attribute-enrichment-in-sentry-core)
60371a2 to
7f844e8
Compare
cd20001 to
d383c6c
Compare
szokeasaurusrex
added a commit
that referenced
this pull request
Apr 23, 2026
Set these metric attributes by default: - `sentry.environment` - `sentry.release` - `sentry.sdk.name` - `sentry.sdk.version` - `server.address` Preserve explicitly set metric attributes when applying those defaults. Stacked on #1061 Co-authored-by: Joris Bayer <joris.bayer@sentry.io> Closes #1059 Closes [RUST-187](https://linear.app/getsentry/issue/RUST-187/add-trace-metric-default-attribute-enrichment-in-sentry-core)
7f844e8 to
208b3ae
Compare
d383c6c to
07acfeb
Compare
szokeasaurusrex
added a commit
that referenced
this pull request
Apr 23, 2026
Set these metric attributes by default: - `sentry.environment` - `sentry.release` - `sentry.sdk.name` - `sentry.sdk.version` - `server.address` Preserve explicitly set metric attributes when applying those defaults. Stacked on #1061 Co-authored-by: Joris Bayer <joris.bayer@sentry.io> Closes #1059 Closes [RUST-187](https://linear.app/getsentry/issue/RUST-187/add-trace-metric-default-attribute-enrichment-in-sentry-core)
208b3ae to
f30b17a
Compare
207d6fc to
0c98e2f
Compare
Set these metric attributes by default: - `sentry.environment` - `sentry.release` - `sentry.sdk.name` - `sentry.sdk.version` - `server.address` Preserve explicitly set metric attributes when applying those defaults. Stacked on #1061 Co-authored-by: Joris Bayer <joris.bayer@sentry.io> Closes #1059 Closes [RUST-187](https://linear.app/getsentry/issue/RUST-187/add-trace-metric-default-attribute-enrichment-in-sentry-core)
f30b17a to
31ee7b5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Set these metric attributes by default:
sentry.environmentsentry.releasesentry.sdk.namesentry.sdk.versionserver.addressPreserve explicitly set metric attributes when applying those defaults.
Stacked on #1073
Co-authored-by: Joris Bayer joris.bayer@sentry.io
Closes #1059
Closes RUST-187