Skip to content

Commit

Permalink
feat: Add extra SdkInfo packages (#4637)
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich authored Dec 16, 2024
1 parent 716a5b0 commit 86e9bf2
Show file tree
Hide file tree
Showing 20 changed files with 482 additions and 107 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
### Internal

- Remove loading `integrations` names from `event.extra` (#4627)
- Add Hybrid SDKs API to add extra SDK packages (#4637)

## 8.42.0-beta.2

Expand Down
24 changes: 20 additions & 4 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
15E0A8F22411A45A00F044E3 /* SentrySession.m in Sources */ = {isa = PBXBuildFile; fileRef = 15E0A8F12411A45A00F044E3 /* SentrySession.m */; };
33042A0D29DAF79A00C60085 /* SentryExtraContextProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 33042A0C29DAF79A00C60085 /* SentryExtraContextProvider.m */; };
33042A1729DC2C4300C60085 /* SentryExtraContextProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33042A1629DC2C4300C60085 /* SentryExtraContextProviderTests.swift */; };
33C374B92D103F17004598F1 /* SentryExtraPackages.h in Headers */ = {isa = PBXBuildFile; fileRef = 33C374B82D103EE5004598F1 /* SentryExtraPackages.h */; settings = {ATTRIBUTES = (Private, ); }; };
33C374BB2D103F4D004598F1 /* SentryExtraPackages.m in Sources */ = {isa = PBXBuildFile; fileRef = 33C374BA2D103F4A004598F1 /* SentryExtraPackages.m */; };
33C374C02D104D6C004598F1 /* SentryExtraPackages.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B6D1262265F7CC600C9BE4B /* SentryExtraPackages.h */; settings = {ATTRIBUTES = (Private, ); }; };
33C374C12D104D9C004598F1 /* SentrySdkPackage.h in Headers */ = {isa = PBXBuildFile; fileRef = 33C374BE2D104A41004598F1 /* SentrySdkPackage.h */; settings = {ATTRIBUTES = (Private, ); }; };
33C374C22D104F60004598F1 /* SentrySdkPackage.m in Sources */ = {isa = PBXBuildFile; fileRef = 33C374BC2D104A31004598F1 /* SentrySdkPackage.m */; };
33EB2A912C3412E4004FED3D /* SentryWithoutUIKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 33EB2A8F2C3411AE004FED3D /* SentryWithoutUIKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
33EB2A922C341300004FED3D /* Sentry.h in Headers */ = {isa = PBXBuildFile; fileRef = 63AA76931EB9C1C200D153DE /* Sentry.h */; settings = {ATTRIBUTES = (Public, ); }; };
51B15F7E2BE88A7C0026A2F2 /* URLSessionTaskHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51B15F7D2BE88A7C0026A2F2 /* URLSessionTaskHelper.swift */; };
Expand Down Expand Up @@ -411,7 +416,6 @@
7B6C5F8726034395007F7DFF /* SentryWatchdogTerminationLogic.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B6C5F8626034395007F7DFF /* SentryWatchdogTerminationLogic.m */; };
7B6CC50224EE5A42001816D7 /* SentryHubTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6CC50124EE5A42001816D7 /* SentryHubTests.swift */; };
7B6D1261265F784000C9BE4B /* PrivateSentrySDKOnly.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7B6D1260265F784000C9BE4B /* PrivateSentrySDKOnly.mm */; };
7B6D1263265F7CC600C9BE4B /* PrivateSentrySDKOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6D1262265F7CC600C9BE4B /* PrivateSentrySDKOnlyTests.swift */; };
7B6D135C27F4605D00331ED2 /* TestEnvelopeRateLimitDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6D135B27F4605D00331ED2 /* TestEnvelopeRateLimitDelegate.swift */; };
7B6D98E924C6D336005502FA /* SentrySdkInfo+Equality.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B6D98E824C6D336005502FA /* SentrySdkInfo+Equality.m */; };
7B6D98EB24C6E84F005502FA /* SentryCrashInstallationReporterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6D98EA24C6E84F005502FA /* SentryCrashInstallationReporterTests.swift */; };
Expand Down Expand Up @@ -1072,6 +1076,10 @@
33042A0B29DAF5F400C60085 /* SentryExtraContextProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryExtraContextProvider.h; sourceTree = "<group>"; };
33042A0C29DAF79A00C60085 /* SentryExtraContextProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryExtraContextProvider.m; sourceTree = "<group>"; };
33042A1629DC2C4300C60085 /* SentryExtraContextProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryExtraContextProviderTests.swift; sourceTree = "<group>"; };
33C374B82D103EE5004598F1 /* SentryExtraPackages.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryExtraPackages.h; path = include/SentryExtraPackages.h; sourceTree = "<group>"; };
33C374BA2D103F4A004598F1 /* SentryExtraPackages.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryExtraPackages.m; sourceTree = "<group>"; };
33C374BC2D104A31004598F1 /* SentrySdkPackage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySdkPackage.m; sourceTree = "<group>"; };
33C374BE2D104A41004598F1 /* SentrySdkPackage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySdkPackage.h; path = include/SentrySdkPackage.h; sourceTree = "<group>"; };
33EB2A8F2C3411AE004FED3D /* SentryWithoutUIKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryWithoutUIKit.h; path = Public/SentryWithoutUIKit.h; sourceTree = "<group>"; };
51B15F7D2BE88A7C0026A2F2 /* URLSessionTaskHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLSessionTaskHelper.swift; sourceTree = "<group>"; };
51B15F7F2BE88D510026A2F2 /* URLSessionTaskHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionTaskHelperTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1437,7 +1445,7 @@
7B6C5F8626034395007F7DFF /* SentryWatchdogTerminationLogic.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryWatchdogTerminationLogic.m; sourceTree = "<group>"; };
7B6CC50124EE5A42001816D7 /* SentryHubTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryHubTests.swift; sourceTree = "<group>"; };
7B6D1260265F784000C9BE4B /* PrivateSentrySDKOnly.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PrivateSentrySDKOnly.mm; sourceTree = "<group>"; };
7B6D1262265F7CC600C9BE4B /* PrivateSentrySDKOnlyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivateSentrySDKOnlyTests.swift; sourceTree = "<group>"; };
7B6D1262265F7CC600C9BE4B /* SentryExtraPackages.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryExtraPackages.h; path = ../../Sources/Sentry/include/SentryExtraPackages.h; sourceTree = "<group>"; };
7B6D135B27F4605D00331ED2 /* TestEnvelopeRateLimitDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestEnvelopeRateLimitDelegate.swift; sourceTree = "<group>"; };
7B6D98E724C6D336005502FA /* SentrySdkInfo+Equality.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentrySdkInfo+Equality.h"; sourceTree = "<group>"; };
7B6D98E824C6D336005502FA /* SentrySdkInfo+Equality.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "SentrySdkInfo+Equality.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2420,6 +2428,8 @@
639889D51EDF10BE00EA7442 /* Helper */ = {
isa = PBXGroup;
children = (
33C374BE2D104A41004598F1 /* SentrySdkPackage.h */,
33C374BC2D104A31004598F1 /* SentrySdkPackage.m */,
63AA76951EB9C1C200D153DE /* SentryDefines.h */,
627E7588299F6FE40085504D /* SentryInternalDefines.h */,
0A9E917028DC7E7000FB4182 /* SentryInternalCDefines.h */,
Expand Down Expand Up @@ -2476,6 +2486,8 @@
D858FA652A29EAB3002A3503 /* SentryBinaryImageCache.m */,
D8739D152BEEA33F007D2F66 /* SentryLevelHelper.h */,
D8739D162BEEA33F007D2F66 /* SentryLevelHelper.m */,
33C374BA2D103F4A004598F1 /* SentryExtraPackages.m */,
33C374B82D103EE5004598F1 /* SentryExtraPackages.h */,
);
name = Helper;
sourceTree = "<group>";
Expand Down Expand Up @@ -2527,7 +2539,7 @@
7B0002312477F0520035FEF1 /* SentrySessionTests.m */,
63AA75951EB8AEDB00D153DE /* SentryTests.m */,
63AA75941EB8AEDB00D153DE /* Info.plist */,
7B6D1262265F7CC600C9BE4B /* PrivateSentrySDKOnlyTests.swift */,
7B6D1262265F7CC600C9BE4B /* SentryExtraPackages.h */,
7B4260332630315C00B36EDD /* SampleError.swift */,
7BAF3DB4243C743E008A5414 /* SentryClientTests.swift */,
A8AFFCD12907DA7600967CD7 /* SentryHttpStatusCodeRangeTests.swift */,
Expand Down Expand Up @@ -4005,6 +4017,7 @@
D8CB74152947246600A5F964 /* SentryEnvelopeAttachmentHeader.h in Headers */,
63FE71BA20DA4C1100CDBAE8 /* SentryCrashInstallation+Private.h in Headers */,
63FE71AE20DA4C1100CDBAE8 /* SentryCrashInstallation.h in Headers */,
33C374C02D104D6C004598F1 /* SentryExtraPackages.h in Headers */,
63FE70F120DA4C1000CDBAE8 /* SentryCrashMonitorType.h in Headers */,
7BA0C04628055F8E003E0326 /* SentryTransportAdapter.h in Headers */,
63FE717720DA4C1100CDBAE8 /* SentryCrashReportWriter.h in Headers */,
Expand Down Expand Up @@ -4085,6 +4098,7 @@
8EAE980B261E9F530073B6B3 /* SentryPerformanceTracker.h in Headers */,
63FE718520DA4C1100CDBAE8 /* SentryCrashC.h in Headers */,
8EA1ED0D2669028C00E62B98 /* SentryUIViewControllerSwizzling.h in Headers */,
33C374B92D103F17004598F1 /* SentryExtraPackages.h in Headers */,
D820CDB82BB1895F00BA339D /* SentrySessionReplayIntegration.h in Headers */,
7B98D7E425FB7A7200C5A389 /* SentryAppState.h in Headers */,
7BDEAA022632A4580001EA25 /* SentryOptions+Private.h in Headers */,
Expand All @@ -4104,6 +4118,7 @@
844EDC6F294143B900C86F34 /* SentryNSProcessInfoWrapper.h in Headers */,
D8479328278873A100BE8E99 /* SentryByteCountFormatter.h in Headers */,
63AA76981EB9C1C200D153DE /* SentryClient.h in Headers */,
33C374C12D104D9C004598F1 /* SentrySdkPackage.h in Headers */,
0A9E917128DC7E7000FB4182 /* SentryInternalCDefines.h in Headers */,
63FE711F20DA4C1000CDBAE8 /* SentryCrashObjC.h in Headers */,
7BC3936825B1AB3E004F03D3 /* SentryLevelMapper.h in Headers */,
Expand Down Expand Up @@ -4626,6 +4641,7 @@
63AA769E1EB9C57A00D153DE /* SentryError.mm in Sources */,
7B8713B026415B22006D6004 /* SentryAppStartTrackingIntegration.m in Sources */,
8E133FA225E72DEF00ABD0BF /* SentrySamplingContext.m in Sources */,
33C374BB2D103F4D004598F1 /* SentryExtraPackages.m in Sources */,
D81988C02BEBFFF70020E36C /* SentryReplayRecording.swift in Sources */,
7B6C5F8726034395007F7DFF /* SentryWatchdogTerminationLogic.m in Sources */,
7BBC827125DFD039005F1ED8 /* SentryInAppLogic.m in Sources */,
Expand Down Expand Up @@ -4805,6 +4821,7 @@
63FE710F20DA4C1000CDBAE8 /* SentryCrashNSErrorUtil.m in Sources */,
8ECC674925C23A20000E2BF6 /* SentrySpanId.m in Sources */,
6344DDB51EC309E000D9160D /* SentryCrashReportSink.m in Sources */,
33C374C22D104F60004598F1 /* SentrySdkPackage.m in Sources */,
8EAE9806261E87120073B6B3 /* SentryUIViewControllerPerformanceTracker.m in Sources */,
D81988C72BEC18E20020E36C /* SentryRRWebVideoEvent.swift in Sources */,
621F61F12BEA073A005E654F /* SentryEnabledFeaturesBuilder.swift in Sources */,
Expand Down Expand Up @@ -4919,7 +4936,6 @@
63FE721920DA66EC00CDBAE8 /* SentryCrashReportStore_Tests.m in Sources */,
7B6D98EB24C6E84F005502FA /* SentryCrashInstallationReporterTests.swift in Sources */,
7BA61EA625F21E660008CAA2 /* SentryLogTests.swift in Sources */,
7B6D1263265F7CC600C9BE4B /* PrivateSentrySDKOnlyTests.swift in Sources */,
62CFD9A92C99741100834E1B /* SentryInvalidJSONStringTests.swift in Sources */,
7BB42EF124F3B7B700D7B39A /* SentrySession+Equality.m in Sources */,
7BF9EF8B2722D58700B5BBEF /* SentryInitializeForGettingSubclassesNotCalled.m in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions SentryTestUtils/ClearTestState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,8 @@ class TestCleanup: NSObject {
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)

sentrycrash_scopesync_reset()

SentrySdkPackage.resetPackageManager()
SentryExtraPackages.clear()
}
}
2 changes: 2 additions & 0 deletions Sources/Resources/Sentry.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ framework module Sentry {
header "SentrySessionReplayIntegration-Hybrid.h"

header "SentrySdkInfo.h"
header "SentryExtraPackages.h"
header "SentrySdkPackage.h"
header "SentryInternalSerializable.h"

export *
Expand Down
6 changes: 6 additions & 0 deletions Sources/Sentry/PrivateSentrySDKOnly.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "SentryViewHierarchy.h"
#import <SentryBreadcrumb.h>
#import <SentryDependencyContainer.h>
#import <SentryExtraPackages.h>
#import <SentryFramesTracker.h>
#import <SentryScope+Private.h>
#import <SentryScreenshot.h>
Expand Down Expand Up @@ -188,6 +189,11 @@ + (NSString *)getSdkVersionString
return SentryMeta.versionString;
}

+ (void)addSdkPackage:(nonnull NSString *)name version:(nonnull NSString *)version
{
[SentryExtraPackages addPackageName:name version:version];
}

+ (NSDictionary *)getExtraContext
{
return [SentryDependencyContainer.sharedInstance.extraContextProvider getExtraContext];
Expand Down
46 changes: 46 additions & 0 deletions Sources/Sentry/SentryExtraPackages.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#import "SentryExtraPackages.h"
#import "SentryMeta.h"

NS_ASSUME_NONNULL_BEGIN

@implementation SentryExtraPackages

static NSSet<NSDictionary<NSString *, NSString *> *> *extraPackages;

+ (void)initialize
{
if (self == [SentryExtraPackages class]) {
extraPackages = [[NSSet alloc] init];
}
}

+ (void)addPackageName:(NSString *)name version:(NSString *)version
{
if (name == nil || version == nil) {
return;
}

@synchronized(extraPackages) {
NSDictionary<NSString *, NSString *> *newPackage =
@{ @"name" : name, @"version" : version };
extraPackages = [extraPackages setByAddingObject:newPackage];
}
}

+ (NSMutableSet<NSDictionary<NSString *, NSString *> *> *)getPackages
{
@synchronized(extraPackages) {
return [extraPackages mutableCopy];
}
}

#if TEST || TESTCI
+ (void)clear
{
extraPackages = [[NSSet alloc] init];
}
#endif

@end

NS_ASSUME_NONNULL_END
87 changes: 29 additions & 58 deletions Sources/Sentry/SentrySdkInfo.m
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
#import "SentrySdkInfo.h"
#import "SentryClient+Private.h"
#import "SentryExtraPackages.h"
#import "SentryHub+Private.h"
#import "SentryMeta.h"
#import "SentryOptions.h"
#import "SentrySDK+Private.h"
#import "SentrySdkPackage.h"
#import "SentrySwift.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
Expand All @@ -59,23 +36,32 @@ - (instancetype)initWithOptions:(SentryOptions *)options
}
#endif

NSMutableSet<NSDictionary<NSString *, NSString *> *> *packages =
[SentryExtraPackages getPackages];
NSDictionary<NSString *, NSString *> *sdkPackage = [SentrySdkPackage global];
if (sdkPackage != nil) {
[packages addObject:sdkPackage];
}

return [self initWithName:SentryMeta.sdkName
version:SentryMeta.versionString
integrations:integrations
features:features];
features:features
packages:[packages allObjects]];
}

- (instancetype)initWithName:(NSString *)name
version:(NSString *)version
integrations:(NSArray<NSString *> *)integrations
features:(NSArray<NSString *> *)features
packages:(NSArray<NSDictionary<NSString *, NSString *> *> *)packages
{
if (self = [super init]) {
_name = name ?: @"";
_version = version ?: @"";
_packageManager = SENTRY_PACKAGE_INFO;
_integrations = integrations ?: @[];
_features = features ?: @[];
_packages = packages ?: @[];
}

return self;
Expand All @@ -87,6 +73,7 @@ - (instancetype)initWithDict:(NSDictionary *)dict
NSString *version = @"";
NSMutableSet<NSString *> *integrations = [[NSMutableSet alloc] init];
NSMutableSet<NSString *> *features = [[NSMutableSet alloc] init];
NSMutableSet<NSDictionary<NSString *, NSString *> *> *packages = [[NSMutableSet alloc] init];

if ([dict[@"name"] isKindOfClass:[NSString class]]) {
name = dict[@"name"];
Expand All @@ -112,48 +99,32 @@ - (instancetype)initWithDict:(NSDictionary *)dict
}
}

if ([dict[@"packages"] isKindOfClass:[NSArray class]]) {
for (id item in dict[@"packages"]) {
if ([item isKindOfClass:[NSDictionary class]] &&
[item[@"name"] isKindOfClass:[NSString class]] &&
[item[@"version"] isKindOfClass:[NSString class]]) {
[packages addObject:@{ @"name" : item[@"name"], @"version" : item[@"version"] }];
}
}
}

return [self initWithName:name
version:version
integrations:[integrations allObjects]
features:[features allObjects]];
}

- (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;
}
features:[features allObjects]
packages:[packages allObjects]];
}

- (NSDictionary<NSString *, id> *)serialize
{
NSMutableDictionary *sdk = @{
return @{
@"name" : self.name,
@"version" : self.version,
@"integrations" : self.integrations,
@"features" : self.features,
}
.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
},
];
}
}

return sdk;
@"packages" : self.packages,
};
}

@end
Expand Down
Loading

0 comments on commit 86e9bf2

Please sign in to comment.