Skip to content

Commit 6232a4a

Browse files
committed
Make SentrySDKSettings only visible to Swift
1 parent d6ab868 commit 6232a4a

13 files changed

+115
-287
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 8 additions & 16 deletions
Large diffs are not rendered by default.

Sources/Sentry/SentryClient.m

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -529,14 +529,8 @@ - (void)captureReplayEvent:(SentryReplayEvent *)replayEvent
529529

530530
// Hybrid SDKs may override the sdk info for a replay Event,
531531
// the same SDK should be used for the envelope header.
532-
SentrySdkInfo *sdkInfo = replayEvent.sdk
533-
? [[SentrySdkInfo alloc]
534-
initWithDict:SENTRY_UNWRAP_NULLABLE_DICT(NSString *, id, replayEvent.sdk)]
535-
: [SentrySdkInfo global];
536532
SentryEnvelopeHeader *envelopeHeader =
537-
[[SentryEnvelopeHeader alloc] initWithId:replayEvent.eventId
538-
sdkInfo:sdkInfo
539-
traceContext:nil];
533+
[[SentryEnvelopeHeader alloc] initWithId:replayEvent.eventId sdkInfo:replayEvent.sdk];
540534

541535
SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader
542536
items:@[ videoEnvelopeItem ]];
@@ -907,7 +901,7 @@ - (void)setSdk:(SentryEvent *)event
907901
return;
908902
}
909903

910-
event.sdk = [[[SentrySdkInfo alloc] initWithOptions:self.options] serialize];
904+
event.sdk = [SentrySdkInfoObjC optionsToDict:self.options];
911905
}
912906

913907
- (void)setUserInfo:(NSDictionary *_Nullable)userInfo withEvent:(SentryEvent *_Nullable)event

Sources/Swift/Helper/SentrySdkInfo.swift

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Foundation
66
* @note Both name and version are required.
77
* @see https://develop.sentry.dev/sdk/event-payloads/sdk/
88
*/
9-
@_spi(Private) @objc public final class SentrySdkInfo: NSObject, SentrySerializable {
9+
final class SentrySdkInfo {
1010

1111
@objc public static func global() -> Self {
1212
if let options = SentrySDKInternal.currentHub().getClient()?.getOptions() {
@@ -54,7 +54,7 @@ import Foundation
5454
/**
5555
* A set of settings as part of this SDK.
5656
*/
57-
@objc public let settings: SentrySDKSettings
57+
let settings: SentrySDKSettings
5858

5959
@objc public convenience init(withOptions options: Options?) {
6060
let features = SentryEnabledFeaturesBuilder.getEnabledFeatures(options: options)
@@ -77,7 +77,7 @@ import Foundation
7777
settings: SentrySDKSettings(sendDefaultPii: sendDefaultPii))
7878
}
7979

80-
@objc public init(name: String?, version: String?, integrations: [String]?, features: [String]?, packages: [[String: String]]?, settings: SentrySDKSettings) {
80+
init(name: String?, version: String?, integrations: [String]?, features: [String]?, packages: [[String: String]]?, settings: SentrySDKSettings) {
8181
self.name = name ?? ""
8282
self.version = version ?? ""
8383
self.integrations = integrations ?? []
@@ -88,39 +88,39 @@ import Foundation
8888

8989
// swiftlint:disable cyclomatic_complexity
9090
@objc
91-
public convenience init(dict: [AnyHashable: Any]) {
91+
public convenience init(dict: [AnyHashable: Any]?) {
9292
var name = ""
9393
var version = ""
9494
var integrations = Set<String>()
9595
var features = Set<String>()
9696
var packages = Set<[String: String]>()
9797
var settings = SentrySDKSettings(dict: [:])
9898

99-
if let nameValue = dict["name"] as? String {
99+
if let nameValue = dict?["name"] as? String {
100100
name = nameValue
101101
}
102102

103-
if let versionValue = dict["version"] as? String {
103+
if let versionValue = dict?["version"] as? String {
104104
version = versionValue
105105
}
106106

107-
if let integrationArray = dict["integrations"] as? [Any] {
107+
if let integrationArray = dict?["integrations"] as? [Any] {
108108
for item in integrationArray {
109109
if let integration = item as? String {
110110
integrations.insert(integration)
111111
}
112112
}
113113
}
114114

115-
if let featureArray = dict["features"] as? [Any] {
115+
if let featureArray = dict?["features"] as? [Any] {
116116
for item in featureArray {
117117
if let feature = item as? String {
118118
features.insert(feature)
119119
}
120120
}
121121
}
122122

123-
if let packageArray = dict["packages"] as? [Any] {
123+
if let packageArray = dict?["packages"] as? [Any] {
124124
for item in packageArray {
125125
if let package = item as? [String: Any],
126126
let name = package["name"] as? String,
@@ -130,7 +130,7 @@ import Foundation
130130
}
131131
}
132132

133-
if let settingsDict = dict["settings"] as? NSDictionary {
133+
if let settingsDict = dict?["settings"] as? NSDictionary {
134134
settings = SentrySDKSettings(dict: settingsDict)
135135
}
136136

@@ -156,3 +156,11 @@ import Foundation
156156
]
157157
}
158158
}
159+
160+
@_spi(Private) @objc public final class SentrySdkInfoObjC: NSObject {
161+
162+
@objc public static func optionsToDict(_ options: Options) -> [String: Any] {
163+
SentrySdkInfo(withOptions: options).serialize()
164+
}
165+
166+
}

Sources/Swift/Protocol/SentrySDKSettings.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22
* Describes the settings for the Sentry SDK
33
* @see https://develop.sentry.dev/sdk/event-payloads/sdk/
44
*/
5-
@_spi(Private) @objc public final class SentrySDKSettings: NSObject {
5+
final class SentrySDKSettings {
66

7-
@objc public override init() {
7+
init() {
88
autoInferIP = false
99
}
1010

11-
@objc public convenience init(options: Options?) {
11+
convenience init(options: Options?) {
1212
self.init(sendDefaultPii: options?.sendDefaultPii ?? false)
1313
}
1414

15-
@objc public init(sendDefaultPii: Bool) {
15+
init(sendDefaultPii: Bool) {
1616
autoInferIP = sendDefaultPii
1717
}
1818

19-
@objc public init(dict: NSDictionary) {
19+
init(dict: NSDictionary) {
2020
if let inferIp = dict["infer_ip"] as? String {
2121
autoInferIP = inferIp == "auto"
2222
} else {
2323
autoInferIP = false
2424
}
2525
}
2626

27-
@objc public var autoInferIP: Bool
27+
var autoInferIP: Bool
2828

29-
@objc public func serialize() -> NSDictionary {
29+
func serialize() -> NSDictionary {
3030
[
3131
"infer_ip": autoInferIP ? "auto" : "never"
3232
]

Sources/Swift/Tools/SentryEnvelopeHeader.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@
3131
* instances should always provide a version.
3232
* @param traceContext Current trace state.
3333
*/
34-
@objc public
3534
init(id eventId: SentryId?, sdkInfo: SentrySdkInfo?, traceContext: TraceContext?) {
3635
self.eventId = eventId
3736
self.sdkInfo = sdkInfo
3837
self.traceContext = traceContext
3938
}
40-
39+
40+
@objc public convenience init(id eventId: SentryId?, sdkInfo: [AnyHashable: Any]?) {
41+
let info = sdkInfo.map { SentrySdkInfo(dict: $0) } ?? SentrySdkInfo.global()
42+
self.init(id: eventId, sdkInfo: info, traceContext: nil)
43+
}
44+
4145
@objc public static func empty() -> Self {
4246
Self(id: nil, traceContext: nil)
4347
}
@@ -48,7 +52,7 @@
4852
* Attachments
4953
*/
5054
@objc public var eventId: SentryId?
51-
@objc public var sdkInfo: SentrySdkInfo?
55+
var sdkInfo: SentrySdkInfo?
5256
@objc public var traceContext: TraceContext?
5357

5458
/**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@testable import Sentry
2+
3+
extension SentrySdkInfo {
4+
public static func == (lhs: Sentry.SentrySdkInfo, rhs: Sentry.SentrySdkInfo) -> Bool {
5+
return lhs.name == rhs.name &&
6+
lhs.version == rhs.version &&
7+
Set(lhs.integrations) == Set(rhs.integrations) &&
8+
Set(lhs.features) == Set(rhs.features) &&
9+
Set(lhs.packages) == Set(rhs.packages) &&
10+
lhs.settings == rhs.settings
11+
}
12+
}
13+
14+
#if compiler(>=6.0)
15+
extension SentrySdkInfo: @retroactive Equatable { }
16+
#else
17+
extension SentrySdkInfo: Equatable { }
18+
#endif

Tests/SentryTests/Protocol/SentrySDKSettings+Equality.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

Tests/SentryTests/Protocol/SentrySDKSettings+Equality.m

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@testable import Sentry
2+
3+
extension SentrySDKSettings {
4+
public static func == (lhs: Sentry.SentrySDKSettings, rhs: Sentry.SentrySDKSettings) -> Bool {
5+
lhs.autoInferIP == rhs.autoInferIP
6+
}
7+
}
8+
9+
#if compiler(>=6.0)
10+
extension SentrySDKSettings: @retroactive Equatable { }
11+
#else
12+
extension SentrySDKSettings: Equatable { }
13+
#endif

Tests/SentryTests/Protocol/SentrySdkInfo+Equality.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)