Skip to content

Commit

Permalink
ref: Mark options.sdkInfo as deprecated (#1960)
Browse files Browse the repository at this point in the history
options.sdkInfo is deprecated; SentryMeta is now the only source of truth. The values can be overridden by hybrid SDKs via PrivateSentrySDKOnly.
  • Loading branch information
kevinrenskers authored Jul 12, 2022
1 parent 252a8c2 commit 0be48b6
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

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

## 7.20.0

Expand Down
4 changes: 4 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
03F84D3727DD4191008FE43F /* SentrySamplingProfiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 03F84D3027DD4191008FE43F /* SentrySamplingProfiler.cpp */; };
03F84D3827DD4191008FE43F /* SentryBacktrace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 03F84D3127DD4191008FE43F /* SentryBacktrace.cpp */; };
03F9D37C2819A65C00602916 /* SentryProfilerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 03F9D37B2819A65C00602916 /* SentryProfilerTests.mm */; };
0A1C3592287D7107007D01E3 /* SentryMetaTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A1C3591287D7107007D01E3 /* SentryMetaTests.swift */; };
15360CCF2432777500112302 /* SentrySessionTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 15360CCE2432777400112302 /* SentrySessionTracker.m */; };
15360CD2243277A000112302 /* SentrySessionTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 15360CD12432779F00112302 /* SentrySessionTracker.h */; };
15360CD62432832400112302 /* SentryAutoSessionTrackingIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = 15360CD52432832400112302 /* SentryAutoSessionTrackingIntegration.m */; };
Expand Down Expand Up @@ -704,6 +705,7 @@
03F84D3027DD4191008FE43F /* SentrySamplingProfiler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SentrySamplingProfiler.cpp; path = Sources/Sentry/SentrySamplingProfiler.cpp; sourceTree = SOURCE_ROOT; };
03F84D3127DD4191008FE43F /* SentryBacktrace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SentryBacktrace.cpp; path = Sources/Sentry/SentryBacktrace.cpp; sourceTree = SOURCE_ROOT; };
03F9D37B2819A65C00602916 /* SentryProfilerTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryProfilerTests.mm; sourceTree = "<group>"; };
0A1C3591287D7107007D01E3 /* SentryMetaTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryMetaTests.swift; sourceTree = "<group>"; };
15360CCE2432777400112302 /* SentrySessionTracker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentrySessionTracker.m; sourceTree = "<group>"; };
15360CD12432779F00112302 /* SentrySessionTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentrySessionTracker.h; path = include/SentrySessionTracker.h; sourceTree = "<group>"; };
15360CD52432832400112302 /* SentryAutoSessionTrackingIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryAutoSessionTrackingIntegration.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1759,6 +1761,7 @@
630C01931EC3402C00C52CEF /* SentryKSCrashReportConverterTests.m */,
63B819131EC352A7002FDF4C /* SentryInterfacesTests.m */,
63EED6C22237989300E02400 /* SentryOptionsTest.m */,
0A1C3591287D7107007D01E3 /* SentryMetaTests.swift */,
632331F52404FFA8008D91D6 /* SentryScopeTests.m */,
7B569DFE2590EEF600B653FC /* SentryScope+Equality.h */,
7B569DFF2590EEF600B653FC /* SentryScope+Equality.m */,
Expand Down Expand Up @@ -3381,6 +3384,7 @@
7BBD18992449DE9D00427C76 /* TestRateLimits.swift in Sources */,
8E4A038625F76A7600000D77 /* TypeMapping.swift in Sources */,
7B04A9AB24EA5F8D00E710B1 /* SentryUserTests.swift in Sources */,
0A1C3592287D7107007D01E3 /* SentryMetaTests.swift in Sources */,
7BA61CCF247EB59500C130A8 /* SentryCrashUUIDConversionTests.swift in Sources */,
7BBD188D2448453600427C76 /* SentryHttpDateParserTests.swift in Sources */,
7BBD18BB24530D2600427C76 /* SentryFileManagerTests.swift in Sources */,
Expand Down
7 changes: 7 additions & 0 deletions Sources/Sentry/PrivateSentrySDKOnly.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "PrivateSentrySDKOnly.h"
#import "SentryDebugImageProvider.h"
#import "SentryInstallation.h"
#import "SentryMeta.h"
#import "SentrySDK+Private.h"
#import "SentrySerialization.h"
#import <Foundation/Foundation.h>
Expand Down Expand Up @@ -66,6 +67,12 @@ + (void)setAppStartMeasurementHybridSDKMode:(BOOL)appStartMeasurementHybridSDKMo
_appStartMeasurementHybridSDKMode = appStartMeasurementHybridSDKMode;
}

+ (void)setSdkName:(NSString *)sdkName andVersionString:(NSString *)versionString
{
SentryMeta.sdkName = sdkName;
SentryMeta.versionString = versionString;
}

#if SENTRY_HAS_UIKIT

+ (BOOL)framesTrackingMeasurementHybridSDKMode
Expand Down
5 changes: 5 additions & 0 deletions Sources/Sentry/Public/PrivateSentrySDKOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ typedef void (^SentryOnAppStartMeasurementAvailable)(
*/
+ (NSArray<SentryDebugMeta *> *)getDebugImages;

/**
* Override SDK information.
*/
+ (void)setSdkName:(NSString *)sdkName andVersionString:(NSString *)versionString;

@property (class, nullable, nonatomic, copy)
SentryOnAppStartMeasurementAvailable onAppStartMeasurementAvailable;

Expand Down
4 changes: 3 additions & 1 deletion Sources/Sentry/Public/SentryOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ NS_SWIFT_NAME(Options)

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

/**
* The maximum size for each attachment in bytes. Default is 20 MiB / 20 * 1024 * 1024 bytes.
Expand Down
8 changes: 4 additions & 4 deletions Sources/Sentry/SentryClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ - (void)captureSession:(SentrySession *)session
}

SentryEnvelopeItem *item = [[SentryEnvelopeItem alloc] initWithSession:session];
SentryEnvelopeHeader *envelopeHeader =
[[SentryEnvelopeHeader alloc] initWithId:nil sdkInfo:self.options.sdkInfo traceContext:nil];
SentryEnvelopeHeader *envelopeHeader = [[SentryEnvelopeHeader alloc] initWithId:nil
traceContext:nil];
SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader
singleItem:item];
[self captureEnvelope:envelope];
Expand Down Expand Up @@ -591,8 +591,8 @@ - (void)setSdk:(SentryEvent *)event
}

event.sdk = @{
@"name" : self.options.sdkInfo.name,
@"version" : self.options.sdkInfo.version,
@"name" : SentryMeta.sdkName,
@"version" : SentryMeta.versionString,
@"integrations" : integrations
};
}
Expand Down
13 changes: 1 addition & 12 deletions Sources/Sentry/SentryEnvelope.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,23 @@ @implementation SentryEnvelopeHeader
// id can be null if no event in the envelope or attachment related to event
- (instancetype)initWithId:(SentryId *_Nullable)eventId
{
SentrySdkInfo *sdkInfo = [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
andVersion:SentryMeta.versionString];
self = [self initWithId:eventId andSdkInfo:sdkInfo];

self = [self initWithId:eventId traceContext:nil];
return self;
}

- (instancetype)initWithId:(SentryId *_Nullable)eventId andSdkInfo:(SentrySdkInfo *_Nullable)sdkInfo
{
return [self initWithId:eventId sdkInfo:sdkInfo traceContext:nil];
}

- (instancetype)initWithId:(nullable SentryId *)eventId
traceContext:(nullable SentryTraceContext *)traceContext
{
SentrySdkInfo *sdkInfo = [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
andVersion:SentryMeta.versionString];

self = [self initWithId:eventId sdkInfo:sdkInfo traceContext:traceContext];

return self;
}

- (instancetype)initWithId:(nullable SentryId *)eventId
sdkInfo:(nullable SentrySdkInfo *)sdkInfo
traceContext:(nullable SentryTraceContext *)traceContext
{

if (self = [super init]) {
_eventId = eventId;
_sdkInfo = sdkInfo;
Expand Down
14 changes: 12 additions & 2 deletions Sources/Sentry/SentryMeta.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@ @implementation SentryMeta
// Don't remove the static keyword. If you do the compiler adds the constant name to the global
// symbol table and it might clash with other constants. When keeping the static keyword the
// compiler replaces all occurrences with the value.
static NSString *const versionString = @"7.20.0";
static NSString *const sdkName = @"sentry.cocoa";
static NSString *versionString = @"7.20.0";
static NSString *sdkName = @"sentry.cocoa";

+ (NSString *)versionString
{
return versionString;
}

+ (void)setVersionString:(NSString *)value
{
versionString = value;
}

+ (NSString *)sdkName
{
return sdkName;
}

+ (void)setSdkName:(NSString *)value
{
sdkName = value;
}

@end
14 changes: 11 additions & 3 deletions Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ - (instancetype)init
}

_inAppExcludes = [NSArray new];
_sdkInfo = [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
andVersion:SentryMeta.versionString];

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

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

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

- (SentrySdkInfo *)sdkInfo
{
return [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
andVersion:SentryMeta.versionString];
}

- (void)setBool:(id)value block:(void (^)(BOOL))block
{
// Entries in the dictionary can be NSNull. Especially, on React-Native, this can happen.
Expand Down
16 changes: 5 additions & 11 deletions Sources/Sentry/SentryTransportAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ - (void)sendEvent:(SentryEvent *)event
attachments:attachments];
[items addObjectsFromArray:additionalEnvelopeItems];

SentryEnvelopeHeader *envelopeHeader =
[[SentryEnvelopeHeader alloc] initWithId:event.eventId
sdkInfo:self.options.sdkInfo
traceContext:traceContext];
SentryEnvelopeHeader *envelopeHeader = [[SentryEnvelopeHeader alloc] initWithId:event.eventId
traceContext:traceContext];
SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader items:items];

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

SentryEnvelopeHeader *envelopeHeader =
[[SentryEnvelopeHeader alloc] initWithId:event.eventId
sdkInfo:self.options.sdkInfo
traceContext:traceContext];
SentryEnvelopeHeader *envelopeHeader = [[SentryEnvelopeHeader alloc] initWithId:event.eventId
traceContext:traceContext];

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

Expand All @@ -90,9 +86,7 @@ - (void)sendUserFeedback:(SentryUserFeedback *)userFeedback
{
SentryEnvelopeItem *item = [[SentryEnvelopeItem alloc] initWithUserFeedback:userFeedback];
SentryEnvelopeHeader *envelopeHeader =
[[SentryEnvelopeHeader alloc] initWithId:userFeedback.eventId
sdkInfo:self.options.sdkInfo
traceContext:nil];
[[SentryEnvelopeHeader alloc] initWithId:userFeedback.eventId traceContext:nil];
SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader
singleItem:item];
[self sendEnvelope:envelope];
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/include/SentryMeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Return a version string e.g: 1.2.3 (3)
*/
@property (nonatomic, class, readonly, copy) NSString *versionString;
@property (nonatomic, class, copy) NSString *versionString;

/**
* Return a string sentry-cocoa
*/
@property (nonatomic, class, readonly, copy) NSString *sdkName;
@property (nonatomic, class, copy) NSString *sdkName;

@end

Expand Down
14 changes: 14 additions & 0 deletions Tests/SentryTests/SentryMetaTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Sentry
import XCTest

class SentryMetaTest: XCTestCase {
func testChangeVersion() {
SentryMeta.versionString = "0.0.1"
XCTAssertEqual(SentryMeta.versionString, "0.0.1")
}

func testChangeName() {
SentryMeta.sdkName = "test"
XCTAssertEqual(SentryMeta.sdkName, "test")
}
}
41 changes: 40 additions & 1 deletion Tests/SentryTests/SentryOptionsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,12 @@ - (void)assertDefaultValues:(SentryOptions *)options
#if SENTRY_TARGET_PROFILING_SUPPORTED
XCTAssertEqual(NO, options.enableProfiling);
#endif

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual(SentryMeta.sdkName, options.sdkInfo.name);
XCTAssertEqual(SentryMeta.versionString, options.sdkInfo.version);
#pragma clang diagnostic pop
}

- (void)testSetValidDsn
Expand Down Expand Up @@ -585,10 +589,12 @@ - (void)testSetInvalidValidDsn

- (void)testSdkInfo
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
SentryOptions *options = [[SentryOptions alloc] init];

XCTAssertEqual(SentryMeta.sdkName, options.sdkInfo.name);
XCTAssertEqual(SentryMeta.versionString, options.sdkInfo.version);
#pragma clang diagnostic pop
}

- (void)testSetCustomSdkInfo
Expand All @@ -601,8 +607,16 @@ - (void)testSetCustomSdkInfo
didFailWithError:&error];

XCTAssertNil(error);

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual(dict[@"name"], options.sdkInfo.name);
XCTAssertEqual(dict[@"version"], options.sdkInfo.version);
#pragma clang diagnostic pop

NSDictionary *info = [[NSBundle bundleForClass:[SentryClient class]] infoDictionary];
NSString *version = [NSString stringWithFormat:@"%@", info[@"CFBundleShortVersionString"]];
SentryMeta.versionString = version;
}

- (void)testSetCustomSdkName
Expand All @@ -615,8 +629,12 @@ - (void)testSetCustomSdkName
didFailWithError:&error];

XCTAssertNil(error);

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual(dict[@"name"], options.sdkInfo.name);
XCTAssertEqual(SentryMeta.versionString, options.sdkInfo.version); // default version
#pragma clang diagnostic pop
}

- (void)testSetCustomSdkVersion
Expand All @@ -629,8 +647,16 @@ - (void)testSetCustomSdkVersion
didFailWithError:&error];

XCTAssertNil(error);

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual(SentryMeta.sdkName, options.sdkInfo.name); // default name
XCTAssertEqual(dict[@"version"], options.sdkInfo.version);
#pragma clang diagnostic pop

NSDictionary *info = [[NSBundle bundleForClass:[SentryClient class]] infoDictionary];
NSString *version = [NSString stringWithFormat:@"%@", info[@"CFBundleShortVersionString"]];
SentryMeta.versionString = version;
}

- (void)testMaxAttachmentSize
Expand Down Expand Up @@ -912,6 +938,19 @@ - (void)testUrlSessionDelegate
XCTAssertNotNil(options.urlSessionDelegate);
}

- (void)testSdkInfoChanges
{
SentryOptions *options = [self getValidOptions:@{}];
SentryMeta.sdkName = @"new name";
SentryMeta.versionString = @"0.0.6";

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual(options.sdkInfo.name, SentryMeta.sdkName);
XCTAssertEqual(options.sdkInfo.version, SentryMeta.versionString);
#pragma clang diagnostic pop
}

- (void)assertArrayEquals:(NSArray<NSString *> *)expected actual:(NSArray<NSString *> *)actual
{
XCTAssertEqualObjects([expected sortedArrayUsingSelector:@selector(compare:)],
Expand Down
4 changes: 3 additions & 1 deletion Tests/SentryTests/SentryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ - (void)testVersion
// (code was loaded inside an app for example)
// in this case, we don't care about asserting our hard coded value matches
// since this will be the app version instead of our SDK version.
XCTAssert([version isEqualToString:SentryMeta.versionString]);
XCTAssert([version isEqualToString:SentryMeta.versionString],
@"Version of bundle:%@ not equal to version of SentryMeta:%@", version,
SentryMeta.versionString);
}
}

Expand Down

0 comments on commit 0be48b6

Please sign in to comment.