sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

feat(metrics): Add integration with installation by SDK

Open philprime opened this issue 3 weeks ago • 3 comments

:scroll: Description

This pull request introduces a new metrics integration to the Sentry SDK for Swift, allowing users to enable metrics collection and reporting via the SDK. The changes include the addition of the enableMetrics option, implementation of the metrics integration, updates to the SDK configuration, and new tests to verify the integration. The project structure is also updated to include the new integration and its tests.

Metrics Integration Feature:

  • Added a new enableMetrics option to SentryOptions, allowing users to enable or disable metrics collection. [1] [2]
  • Implemented MetricsIntegration, which is installed when enableMetrics is set to true. [1] [2]
  • Updated the SDK wrapper and options validation to support the new enableMetrics option. [1] [2]
  • Updated the enabled features builder to include "metrics" when the feature is enabled.

:bulb: Motivation and Context

Closes #6954

:green_heart: How did you test it?

  • Added unit tests based on the existing option enableLogs
  • Added unit tests based on the session replay integration
  • Added option to enable metrics to run arguments in scheme
    • Enabled the option, ran the macOS sample app and checked that the "Integration initialized" log message shows up.

:pencil: Checklist

You have to check all boxes before merging:

  • [X] I added tests to verify the changes.
  • [X] No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • [ ] I updated the docs if needed.
  • [ ] I updated the wizard if needed.
  • [X] Review from the native team if needed.
  • [ ] No breaking change or entry added to the changelog.
  • [X] No breaking change for hybrid SDKs or communicated to hybrid SDKs.

philprime avatar Dec 02 '25 13:12 philprime

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

Generated by :no_entry_sign: dangerJS against e61661bed996f45c51987841848f5c44d23a13b0

github-actions[bot] avatar Dec 02 '25 13:12 github-actions[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 84.928%. Comparing base (771f76a) to head (e61661b). :white_check_mark: All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #6956       +/-   ##
=============================================
- Coverage   84.933%   84.928%   -0.005%     
=============================================
  Files          457       458        +1     
  Lines        27624     27635       +11     
  Branches     12144     12151        +7     
=============================================
+ Hits         23462     23470        +8     
+ Misses        4119      3907      -212     
- Partials        43       258      +215     
Files with missing lines Coverage Δ
SentryTestUtils/Sources/TestOptions.swift 100.000% <100.000%> (ø)
Sources/Swift/Core/Integrations/Integrations.swift 100.000% <100.000%> (ø)
...es/Swift/Helper/SentryEnabledFeaturesBuilder.swift 100.000% <100.000%> (ø)
...ntegrations/Metrics/SentryMetricsIntegration.swift 100.000% <100.000%> (ø)
Sources/Swift/SentryExperimentalOptions.swift 75.000% <100.000%> (+8.333%) :arrow_up:

... and 30 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 771f76a...e61661b. Read the comment docs.

codecov[bot] avatar Dec 02 '25 13:12 codecov[bot]

@cursor review @sentry review

philprime avatar Dec 02 '25 14:12 philprime

Performance metrics :rocket:

  Plain With Sentry Diff
Startup time 1205.02 ms 1237.27 ms 32.25 ms
Size 24.14 KiB 1.03 MiB 1.01 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
af848c439ac97ab7850767f9f49d7a935b511cd9 1224.02 ms 1251.00 ms 26.98 ms
2ec27000f0f0c2e2b99104488c080e9b6ea6fea2 1238.28 ms 1258.82 ms 20.53 ms
b358363efd7e81b5a9e0ecb3ee7daf003dba6754 1228.33 ms 1262.34 ms 34.01 ms
dcaec4e4f4f31a02aa5c5c409308dcc9eb9c7a0c 1209.06 ms 1246.02 ms 36.96 ms
5ff1b04b314290120c468597d0d1add73e15bf04 1226.00 ms 1259.98 ms 33.98 ms
1b9991e062e58b3eca64ce9b3a4ced2a8ca0aae2 1233.45 ms 1256.61 ms 23.17 ms
f8cad3cab6dfd77a717640313a4208d27fc41b54 1217.94 ms 1257.96 ms 40.02 ms
5cfc76877e04e23aca2f156286738a33882cd485 1220.74 ms 1245.06 ms 24.32 ms
650d8026fd8bf70270211b709910dfe2454660a4 1231.86 ms 1255.64 ms 23.78 ms
5ec90e0df18400cbc7615eb74351d1c74216ed59 1235.57 ms 1258.45 ms 22.88 ms

App size

Revision Plain With Sentry Diff
af848c439ac97ab7850767f9f49d7a935b511cd9 24.14 KiB 1.01 MiB 1012.94 KiB
2ec27000f0f0c2e2b99104488c080e9b6ea6fea2 23.75 KiB 980.80 KiB 957.05 KiB
b358363efd7e81b5a9e0ecb3ee7daf003dba6754 23.75 KiB 987.92 KiB 964.18 KiB
dcaec4e4f4f31a02aa5c5c409308dcc9eb9c7a0c 24.15 KiB 1.01 MiB 1014.80 KiB
5ff1b04b314290120c468597d0d1add73e15bf04 23.75 KiB 1.01 MiB 1016.24 KiB
1b9991e062e58b3eca64ce9b3a4ced2a8ca0aae2 23.75 KiB 908.01 KiB 884.26 KiB
f8cad3cab6dfd77a717640313a4208d27fc41b54 23.75 KiB 1.01 MiB 1016.13 KiB
5cfc76877e04e23aca2f156286738a33882cd485 23.75 KiB 850.73 KiB 826.98 KiB
650d8026fd8bf70270211b709910dfe2454660a4 23.74 KiB 913.13 KiB 889.39 KiB
5ec90e0df18400cbc7615eb74351d1c74216ed59 23.74 KiB 872.67 KiB 848.92 KiB

Previous results on branch: philprime/metrics-bootstrap

Startup times

Revision Plain With Sentry Diff
1fc93d0bdb3445096b15fd5db0cd74ec392a73d8 1231.06 ms 1261.37 ms 30.31 ms
c17fb00bdea540635aba2a28b309d05906a33e00 1213.18 ms 1244.28 ms 31.10 ms
b0e93524725794959be3ab81c4bf8fd9bb5d7fda 1229.50 ms 1265.81 ms 36.31 ms
2d018e1e8f05f191199b7b1dc2f439ada894b7bc 1227.67 ms 1245.79 ms 18.12 ms
94a1efd66ca54b59247e16b561208f40f528a899 1212.39 ms 1250.19 ms 37.80 ms
40a71d5221e56bb78349ecc7ad52359a336c0d89 1221.24 ms 1263.70 ms 42.46 ms

App size

Revision Plain With Sentry Diff
1fc93d0bdb3445096b15fd5db0cd74ec392a73d8 24.14 KiB 1.03 MiB 1.00 MiB
c17fb00bdea540635aba2a28b309d05906a33e00 24.14 KiB 1.03 MiB 1.00 MiB
b0e93524725794959be3ab81c4bf8fd9bb5d7fda 24.14 KiB 1.03 MiB 1.01 MiB
2d018e1e8f05f191199b7b1dc2f439ada894b7bc 24.14 KiB 1.03 MiB 1.01 MiB
94a1efd66ca54b59247e16b561208f40f528a899 24.14 KiB 1.03 MiB 1.00 MiB
40a71d5221e56bb78349ecc7ad52359a336c0d89 24.14 KiB 1.03 MiB 1.01 MiB

github-actions[bot] avatar Dec 15 '25 12:12 github-actions[bot]

After reconsideration and learnings while working on #6957 I decided that I will move this feature to be marked as "experimental" first to keep some leeway to react if the public API using Swift Language features such as ExpressibleByInt is not working as expected.

philprime avatar Dec 17 '25 11:12 philprime