Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Transactions for crashes #4504

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

philipphofmann
Copy link
Member

@philipphofmann philipphofmann commented Nov 5, 2024

📜 Description

Finishes the transaction bound to the scope when the app crashes and stores it to disk. This experimental feature is disabled by default. You can enable it via the option enableTracingWhenCrashing.

I'm sorry about the large diff, but the PR only makes sense in one significant change. The largest part is the tests.

Docs PR: getsentry/sentry-docs#11732.

💡 Motivation and Context

Fixes GH-2306

💚 How did you test it?

Unit tests, simulator, and a release build via TestFlight.

CleanShot 2024-11-05 at 10 52 37@2x

https://sentry-sdks.sentry.io/issues/6044162827/events/4e25fdce217445b5ab3ecd6eb906a77e/?node=txn-efa80d62c9a4472fa8cfef87320638d2&project=5428557

📝 Checklist

You have to check all boxes before merging:

  • I reviewed the submitted code.
  • 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.
  • 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.

🔮 Next steps

Copy link

github-actions bot commented Nov 5, 2024

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

Generated by 🚫 dangerJS against 65e2095

Copy link

github-actions bot commented Nov 5, 2024

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1217.90 ms 1249.32 ms 31.42 ms
Size 21.90 KiB 728.19 KiB 706.29 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
ddb4778 1245.36 ms 1254.16 ms 8.80 ms
020745f 1222.64 ms 1253.54 ms 30.90 ms
18d491a 1229.78 ms 1252.67 ms 22.90 ms
077e940 1227.31 ms 1246.51 ms 19.20 ms
c319795 1256.18 ms 1266.87 ms 10.69 ms
cc31630 1235.22 ms 1252.51 ms 17.29 ms
94e1968 1234.41 ms 1252.63 ms 18.22 ms
216bdf9 1202.57 ms 1215.45 ms 12.88 ms
bb5dc7d 1240.44 ms 1266.45 ms 26.01 ms
46f5eb8 1200.09 ms 1231.38 ms 31.29 ms

App size

Revision Plain With Sentry Diff
ddb4778 21.58 KiB 414.92 KiB 393.34 KiB
020745f 22.84 KiB 403.13 KiB 380.29 KiB
18d491a 21.58 KiB 544.87 KiB 523.29 KiB
077e940 21.58 KiB 706.97 KiB 685.39 KiB
c319795 20.76 KiB 431.99 KiB 411.22 KiB
cc31630 21.58 KiB 694.58 KiB 672.99 KiB
94e1968 21.58 KiB 614.74 KiB 593.15 KiB
216bdf9 21.58 KiB 418.13 KiB 396.54 KiB
bb5dc7d 22.85 KiB 412.98 KiB 390.13 KiB
46f5eb8 20.76 KiB 432.37 KiB 411.61 KiB

Previous results on branch: feat/transactions-for-crashes

Startup times

Revision Plain With Sentry Diff
8222b3d 1212.98 ms 1240.35 ms 27.37 ms
88aa4f6 1230.12 ms 1258.31 ms 28.18 ms
fa979fd 1234.69 ms 1255.37 ms 20.67 ms

App size

Revision Plain With Sentry Diff
8222b3d 21.90 KiB 728.22 KiB 706.32 KiB
88aa4f6 21.90 KiB 728.19 KiB 706.29 KiB
fa979fd 21.90 KiB 728.17 KiB 706.27 KiB

@philipphofmann
Copy link
Member Author

@brustolin, I still need to fix some problems with the context before you can review this.

Copy link

codecov bot commented Nov 5, 2024

Codecov Report

Attention: Patch coverage is 97.72296% with 12 lines in your changes missing coverage. Please review.

Project coverage is 91.483%. Comparing base (522f8da) to head (65e2095).

Files with missing lines Patch % Lines
Sources/Sentry/SentrySpotlightTransport.m 0.000% 3 Missing ⚠️
Sources/SentryCrash/Recording/SentryCrashC.c 78.571% 3 Missing ⚠️
Sources/Sentry/SentryTracer.m 96.969% 2 Missing ⚠️
...es/Sentry/SentryWatchdogTerminationScopeObserver.m 0.000% 2 Missing ⚠️
...ts/SentryTests/Transaction/SentryTracerTests.swift 97.368% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #4504       +/-   ##
=============================================
+ Coverage   91.436%   91.483%   +0.046%     
=============================================
  Files          616       616               
  Lines        68863     69332      +469     
  Branches     24707     24861      +154     
=============================================
+ Hits         62966     63427      +461     
- Misses        5803      5813       +10     
+ Partials        94        92        -2     
Files with missing lines Coverage Δ
SentryTestUtils/TestClient.swift 85.350% <100.000%> (+0.382%) ⬆️
SentryTestUtils/TestTransport.swift 87.500% <100.000%> (+2.500%) ⬆️
SentryTestUtils/TestTransportAdapter.swift 72.727% <100.000%> (+6.060%) ⬆️
Sources/Sentry/SentryClient.m 98.701% <100.000%> (+0.020%) ⬆️
Sources/Sentry/SentryCrashIntegration.m 99.159% <100.000%> (+0.112%) ⬆️
Sources/Sentry/SentryCrashReportConverter.m 96.049% <100.000%> (+0.049%) ⬆️
Sources/Sentry/SentryCrashScopeObserver.m 96.396% <100.000%> (+0.134%) ⬆️
Sources/Sentry/SentryHttpTransport.m 98.098% <100.000%> (+0.021%) ⬆️
Sources/Sentry/SentryHub.m 99.072% <100.000%> (+0.017%) ⬆️
Sources/Sentry/SentryOptions.m 98.698% <100.000%> (+0.007%) ⬆️
... and 19 more

... and 7 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 522f8da...65e2095. Read the comment docs.

@philipphofmann philipphofmann marked this pull request as ready for review November 5, 2024 15:27
Comment on lines +546 to +573
SentryTransaction *transaction = [self toTransaction];

#if SENTRY_TARGET_PROFILING_SUPPORTED
if (self.isProfiling) {
NSDate *startTimestamp;

# if SENTRY_HAS_UIKIT
if (appStartMeasurement != nil) {
startTimestamp = appStartMeasurement.runtimeInitTimestamp;
}
# endif // SENTRY_HAS_UIKIT

if (startTimestamp == nil) {
startTimestamp = self.startTimestamp;
}
if (!SENTRY_ASSERT_RETURN(startTimestamp != nil,
@"A transaction with a profile should have a start timestamp already. We will "
@"assign the current time but this will be incorrect.")) {
startTimestamp = [SentryDependencyContainer.sharedInstance.dateProvider date];
}

sentry_captureTransactionWithProfile(
self.hub, self.dispatchQueue, transaction, startTimestamp);
return;
}
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

[_hub captureTransaction:transaction withScope:_hub.scope];
Copy link
Member Author

Choose a reason for hiding this comment

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

This code was already here in a previous version. I only moved it to a different method.

@@ -97,7 +97,7 @@ - (instancetype)initWithScope:(SentryScope *)scope
[_fingerprintArray addObjectsFromArray:[scope fingerprints]];
[_attachmentArray addObjectsFromArray:[scope attachments]];

self.propagationContext = [[SentryPropagationContext alloc] init];
self.propagationContext = scope.propagationContext;
Copy link
Member Author

Choose a reason for hiding this comment

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

I will open an extra PR for this change before merging this PR, as it's a small bug fix that deserves it's own PR.

@philipphofmann
Copy link
Member Author

@brustolin, this is ready for review now.

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.

Finish and capture transaction/span bound to the Scope in case of a fatal crash
1 participant