Skip to content

Conversation

@denrase
Copy link
Collaborator

@denrase denrase commented Nov 26, 2025

📜 Description

  • Call captureLogs on batcher if app terminates
  • Call captureLogs on batcher if app resigns active

Introduces listeners on the AppState and observes it in a conditional (UIKit) integration.

💡 Motivation and Context

Implements missing behaviour from batch processor spec.

When the application shuts down gracefully, the BatchProcessor SHOULD forward all data in memory to the transport. The transport SHOULD keep its existing behavior, which usually stores the data to disk as an envelope. It is not required to call a transport flush. This is mostly relevant for mobile SDKs already subscribed to these hooks, such as applicationWillTerminate on iOS.

When the application moves to the background, the BatchProcessor SHOULD forward all the data in memory to the transport and stop the timer. The transport SHOULD keep its existing behavior, which usually stores the data to disk as an envelope. It is not required to call the transport flush. This is mostly relevant for mobile SDKs.

Closes #6478

💚 How did you test it?

Added tests and tested manually.

📝 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.
  • 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.

@denrase denrase changed the title Flush Logs on Terminate or Resign Active State Flush Logs on WillTerminate or WillResignActive` App State Nov 26, 2025
@denrase denrase changed the title Flush Logs on WillTerminate or WillResignActive` App State Flush Logs on WillTerminate or WillResignActive App State Nov 26, 2025
@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

❌ Patch coverage is 93.44262% with 4 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@e0809f1). Learn more about missing BASE report.
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
.../Swift/Integrations/Log/FlushLogsIntegration.swift 90.476% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main     #6909   +/-   ##
========================================
  Coverage        ?   85.092%           
========================================
  Files           ?       454           
  Lines           ?     27697           
  Branches        ?     12145           
========================================
  Hits            ?     23568           
  Misses          ?      4085           
  Partials        ?        44           
Files with missing lines Coverage Δ
SentryTestUtils/Sources/TestClient.swift 85.321% <100.000%> (ø)
Sources/Sentry/SentryClient.m 97.412% <100.000%> (ø)
...urces/Sentry/_SentryDispatchQueueWrapperInternal.m 84.615% <100.000%> (ø)
Sources/Swift/AppState/SentryAppState.swift 95.945% <ø> (ø)
Sources/Swift/AppState/SentryAppStateManager.swift 100.000% <ø> (ø)
Sources/Swift/Core/Integrations/Integrations.swift 100.000% <100.000%> (ø)
...rces/Swift/Helper/SentryDispatchQueueWrapper.swift 100.000% <100.000%> (ø)
Sources/Swift/SentryDependencyContainer.swift 98.496% <ø> (ø)
Sources/Swift/Tools/SentryLogBatcher.swift 98.540% <100.000%> (ø)
.../Swift/Integrations/Log/FlushLogsIntegration.swift 90.476% <90.476%> (ø)

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 e0809f1...7184c36. Read the comment docs.

@denrase
Copy link
Collaborator Author

denrase commented Nov 26, 2025

The app state manager is only enabled for UIKit, but the notification-equivalents for terminate/active should also be available for macOS. Is this intended behaviour?

@denrase denrase added the ready-to-merge Use this label to trigger all PR workflows label Nov 26, 2025
@denrase denrase marked this pull request as ready for review November 26, 2025 10:25
@github-actions
Copy link
Contributor

github-actions bot commented Nov 26, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1224.36 ms 1250.33 ms 25.97 ms
Size 24.14 KiB 1.02 MiB 1019.40 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
b9c733a 1195.49 ms 1220.23 ms 24.74 ms
9e0030e 1222.78 ms 1242.23 ms 19.45 ms
916edbe 1243.86 ms 1256.11 ms 12.25 ms
884b224 1221.11 ms 1255.88 ms 34.77 ms
650d802 1231.86 ms 1255.64 ms 23.78 ms
d83b35a 1212.48 ms 1237.02 ms 24.54 ms
bc0a04c 1226.83 ms 1255.04 ms 28.21 ms
ec3fc3a 1212.92 ms 1245.06 ms 32.14 ms
2a36c3f 1227.27 ms 1246.89 ms 19.63 ms
0b6776b 1230.18 ms 1262.06 ms 31.88 ms

App size

Revision Plain With Sentry Diff
b9c733a 23.74 KiB 1021.49 KiB 997.74 KiB
9e0030e 23.75 KiB 893.72 KiB 869.97 KiB
916edbe 23.75 KiB 908.41 KiB 884.66 KiB
884b224 23.75 KiB 879.55 KiB 855.80 KiB
650d802 23.74 KiB 913.13 KiB 889.39 KiB
d83b35a 23.75 KiB 913.17 KiB 889.42 KiB
bc0a04c 23.75 KiB 933.32 KiB 909.57 KiB
ec3fc3a 23.74 KiB 1022.75 KiB 999.01 KiB
2a36c3f 23.75 KiB 874.45 KiB 850.71 KiB
0b6776b 23.75 KiB 968.23 KiB 944.49 KiB

Previous results on branch: feat/flush-logs-on-app-state-change

Startup times

Revision Plain With Sentry Diff
4d08953 1219.49 ms 1252.85 ms 33.36 ms
58c01c4 1193.19 ms 1242.47 ms 49.28 ms
862c32d 1212.94 ms 1246.50 ms 33.56 ms
a6be137 1221.02 ms 1260.93 ms 39.91 ms
27d2fb4 1228.62 ms 1260.15 ms 31.53 ms
2cb9aef 1228.32 ms 1265.86 ms 37.54 ms
6b6ef93 1192.06 ms 1212.08 ms 20.02 ms
e1bf267 1215.20 ms 1241.04 ms 25.84 ms
9ee58f1 1231.78 ms 1268.67 ms 36.89 ms
5a96fbe 1223.24 ms 1239.82 ms 16.57 ms

App size

Revision Plain With Sentry Diff
4d08953 24.14 KiB 1.02 MiB 1017.81 KiB
58c01c4 24.14 KiB 1.01 MiB 1013.67 KiB
862c32d 24.14 KiB 1.02 MiB 1017.77 KiB
a6be137 24.14 KiB 1.02 MiB 1017.81 KiB
27d2fb4 24.14 KiB 1.02 MiB 1017.82 KiB
2cb9aef 24.14 KiB 1.02 MiB 1017.76 KiB
6b6ef93 24.14 KiB 1.01 MiB 1015.51 KiB
e1bf267 24.14 KiB 1.01 MiB 1015.57 KiB
9ee58f1 24.14 KiB 1.01 MiB 1013.68 KiB
5a96fbe 24.14 KiB 1.01 MiB 1015.46 KiB

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Thanks for doing this. I found a few high-level issues we need to address before I give this a closer look.

@denrase denrase changed the title Flush Logs on WillTerminate or WillResignActive App State Flush Logs on WillTerminate or WillResignActive Notifications Dec 3, 2025
@denrase denrase requested a review from philprime December 4, 2025 10:38
Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Thanks, @denrase, we're getting closer to an LGTM.

# Conflicts:
#	Sentry.xcodeproj/project.pbxproj
#	Sources/Swift/Core/Integrations/Integrations.swift
#	Sources/Swift/Integrations/Session/SessionTracker.swift
#	Sources/Swift/SentryDependencyContainer.swift
Copy link
Member

@philprime philprime left a comment

Choose a reason for hiding this comment

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

LGTM, left some feedback to consider

@denrase denrase merged commit 0af71b2 into main Dec 9, 2025
192 checks passed
@denrase denrase deleted the feat/flush-logs-on-app-state-change branch December 9, 2025 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Use this label to trigger all PR workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logs: Batch Processor Minimize Data Loss

4 participants