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.837%. Comparing base (7aaa0b6) to head (3d57dc6).
✅ 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.818%   86.837%   +0.018%     
=============================================
  Files          438       439        +1     
  Lines        37311     37356       +45     
  Branches     17428     17429        +1     
=============================================
+ Hits         32393     32439       +46     
+ Misses        4874      4643      -231     
- Partials        44       274      +230     
Files with missing lines Coverage Δ
SentryTestUtils/ClearTestState.swift 86.567% <100.000%> (+0.413%) ⬆️
Sources/SentrySwiftLog/SentryLogHandler.swift 86.046% <86.046%> (ø)

... and 38 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 7aaa0b6...3d57dc6. Read the comment docs.

Copy link
Contributor

github-actions bot commented Sep 25, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1227.86 ms 1255.65 ms 27.79 ms
Size 23.75 KiB 989.97 KiB 966.22 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
2ec2700 1238.28 ms 1258.82 ms 20.53 ms
d0f70ce 1226.54 ms 1247.04 ms 20.50 ms
5bf2b17 1213.53 ms 1238.54 ms 25.01 ms
efab7d3 1219.98 ms 1252.12 ms 32.14 ms
e3ebff3 1223.47 ms 1249.27 ms 25.80 ms
7b3399c 1193.35 ms 1227.38 ms 34.03 ms
3133d0e 1237.86 ms 1262.87 ms 25.01 ms
22b6996 1234.00 ms 1263.24 ms 29.24 ms
43597ba 1214.88 ms 1243.52 ms 28.65 ms
fc6557e 1226.40 ms 1249.88 ms 23.48 ms

App size

Revision Plain With Sentry Diff
2ec2700 23.75 KiB 980.80 KiB 957.05 KiB
d0f70ce 23.75 KiB 913.09 KiB 889.34 KiB
5bf2b17 23.75 KiB 913.27 KiB 889.52 KiB
efab7d3 23.75 KiB 912.78 KiB 889.03 KiB
e3ebff3 23.75 KiB 878.48 KiB 854.73 KiB
7b3399c 23.75 KiB 946.68 KiB 922.94 KiB
3133d0e 23.74 KiB 976.79 KiB 953.04 KiB
22b6996 23.75 KiB 908.02 KiB 884.27 KiB
43597ba 23.75 KiB 880.32 KiB 856.58 KiB
fc6557e 23.75 KiB 866.68 KiB 842.93 KiB

Previous results on branch: denrase/swift-log-sentry-poc

Startup times

Revision Plain With Sentry Diff
0fd08ab 1225.14 ms 1256.49 ms 31.35 ms

App size

Revision Plain With Sentry Diff
0fd08ab 23.75 KiB 995.43 KiB 971.68 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
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link
Contributor

@itaybre itaybre left a comment

Choose a reason for hiding this comment

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

Looks good, just a small comment

Comment on lines +53 to +56
# Clean up orphaned commas and fix syntax
sed -i '' '/^[[:space:]]*,$/d' $PACKAGE_FILE
sed -i '' 's/name: "Sentry\(-.*\)\?"$/name: "Sentry\1",/g' $PACKAGE_FILE
sed -i '' 's/platforms: \[\.iOS(\.v11), \.macOS(\.v10_13), \.tvOS(\.v11), \.watchOS(\.v4)\]$/platforms: [.iOS(.v11), .macOS(.v10_13), .tvOS(.v11), .watchOS(.v4)],/g' $PACKAGE_FILE
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this trying to do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One of the CI jobs is replacing dependencies with local build artefacts. This broke, as swift-log was added to our Package.swift. This code fixes those issues.

Copy link
Member

Choose a reason for hiding this comment

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

Does this only happen because of swift-log or should we do the fix in a separate PR?

@denrase denrase requested a review from itaybre October 13, 2025 14:31
.library(name: "SentrySwiftUI", targets: ["Sentry", "SentrySwiftUI", "SentryCppHelper"]),
.library(name: "SentryDistribution", targets: ["SentryDistribution"])
.library(name: "SentryDistribution", targets: ["SentryDistribution"]),
.library(name: "SentrySwiftLog", targets: ["Sentry", "SentrySwiftLog"])
Copy link
Member

Choose a reason for hiding this comment

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

m: I don't fully understand why this is another target. Is this only here because swift-log is a new dependency? Shouldn't we add it as a dependency to Sentry instead?

platforms: [.iOS(.v15), .macOS(.v12), .tvOS(.v15), .watchOS(.v8)],
products: products,
dependencies: [
.package(url: "https://github.com/apple/swift-log", from: "1.6.0")
Copy link
Member

Choose a reason for hiding this comment

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

h: So I think this is going to be a problem as soon as new swift-log version becomes available. AFAIK the SPM doesn't support peer-dependencies, so if someone uses swift-log with a version not being 1.6.0, while we depend on it, Xcode will not build because it doesn't support the same dependency with different versions like NPM.

So basically this will lock our SDK users into exactly the swift-log version we declare, requiring us to release a new SDK version with every update of swift-log, furthermore requiring users to update the Sentry SDK even though they just want a new version of swift-log. At this point I do not have a proposal how to fix this other than asking the user to "inject" their swift-log version by making it conform to a Sentry-included protocol


Removes deprecated user feedback API, this is replaced with the new feedback API (#5591)
Removes `enablePerformanceV2` option and makes this the default. The app start duration will now finish when the first frame is drawn instead of when the OS posts the UIWindowDidBecomeVisibleNotification. (#6008)
Structured Logs: Move options out of experimental (#6359)
Copy link
Member

Choose a reason for hiding this comment

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

l: Why is one list with - and one without?

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

3 participants