feat(auto-metrics): Add experimental auto game-metrics collection - #2777
Conversation
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Features
- Add experimental auto game-metrics collection ([#2777](https://github.com/getsentry/sentry-unity/pull/2777))If none of the above apply, you can opt out of this check by adding |
ef8cb9f to
37dcb2a
Compare
37dcb2a to
8125cb7
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cb420b7. Configure here.
| <AppHangTimeout>k__BackingField: 5000 | ||
| <CaptureFailedRequests>k__BackingField: 1 | ||
| <FailedRequestStatusCodes>k__BackingField: f401000057020000 | ||
| <FailedRequestStatusCodes>k__BackingField: f401000057020000i |
There was a problem hiding this comment.
Corrupted failed-request status codes
High Severity
FailedRequestStatusCodes gained a stray trailing i in its Unity hex payload (f401000057020000i). That corrupts the serialized List<int> and can break options loading when ranges are rebuilt pairwise during SDK init.
Reviewed by Cursor Bugbot for commit cb420b7. Configure here.
| return null; | ||
| } | ||
|
|
||
| return getCurrentRtt.Invoke(transport, new object[] { ServerClientId }) as ulong?; |
There was a problem hiding this comment.
Bug: The use of as ulong? to unbox a ulong returned from reflection will always result in null, causing the network ping metric to be silently lost.
Severity: MEDIUM
Suggested Fix
Replace the as ulong? operator with an explicit cast to correctly unbox the value. The line should be changed to return (ulong?)getCurrentRtt.Invoke(transport, new object[] { ServerClientId });.
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: src/Sentry.Unity/Metrics/NetworkMetricsMonitor.cs#L133
Potential issue: In `NetworkMetricsMonitor.cs`, the code uses reflection to get the
current Round-Trip Time (RTT) via `getCurrentRtt.Invoke(...)`. This method returns a
boxed `ulong`. The code then attempts to unbox this value using the `as ulong?`
operator. According to C# semantics, the `as` operator will return `null` when
attempting to unbox a value type to its nullable counterpart, instead of performing the
unboxing conversion. As a result, the check `rtt.HasValue` on the following line will
always be false, and the ping metric will be silently dropped instead of being reported
to Sentry.
Did we get this right? 👍 / 👎 to inform future reviews.


Added experimental auto game-metrics. When enabled, the SDK periodically collects common performance metrics and sends them to Sentry via the metrics API.