-
-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(internal): Add packages
set to SentrySdkInfo
#4598
Changes from all commits
10ebd39
87299dd
a56cf84
2154692
2cc2664
b0bb91e
158e3a8
e0b0ce0
0395d31
29fe1d9
0e2ca80
e44ea4e
3b3e844
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,8 @@ - (instancetype)initWithId:(nullable SentryId *)eventId | |
traceContext:(nullable SentryTraceContext *)traceContext | ||
{ | ||
SentrySdkInfo *sdkInfo = [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName | ||
andVersion:SentryMeta.versionString]; | ||
andVersion:SentryMeta.versionString | ||
andPackages:[SentryMeta getSdkPackages]]; | ||
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Now that we touch both SDKInfo for the envelope header and the event payload, I think it would be great to merge the different implementations. To make this easier we could do this in an extra PR before adding the new packages implementation. |
||
self = [self initWithId:eventId sdkInfo:sdkInfo traceContext:traceContext]; | ||
return self; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,32 @@ | ||
#import "SentrySdkInfo.h" | ||
#import <Foundation/Foundation.h> | ||
|
||
typedef NS_ENUM(NSUInteger, SentryPackageManagerOption) { | ||
SentrySwiftPackageManager, | ||
SentryCocoaPods, | ||
SentryCarthage, | ||
SentryPackageManagerUnkown | ||
}; | ||
|
||
/** | ||
* This is required to identify the package manager used when installing sentry. | ||
*/ | ||
#if SWIFT_PACKAGE | ||
static SentryPackageManagerOption SENTRY_PACKAGE_INFO = SentrySwiftPackageManager; | ||
#elif COCOAPODS | ||
static SentryPackageManagerOption SENTRY_PACKAGE_INFO = SentryCocoaPods; | ||
#elif CARTHAGE_YES | ||
// CARTHAGE is a xcodebuild build setting with value `YES`, we need to convert it into a compiler | ||
// definition to be able to use it. | ||
static SentryPackageManagerOption SENTRY_PACKAGE_INFO = SentryCarthage; | ||
#else | ||
static SentryPackageManagerOption SENTRY_PACKAGE_INFO = SentryPackageManagerUnkown; | ||
#endif | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface SentrySdkInfo () | ||
|
||
@property (nonatomic) SentryPackageManagerOption packageManager; | ||
|
||
@end | ||
|
||
@implementation SentrySdkInfo | ||
|
||
- (instancetype)initWithName:(NSString *)name andVersion:(NSString *)version | ||
- (instancetype)initWithName:(NSString *)name | ||
andVersion:(NSString *)version | ||
andPackages:(NSSet<SentrySdkPackage *> *)packages | ||
{ | ||
if (self = [super init]) { | ||
_name = name ?: @""; | ||
_version = version ?: @""; | ||
_packageManager = SENTRY_PACKAGE_INFO; | ||
_packages = packages ?: [NSSet set]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (instancetype)initWithName:(NSString *)name andVersion:(NSString *)version | ||
{ | ||
return [self initWithName:name andVersion:version andPackages:[NSSet set]]; | ||
} | ||
|
||
- (instancetype)initWithDict:(NSDictionary *)dict | ||
{ | ||
return [self initWithDictInternal:dict orDefaults:nil]; | ||
|
@@ -58,6 +41,7 @@ | |
{ | ||
NSString *name = @""; | ||
NSString *version = @""; | ||
NSSet *packages = [NSSet set]; | ||
|
||
if (nil != dict[@"sdk"] && [dict[@"sdk"] isKindOfClass:[NSDictionary class]]) { | ||
NSDictionary<NSString *, id> *sdkInfoDict = dict[@"sdk"]; | ||
|
@@ -72,43 +56,41 @@ | |
} else if (info && info.version) { | ||
version = info.version; | ||
} | ||
} | ||
|
||
return [self initWithName:name andVersion:version]; | ||
} | ||
|
||
- (nullable NSString *)getPackageName:(SentryPackageManagerOption)packageManager | ||
{ | ||
switch (packageManager) { | ||
case SentrySwiftPackageManager: | ||
return @"spm:getsentry/%@"; | ||
case SentryCocoaPods: | ||
return @"cocoapods:getsentry/%@"; | ||
case SentryCarthage: | ||
return @"carthage:getsentry/%@"; | ||
default: | ||
return nil; | ||
if ([sdkInfoDict[@"packages"] isKindOfClass:[NSArray class]]) { | ||
NSMutableSet *newPackages = [NSMutableSet set]; | ||
for (id maybePackageDict in sdkInfoDict[@"packages"]) { | ||
if ([maybePackageDict isKindOfClass:[NSDictionary class]]) { | ||
SentrySdkPackage *package = | ||
[[SentrySdkPackage alloc] initWithDict:maybePackageDict]; | ||
if (package != nil) { | ||
[newPackages addObject:package]; | ||
} | ||
} | ||
} | ||
packages = newPackages; | ||
} else if (info && info.packages) { | ||
packages = info.packages; | ||
} | ||
} | ||
|
||
return [self initWithName:name andVersion:version andPackages:packages]; | ||
} | ||
|
||
- (NSDictionary<NSString *, id> *)serialize | ||
{ | ||
NSMutableDictionary *sdk = @{ | ||
@"name" : self.name, | ||
@"version" : self.version, | ||
} | ||
.mutableCopy; | ||
if (self.packageManager != SentryPackageManagerUnkown) { | ||
NSString *format = [self getPackageName:self.packageManager]; | ||
if (format != nil) { | ||
sdk[@"packages"] = @{ | ||
@"name" : [NSString stringWithFormat:format, self.name], | ||
@"version" : self.version | ||
}; | ||
Comment on lines
-104
to
-107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the development docs this should be an array, I don't know if this value was used anywhere, so I just updated it to the array. If it's not used I would consider removing it completely and only create packages in SentryClient (same as features, integrations...). Headers docs: https://develop.sentry.dev/sdk/data-model/envelopes/#envelope-headers SDK Info interface docs: https://develop.sentry.dev/sdk/data-model/event-payloads/sdk/ |
||
} | ||
NSMutableArray *serializedPackages = [NSMutableArray array]; | ||
for (SentrySdkPackage *package in self.packages) { | ||
[serializedPackages addObject:[package serialize]]; | ||
} | ||
|
||
return @{ @"sdk" : sdk }; | ||
return @{ | ||
@"sdk" : @ { | ||
@"name" : self.name, | ||
@"version" : self.version, | ||
@"packages" : serializedPackages, | ||
}, | ||
}; | ||
} | ||
|
||
@end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#import "SentrySdkPackage.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface SentrySdkPackage (Equality) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
- (BOOL)isEqual:(id _Nullable)object; | ||
|
||
- (NSUInteger)hash; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#import "SentrySdkPackage+Equality.h" | ||
|
||
@implementation SentrySdkPackage (Equality) | ||
|
||
- (BOOL)isEqual:(id _Nullable)object | ||
{ | ||
if (object == self) | ||
return YES; | ||
if ([self class] != [object class]) | ||
return NO; | ||
|
||
SentrySdkPackage *other = (SentrySdkPackage *)object; | ||
|
||
if (![self.name isEqualToString:other.name]) { | ||
return NO; | ||
} | ||
|
||
if (![self.version isEqualToString:other.version]) { | ||
return NO; | ||
} | ||
|
||
return YES; | ||
} | ||
|
||
- (NSUInteger)hash | ||
{ | ||
NSUInteger hash = 17; | ||
|
||
hash = hash * 23 + [self.name hash]; | ||
hash = hash * 23 + [self.version hash]; | ||
|
||
return hash; | ||
} | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## 8.42.0
.Consider moving the entry to the
## Unreleased
section, please.