Skip to content

Conversation

@philprime
Copy link
Member

@philprime philprime commented Dec 2, 2025

This PR is part of a merge-chain and should be merged one-by-one into main as soon as all of them are ready to be merged:

  1. feat(metrics): Add integration with installation by SDK #6956
  2. feat(metrics): Add implementation for metrics envelope item #6960
  3. feat(metrics): Add public API to collect count, distribution and gauge #6957

This PR must also wait for #7077 to be merged

📜 Description

This pull request introduces a new metrics API to the codebase, allowing clients to record custom metrics such as counts, distributions, and gauges. The API is exposed via the SentrySDK.metrics property and is designed for future extensibility, though the current implementation is a no-op.

This PR also adds an example UI to manually collect metrics in iOS-Swift.

💡 Motivation and Context

Closes #6949

💚 How did you test it?

  • Added unit tests

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed. → feat(apple): Add documentation for metrics sentry-docs#15822
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

TODO

  • Add Attributable and AttributeValue to support type-safe bool, string, int, float, double literal values and variables
  • Add AttributeArrayValue to support type-safe arrays without mixed types

@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against f402adb

@philprime philprime marked this pull request as draft December 2, 2025 13:42
@codecov
Copy link

codecov bot commented Dec 2, 2025

Codecov Report

❌ Patch coverage is 98.91892% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.973%. Comparing base (be43bd8) to head (f402adb).
⚠️ Report is 1 commits behind head on philprime/metrics-envelope.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ntegrations/Metrics/SentryMetricsIntegration.swift 0.000% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                        Coverage Diff                        @@
##           philprime/metrics-envelope     #6957        +/-   ##
=================================================================
+ Coverage                       7.044%   84.973%   +77.928%     
=================================================================
  Files                             430       468        +38     
  Lines                           26644     28110      +1466     
  Branches                        10356     12500      +2144     
=================================================================
+ Hits                             1877     23886     +22009     
+ Misses                          24754      4184     -20570     
- Partials                           13        40        +27     
Files with missing lines Coverage Δ
Sources/Swift/Helper/SentrySDK.swift 84.259% <ø> (+76.851%) ⬆️
.../Swift/Integrations/Metrics/SentryMetricsApi.swift 100.000% <100.000%> (ø)
...ntegrations/Metrics/SentryMetricsApiProtocol.swift 100.000% <100.000%> (ø)
...Swift/Integrations/Metrics/SentryMetricsUnit.swift 100.000% <100.000%> (ø)
Sources/Swift/Protocol/SentryMetric.swift 100.000% <ø> (+100.000%) ⬆️
...ntegrations/Metrics/SentryMetricsIntegration.swift 92.307% <0.000%> (+92.307%) ⬆️

... and 442 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be43bd8...f402adb. Read the comment docs.

@philprime philprime changed the base branch from philprime/metrics-bootstrap to philprime/metrics December 2, 2025 14:33
@philprime philprime force-pushed the philprime/metrics-public-api branch from 7158dfc to 87379ed Compare December 2, 2025 14:34
@philprime philprime force-pushed the philprime/metrics-public-api branch from 4c30f13 to 02c3573 Compare December 2, 2025 15:23
@philprime philprime changed the base branch from philprime/metrics to philprime/metrics-envelope December 2, 2025 15:26
@philprime philprime force-pushed the philprime/metrics-public-api branch from 02c3573 to 1ab754c Compare December 2, 2025 15:32
@philprime
Copy link
Member Author

@sentry review

@philprime philprime added the dontmerge A branch that absolutely should not be merged while this label is applied. label Dec 22, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentryNetworkTracker.m

@philprime philprime marked this pull request as ready for review January 9, 2026 13:18
- Changed the metrics enablement check to reference the experimental options in SentrySDKInternal.
- Adjusted the return statement for metrics integration to improve clarity and consistency.
The test was failing because it created a span without setting its traceId.
Since the fix now uses span.traceId when a span is active, the test needs
to set the span's traceId to match the propagationContext traceId for
consistency.
- Eliminated the isMetricsEnabled property from the SentryMetricsApiDependencies protocol, simplifying the dependency structure.
- Updated related code to ensure metrics integration is nullable, enhancing clarity on metrics availability.
- Adjusted tests to reflect the removal of isMetricsEnabled, ensuring they accurately simulate scenarios where metrics are disabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dontmerge A branch that absolutely should not be merged while this label is applied. ready-to-merge Use this label to trigger all PR workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants