Skip to content

Conversation

denrase
Copy link
Collaborator

@denrase denrase commented Sep 25, 2025

📜 Description

The Sentry swift-log integration.

Setup

  • Adds SentrySwiftLog as a target to Sentry target
  • Adds SentrySwiftLog to Package.swift
  • Add a sample call to the iOS15-SwiftUi app so you can play around with it

Implementation

  • Adds SentryLogHandler
  • sentry-log metadata is mapped to attributes and prefixed with swift-log
  • Other parameters of the log function are set as attributes and

Discussion

Here vs Own Repo

Added the integration to this repo, because it is easier for us to maintain.

On the swift-log repo integrations section is linking to the swift package index with search term swift-log. So for visibility, we'd need to have a separate swift-log-sentry repo.

https://github.com/apple/swift-log?tab=readme-ov-file#available-log-handler-backends
https://swiftpackageindex.com/search?query=swift-log

Distribution

Only distributed through SPM, as swift-log dropped support for CocoaPods. Also, we'll not be able to distribute this as a binary, as swift-log is not supporting that.

Module was not compiled with library evolution support; using it means binary compatibility for can't be guaranteed

💡 Motivation and Context

Closes #5372

💚 How did you test it?

Unit Tests
Sample App

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

Copy link

codecov bot commented Sep 25, 2025

Codecov Report

❌ Patch coverage is 86.66667% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.869%. Comparing base (c8420eb) to head (0779263).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
Sources/SentrySwiftLog/SentryLogHandler.swift 86.046% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #6286       +/-   ##
=============================================
+ Coverage   86.742%   86.869%   +0.126%     
=============================================
  Files          438       434        -4     
  Lines        37344     37271       -73     
  Branches     17462     17457        -5     
=============================================
- Hits         32393     32377       -16     
+ Misses        4907      4619      -288     
- Partials        44       275      +231     
Files with missing lines Coverage Δ
SentryTestUtils/ClearTestState.swift 86.567% <100.000%> (+0.413%) ⬆️
Sources/SentrySwiftLog/SentryLogHandler.swift 86.046% <86.046%> (ø)

... and 43 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 1fc6015...0779263. Read the comment docs.

Copy link
Contributor

github-actions bot commented Sep 25, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1225.14 ms 1256.49 ms 31.35 ms
Size 23.75 KiB 995.43 KiB 971.68 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
e0424b9 1204.23 ms 1241.08 ms 36.85 ms
795dd39 1216.88 ms 1245.47 ms 28.59 ms
856fffe 1232.69 ms 1245.80 ms 13.10 ms
ae7be93 1236.24 ms 1258.18 ms 21.94 ms
9080e6c 1221.17 ms 1247.87 ms 26.71 ms
ea5a59b 1222.87 ms 1253.47 ms 30.60 ms
2b02431 1229.63 ms 1248.98 ms 19.35 ms
5cbd333 1219.93 ms 1241.76 ms 21.83 ms
d05d866 1211.78 ms 1230.96 ms 19.18 ms
7f2f69c 1237.61 ms 1266.96 ms 29.35 ms

App size

Revision Plain With Sentry Diff
e0424b9 23.74 KiB 874.07 KiB 850.33 KiB
795dd39 23.75 KiB 908.16 KiB 884.41 KiB
856fffe 23.75 KiB 975.18 KiB 951.44 KiB
ae7be93 23.75 KiB 879.24 KiB 855.49 KiB
9080e6c 23.75 KiB 926.80 KiB 903.05 KiB
ea5a59b 23.75 KiB 874.46 KiB 850.71 KiB
2b02431 23.75 KiB 850.73 KiB 826.98 KiB
5cbd333 23.74 KiB 969.77 KiB 946.02 KiB
d05d866 23.75 KiB 878.60 KiB 854.85 KiB
7f2f69c 23.75 KiB 913.38 KiB 889.63 KiB

@denrase denrase changed the title Structured Logs: swift-log Integration Structured Logs: Add SentrySwiftLog Integration Sep 30, 2025
@denrase denrase marked this pull request as ready for review October 1, 2025 13:25
@denrase denrase requested a review from itaybre as a code owner October 1, 2025 13:26
attributes["swift-log.source"] = source
attributes["swift-log.file"] = file
attributes["swift-log.function"] = function
attributes["swift-log.line"] = line
Copy link

Choose a reason for hiding this comment

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

Bug: Log Attribute Type Mismatch Causes Test Failures

The SentryLogHandler assigns the swift-log.line attribute as a UInt to the attributes dictionary. This is inconsistent with other swift-log attributes, which are converted to strings, and conflicts with test expectations. This type mismatch may cause issues if the SentryLogger expects uniform string types.

Fix in Cursor Fix in Web

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.

Log Integration: swift-log
1 participant