Skip to content

Commit 8bccc72

Browse files
authored
Structured Logs: Add SentrySwiftLog Integration (#6286)
1 parent 1655116 commit 8bccc72

File tree

16 files changed

+1788
-10
lines changed

16 files changed

+1788
-10
lines changed

.github/actions/prepare-package.swift/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ runs:
4343
env:
4444
PACKAGE_FILE: ${{ inputs.package-file }}
4545
run: |
46-
sed -i '' 's/url.*//g' $PACKAGE_FILE
46+
# Remove Sentry binary framework URLs and convert checksums to paths
47+
sed -i '' 's/url: "https:\/\/github\.com\/getsentry\/sentry-cocoa\/releases\/download\/.*"//g' $PACKAGE_FILE
4748
sed -i '' 's/checksum: ".*" \/\/Sentry-Static/path: "Sentry.xcframework.zip"/g' $PACKAGE_FILE
4849
sed -i '' 's/checksum: ".*" \/\/Sentry-Dynamic-WithARM64e/path: "Sentry-Dynamic-WithARM64e.xcframework.zip"/g' $PACKAGE_FILE
4950
sed -i '' 's/checksum: ".*" \/\/Sentry-Dynamic/path: "Sentry-Dynamic.xcframework.zip"/g' $PACKAGE_FILE
5051
sed -i '' 's/checksum: ".*" \/\/Sentry-WithoutUIKitOrAppKit-WithARM64e/path: "Sentry-WithoutUIKitOrAppKit-WithARM64e.xcframework.zip"/g' $PACKAGE_FILE
5152
sed -i '' 's/checksum: ".*" \/\/Sentry-WithoutUIKitOrAppKit/path: "Sentry-WithoutUIKitOrAppKit.xcframework.zip"/g' $PACKAGE_FILE
53+
# Clean up orphaned commas and fix syntax
54+
sed -i '' '/^[[:space:]]*,$/d' $PACKAGE_FILE
55+
sed -i '' 's/name: "Sentry\(-.*\)\?"$/name: "Sentry\1",/g' $PACKAGE_FILE
56+
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

.github/workflows/test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ jobs:
330330
device: "iPhone 15 Pro"
331331
scheme: "SentrySwiftUI"
332332

333+
# iOS 17 - Use pre-installed iOS 17.5 runtime on macOS-14 with Xcode 15.4
334+
- name: iOS 17 SentrySwiftLog
335+
runs-on: macos-14
336+
xcode: "15.4"
337+
test-destination-os: "17.5"
338+
platform: "iOS"
339+
create_device: true
340+
device: "iPhone 15 Pro"
341+
scheme: "SentrySwiftLog"
342+
333343
# tvOS 18
334344
- name: tvOS 18 Sentry
335345
runs-on: macos-15

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
This option is still disabled by default and will be enabled in a future major release.
4848
- Move `enableDataSwizzling` from experimental options to top-level options (#6592). This option remains enabled by default.
4949
- Add `sentry.replay_id` attribute to logs ([#6515](https://github.com/getsentry/sentry-cocoa/pull/6515))
50+
- Structured Logs: Add `SentrySwiftLog` Integration (#6286)
5051

5152
### Fixes
5253

Package.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ var products: [Product] = [
1616
.library(name: "Sentry-WithoutUIKitOrAppKit", targets: ["Sentry-WithoutUIKitOrAppKit", "SentryCppHelper"]),
1717
.library(name: "Sentry-WithoutUIKitOrAppKit-WithARM64e", targets: ["Sentry-WithoutUIKitOrAppKit-WithARM64e", "SentryCppHelper"]),
1818
.library(name: "SentrySwiftUI", targets: ["Sentry", "SentrySwiftUI", "SentryCppHelper"]),
19-
.library(name: "SentryDistribution", targets: ["SentryDistribution"])
19+
.library(name: "SentryDistribution", targets: ["SentryDistribution"]),
20+
.library(name: "SentrySwiftLog", targets: ["Sentry", "SentrySwiftLog"])
2021
]
2122

2223
var targets: [Target] = [
@@ -45,21 +46,31 @@ var targets: [Target] = [
4546
url: "https://github.com/getsentry/sentry-cocoa/releases/download/8.57.1/Sentry-WithoutUIKitOrAppKit-WithARM64e.xcframework.zip",
4647
checksum: "6f3b991969a02f02878d052d0edf7076110f0ea577f84b2c5ad706a9bd302c54" //Sentry-WithoutUIKitOrAppKit-WithARM64e
4748
),
48-
.target (
49+
.target(
4950
name: "SentrySwiftUI",
5051
dependencies: ["Sentry", "SentryInternal"],
5152
path: "Sources/SentrySwiftUI",
5253
exclude: ["SentryInternal/", "module.modulemap"],
5354
linkerSettings: [
5455
.linkedFramework("Sentry")
55-
]),
56+
]
57+
),
58+
.target(
59+
name: "SentrySwiftLog",
60+
dependencies: ["Sentry", .product(name: "Logging", package: "swift-log")],
61+
path: "Sources/SentrySwiftLog",
62+
linkerSettings: [
63+
.linkedFramework("Sentry")
64+
]
65+
),
5666
.target(
5767
name: "SentryInternal",
5868
path: "Sources/SentrySwiftUI",
5969
sources: [
6070
"SentryInternal/"
6171
],
62-
publicHeadersPath: "SentryInternal/"),
72+
publicHeadersPath: "SentryInternal/"
73+
),
6374
.target(
6475
name: "SentryCppHelper",
6576
dependencies: ["Sentry"],
@@ -101,7 +112,7 @@ if let env = env, String(cString: env, encoding: .utf8) == "1" {
101112
name: "SentryObjc",
102113
dependencies: ["SentrySwift"],
103114
path: "Sources",
104-
exclude: ["Sentry/SentryDummyPublicEmptyClass.m", "Sentry/SentryDummyPrivateEmptyClass.m", "Swift", "SentrySwiftUI", "Resources", "Configuration", "SentryCppHelper", "SentryDistribution", "SentryDistributionTests"],
115+
exclude: ["Sentry/SentryDummyPublicEmptyClass.m", "Sentry/SentryDummyPrivateEmptyClass.m", "Swift", "SentrySwiftUI", "SentrySwiftLog", "Resources", "Configuration", "SentryCppHelper", "SentryDistribution", "SentryDistributionTests"],
105116
cSettings: [
106117
.headerSearchPath("Sentry/include/HybridPublic"),
107118
.headerSearchPath("Sentry"),
@@ -118,6 +129,12 @@ let package = Package(
118129
name: "Sentry",
119130
platforms: [.iOS(.v15), .macOS(.v12), .tvOS(.v15), .watchOS(.v8)],
120131
products: products,
132+
dependencies: [
133+
// SPM doesn't support peer-dependencies, so users are locked into our declared version.
134+
// Using `from: "1.6.0"` covers 1.6.0 < 2.0.0, resolving minor versions automatically.
135+
// See develop-docs/DECISIONS.md for discussion.
136+
.package(url: "https://github.com/apple/swift-log", from: "1.6.0")
137+
],
121138
targets: targets,
122139
cxxLanguageStandard: .cxx14
123140
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"configurations" : [
3+
{
4+
"id" : "EBB4F92C-3CA9-47E0-8589-7934881F1E4B",
5+
"name" : "Configuration 1",
6+
"options" : {
7+
8+
}
9+
}
10+
],
11+
"defaultOptions" : {
12+
"codeCoverage" : true
13+
},
14+
"testTargets" : [
15+
{
16+
"target" : {
17+
"containerPath" : "container:Sentry.xcodeproj",
18+
"identifier" : "9241AC1A2EBA38CC00E611ED",
19+
"name" : "SentrySwiftLogTests"
20+
}
21+
}
22+
],
23+
"version" : 1
24+
}

Samples/iOS-Swift/iOS-Swift.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ targets:
3232
- target: iOS-SwiftClip
3333
- target: SentrySampleShared/SentrySampleShared
3434
- target: iOS-Swift-ShareExtension
35+
- target: Sentry/SentrySwiftLog
3536
configFiles:
3637
Debug: iOS-Swift.xcconfig
3738
Release: iOS-Swift.xcconfig

Samples/iOS-Swift/iOS-Swift/AppDelegate.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import SentrySampleShared
22
import UIKit
33

4+
import Logging
5+
import SentrySwiftLog
6+
47
@UIApplicationMain
58
class AppDelegate: UIResponder, UIApplicationDelegate {
69
private var randomDistributionTimer: Timer?
@@ -24,11 +27,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2427

2528
SentrySDKWrapper.shared.startSentry()
2629
SampleAppDebugMenu.shared.display()
27-
30+
2831
if #available(iOS 15.0, *) {
2932
metricKit.receiveReports()
3033
}
3134

35+
// Use structured logs with swift-log
36+
LoggingSystem.bootstrap { _ in
37+
return SentryLogHandler(logLevel: .trace)
38+
}
39+
let logger = Logger(label: "io.sentry.iOS-Swift")
40+
logger.trace(
41+
"[iOS-Swift] didFinishLaunchingWithOptions",
42+
metadata: ["foo": "bar"],
43+
source: "iOS"
44+
)
45+
3246
return true
3347
}
3448

Samples/iOS15-SwiftUI/iOS15-SwiftUI/ContentView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ struct ContentView: View {
88
await captureErrorAsync()
99
}
1010
}
11-
1211
func captureErrorAsync() async {
1312
let error = NSError(domain: "SampleErrorDomain", code: 1, userInfo: [NSLocalizedDescriptionKey: "Object does not exist"])
1413
SentrySDK.capture(error: error)

0 commit comments

Comments
 (0)