Skip to content

Commit 0be48b6

Browse files
ref: Mark options.sdkInfo as deprecated (#1960)
options.sdkInfo is deprecated; SentryMeta is now the only source of truth. The values can be overridden by hybrid SDKs via PrivateSentrySDKOnly.
1 parent 252a8c2 commit 0be48b6

File tree

14 files changed

+112
-37
lines changed

14 files changed

+112
-37
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
- Properly sanitize the event context and SDK information (#1943)
1313
- Don't send error 429 as `network_error` (#1957)
14+
- Deprecate not needed option `sdkInfo` (#1960)
1415

1516
## 7.20.0
1617

Sentry.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
03F84D3727DD4191008FE43F /* SentrySamplingProfiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 03F84D3027DD4191008FE43F /* SentrySamplingProfiler.cpp */; };
3636
03F84D3827DD4191008FE43F /* SentryBacktrace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 03F84D3127DD4191008FE43F /* SentryBacktrace.cpp */; };
3737
03F9D37C2819A65C00602916 /* SentryProfilerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 03F9D37B2819A65C00602916 /* SentryProfilerTests.mm */; };
38+
0A1C3592287D7107007D01E3 /* SentryMetaTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A1C3591287D7107007D01E3 /* SentryMetaTests.swift */; };
3839
15360CCF2432777500112302 /* SentrySessionTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 15360CCE2432777400112302 /* SentrySessionTracker.m */; };
3940
15360CD2243277A000112302 /* SentrySessionTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 15360CD12432779F00112302 /* SentrySessionTracker.h */; };
4041
15360CD62432832400112302 /* SentryAutoSessionTrackingIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = 15360CD52432832400112302 /* SentryAutoSessionTrackingIntegration.m */; };
@@ -704,6 +705,7 @@
704705
03F84D3027DD4191008FE43F /* SentrySamplingProfiler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SentrySamplingProfiler.cpp; path = Sources/Sentry/SentrySamplingProfiler.cpp; sourceTree = SOURCE_ROOT; };
705706
03F84D3127DD4191008FE43F /* SentryBacktrace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SentryBacktrace.cpp; path = Sources/Sentry/SentryBacktrace.cpp; sourceTree = SOURCE_ROOT; };
706707
03F9D37B2819A65C00602916 /* SentryProfilerTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryProfilerTests.mm; sourceTree = "<group>"; };
708+
0A1C3591287D7107007D01E3 /* SentryMetaTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryMetaTests.swift; sourceTree = "<group>"; };
707709
15360CCE2432777400112302 /* SentrySessionTracker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentrySessionTracker.m; sourceTree = "<group>"; };
708710
15360CD12432779F00112302 /* SentrySessionTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentrySessionTracker.h; path = include/SentrySessionTracker.h; sourceTree = "<group>"; };
709711
15360CD52432832400112302 /* SentryAutoSessionTrackingIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryAutoSessionTrackingIntegration.m; sourceTree = "<group>"; };
@@ -1759,6 +1761,7 @@
17591761
630C01931EC3402C00C52CEF /* SentryKSCrashReportConverterTests.m */,
17601762
63B819131EC352A7002FDF4C /* SentryInterfacesTests.m */,
17611763
63EED6C22237989300E02400 /* SentryOptionsTest.m */,
1764+
0A1C3591287D7107007D01E3 /* SentryMetaTests.swift */,
17621765
632331F52404FFA8008D91D6 /* SentryScopeTests.m */,
17631766
7B569DFE2590EEF600B653FC /* SentryScope+Equality.h */,
17641767
7B569DFF2590EEF600B653FC /* SentryScope+Equality.m */,
@@ -3381,6 +3384,7 @@
33813384
7BBD18992449DE9D00427C76 /* TestRateLimits.swift in Sources */,
33823385
8E4A038625F76A7600000D77 /* TypeMapping.swift in Sources */,
33833386
7B04A9AB24EA5F8D00E710B1 /* SentryUserTests.swift in Sources */,
3387+
0A1C3592287D7107007D01E3 /* SentryMetaTests.swift in Sources */,
33843388
7BA61CCF247EB59500C130A8 /* SentryCrashUUIDConversionTests.swift in Sources */,
33853389
7BBD188D2448453600427C76 /* SentryHttpDateParserTests.swift in Sources */,
33863390
7BBD18BB24530D2600427C76 /* SentryFileManagerTests.swift in Sources */,

Sources/Sentry/PrivateSentrySDKOnly.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#import "PrivateSentrySDKOnly.h"
22
#import "SentryDebugImageProvider.h"
33
#import "SentryInstallation.h"
4+
#import "SentryMeta.h"
45
#import "SentrySDK+Private.h"
56
#import "SentrySerialization.h"
67
#import <Foundation/Foundation.h>
@@ -66,6 +67,12 @@ + (void)setAppStartMeasurementHybridSDKMode:(BOOL)appStartMeasurementHybridSDKMo
6667
_appStartMeasurementHybridSDKMode = appStartMeasurementHybridSDKMode;
6768
}
6869

70+
+ (void)setSdkName:(NSString *)sdkName andVersionString:(NSString *)versionString
71+
{
72+
SentryMeta.sdkName = sdkName;
73+
SentryMeta.versionString = versionString;
74+
}
75+
6976
#if SENTRY_HAS_UIKIT
7077

7178
+ (BOOL)framesTrackingMeasurementHybridSDKMode

Sources/Sentry/Public/PrivateSentrySDKOnly.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ typedef void (^SentryOnAppStartMeasurementAvailable)(
4141
*/
4242
+ (NSArray<SentryDebugMeta *> *)getDebugImages;
4343

44+
/**
45+
* Override SDK information.
46+
*/
47+
+ (void)setSdkName:(NSString *)sdkName andVersionString:(NSString *)versionString;
48+
4449
@property (class, nullable, nonatomic, copy)
4550
SentryOnAppStartMeasurementAvailable onAppStartMeasurementAvailable;
4651

Sources/Sentry/Public/SentryOptions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ NS_SWIFT_NAME(Options)
153153

154154
/**
155155
* Describes the Sentry SDK and its configuration used to capture and transmit an event.
156+
* This is reserved for internal use, and will be removed in a future version of the SDK.
156157
*/
157-
@property (nonatomic, readonly, strong) SentrySdkInfo *sdkInfo;
158+
@property (nonatomic, readonly, strong) SentrySdkInfo *sdkInfo DEPRECATED_MSG_ATTRIBUTE(
159+
"This property will be removed in a future version of the SDK");
158160

159161
/**
160162
* The maximum size for each attachment in bytes. Default is 20 MiB / 20 * 1024 * 1024 bytes.

Sources/Sentry/SentryClient.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ - (void)captureSession:(SentrySession *)session
363363
}
364364

365365
SentryEnvelopeItem *item = [[SentryEnvelopeItem alloc] initWithSession:session];
366-
SentryEnvelopeHeader *envelopeHeader =
367-
[[SentryEnvelopeHeader alloc] initWithId:nil sdkInfo:self.options.sdkInfo traceContext:nil];
366+
SentryEnvelopeHeader *envelopeHeader = [[SentryEnvelopeHeader alloc] initWithId:nil
367+
traceContext:nil];
368368
SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader
369369
singleItem:item];
370370
[self captureEnvelope:envelope];
@@ -591,8 +591,8 @@ - (void)setSdk:(SentryEvent *)event
591591
}
592592

593593
event.sdk = @{
594-
@"name" : self.options.sdkInfo.name,
595-
@"version" : self.options.sdkInfo.version,
594+
@"name" : SentryMeta.sdkName,
595+
@"version" : SentryMeta.versionString,
596596
@"integrations" : integrations
597597
};
598598
}

Sources/Sentry/SentryEnvelope.m

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,23 @@ @implementation SentryEnvelopeHeader
2020
// id can be null if no event in the envelope or attachment related to event
2121
- (instancetype)initWithId:(SentryId *_Nullable)eventId
2222
{
23-
SentrySdkInfo *sdkInfo = [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
24-
andVersion:SentryMeta.versionString];
25-
self = [self initWithId:eventId andSdkInfo:sdkInfo];
26-
23+
self = [self initWithId:eventId traceContext:nil];
2724
return self;
2825
}
2926

30-
- (instancetype)initWithId:(SentryId *_Nullable)eventId andSdkInfo:(SentrySdkInfo *_Nullable)sdkInfo
31-
{
32-
return [self initWithId:eventId sdkInfo:sdkInfo traceContext:nil];
33-
}
34-
3527
- (instancetype)initWithId:(nullable SentryId *)eventId
3628
traceContext:(nullable SentryTraceContext *)traceContext
3729
{
3830
SentrySdkInfo *sdkInfo = [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
3931
andVersion:SentryMeta.versionString];
40-
4132
self = [self initWithId:eventId sdkInfo:sdkInfo traceContext:traceContext];
42-
4333
return self;
4434
}
4535

4636
- (instancetype)initWithId:(nullable SentryId *)eventId
4737
sdkInfo:(nullable SentrySdkInfo *)sdkInfo
4838
traceContext:(nullable SentryTraceContext *)traceContext
4939
{
50-
5140
if (self = [super init]) {
5241
_eventId = eventId;
5342
_sdkInfo = sdkInfo;

Sources/Sentry/SentryMeta.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,27 @@ @implementation SentryMeta
55
// Don't remove the static keyword. If you do the compiler adds the constant name to the global
66
// symbol table and it might clash with other constants. When keeping the static keyword the
77
// compiler replaces all occurrences with the value.
8-
static NSString *const versionString = @"7.20.0";
9-
static NSString *const sdkName = @"sentry.cocoa";
8+
static NSString *versionString = @"7.20.0";
9+
static NSString *sdkName = @"sentry.cocoa";
1010

1111
+ (NSString *)versionString
1212
{
1313
return versionString;
1414
}
1515

16+
+ (void)setVersionString:(NSString *)value
17+
{
18+
versionString = value;
19+
}
20+
1621
+ (NSString *)sdkName
1722
{
1823
return sdkName;
1924
}
2025

26+
+ (void)setSdkName:(NSString *)value
27+
{
28+
sdkName = value;
29+
}
30+
2131
@end

Sources/Sentry/SentryOptions.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ - (instancetype)init
9595
}
9696

9797
_inAppExcludes = [NSArray new];
98-
_sdkInfo = [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
99-
andVersion:SentryMeta.versionString];
10098

10199
// Set default release name
102100
if (nil != infoDict) {
@@ -303,8 +301,12 @@ - (BOOL)validateOptions:(NSDictionary<NSString *, id> *)options
303301

304302
// SentrySdkInfo already expects a dictionary with {"sdk": {"name": ..., "value": ...}}
305303
// so we're passing the whole options object.
304+
// Note: we should remove this code once the hybrid SDKs move over to the new
305+
// PrivateSentrySDKOnly setter functions.
306306
if ([options[@"sdk"] isKindOfClass:[NSDictionary class]]) {
307-
_sdkInfo = [[SentrySdkInfo alloc] initWithDict:options orDefaults:_sdkInfo];
307+
SentrySdkInfo *sdkInfo = [[SentrySdkInfo alloc] initWithDict:options];
308+
SentryMeta.versionString = sdkInfo.version;
309+
SentryMeta.sdkName = sdkInfo.name;
308310
}
309311

310312
if (nil != error && nil != *error) {
@@ -314,6 +316,12 @@ - (BOOL)validateOptions:(NSDictionary<NSString *, id> *)options
314316
}
315317
}
316318

319+
- (SentrySdkInfo *)sdkInfo
320+
{
321+
return [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
322+
andVersion:SentryMeta.versionString];
323+
}
324+
317325
- (void)setBool:(id)value block:(void (^)(BOOL))block
318326
{
319327
// Entries in the dictionary can be NSNull. Especially, on React-Native, this can happen.

Sources/Sentry/SentryTransportAdapter.m

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ - (void)sendEvent:(SentryEvent *)event
5858
attachments:attachments];
5959
[items addObjectsFromArray:additionalEnvelopeItems];
6060

61-
SentryEnvelopeHeader *envelopeHeader =
62-
[[SentryEnvelopeHeader alloc] initWithId:event.eventId
63-
sdkInfo:self.options.sdkInfo
64-
traceContext:traceContext];
61+
SentryEnvelopeHeader *envelopeHeader = [[SentryEnvelopeHeader alloc] initWithId:event.eventId
62+
traceContext:traceContext];
6563
SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader items:items];
6664

6765
[self sendEnvelope:envelope];
@@ -76,10 +74,8 @@ - (void)sendEvent:(SentryEvent *)event
7674
attachments:attachments];
7775
[items addObject:[[SentryEnvelopeItem alloc] initWithSession:session]];
7876

79-
SentryEnvelopeHeader *envelopeHeader =
80-
[[SentryEnvelopeHeader alloc] initWithId:event.eventId
81-
sdkInfo:self.options.sdkInfo
82-
traceContext:traceContext];
77+
SentryEnvelopeHeader *envelopeHeader = [[SentryEnvelopeHeader alloc] initWithId:event.eventId
78+
traceContext:traceContext];
8379

8480
SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader items:items];
8581

@@ -90,9 +86,7 @@ - (void)sendUserFeedback:(SentryUserFeedback *)userFeedback
9086
{
9187
SentryEnvelopeItem *item = [[SentryEnvelopeItem alloc] initWithUserFeedback:userFeedback];
9288
SentryEnvelopeHeader *envelopeHeader =
93-
[[SentryEnvelopeHeader alloc] initWithId:userFeedback.eventId
94-
sdkInfo:self.options.sdkInfo
95-
traceContext:nil];
89+
[[SentryEnvelopeHeader alloc] initWithId:userFeedback.eventId traceContext:nil];
9690
SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader
9791
singleItem:item];
9892
[self sendEnvelope:envelope];

0 commit comments

Comments
 (0)