Skip to content

chore: Refactor SentryAttributes into a separate class#4936

Open
jamescrosswell wants to merge 5 commits intomainfrom
sentry-attributes
Open

chore: Refactor SentryAttributes into a separate class#4936
jamescrosswell wants to merge 5 commits intomainfrom
sentry-attributes

Conversation

@jamescrosswell
Copy link
Collaborator

Before closing #4912 I figured we could extract some of the refactorings that might be useful in other PRs dealing with Attributes. Basically there's some functionality that is only accessible in the SentryMetrics class at the moment, but which will be needed by any other classes that also have Attributes.

#skip-changelog

@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@jamescrosswell jamescrosswell changed the title Refactored SentryAttributes into a separate class chore: Refactor SentryAttributes into a separate class Feb 19, 2026
@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 81.25000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.86%. Comparing base (f201b65) to head (ecf30ae).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
src/Sentry/Protocol/SentryAttributes.cs 76.59% 9 Missing and 2 partials ⚠️
src/Sentry/SentryMetric.Factory.cs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4936      +/-   ##
==========================================
- Coverage   73.90%   73.86%   -0.04%     
==========================================
  Files         496      497       +1     
  Lines       17951    17938      -13     
  Branches     3516     3511       -5     
==========================================
- Hits        13266    13250      -16     
- Misses       3824     3831       +7     
+ Partials      861      857       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamescrosswell jamescrosswell marked this pull request as ready for review February 20, 2026 04:39
Copy link

@cursor cursor bot left a comment

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.

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

return false;
}
internal bool TryGetAttribute(string key, [NotNullWhen(true)] out string? value) =>
_attributes.TryGetAttribute(key, out value);
Copy link

Choose a reason for hiding this comment

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

Dropped Type metadata check in SentryLog.TryGetAttribute

Low Severity

The internal SentryLog.TryGetAttribute(string, out string?) previously checked attribute.Type == "string" (metadata-based), but the new delegation to SentryAttributes.TryGetAttribute<string> only checks attribute.Value is string (runtime type). This means attributes stored via the public SetAttribute(string, object) with a string value (which sets Type = null) will now be returned by the string overload, where before they would not. While likely an improvement, it's a silent semantic change that could affect callers relying on the stricter Type-based filtering.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Flash0ver what do you think about this? Do you want to restore the previous code/behaviour or OK with this?

@jamescrosswell jamescrosswell requested a review from Flash0ver March 5, 2026 22:39
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