diff --git a/Samples/SentrySampleShared/SentrySampleShared/SpanObserver.swift b/Samples/SentrySampleShared/SentrySampleShared/SpanObserver.swift index ec9531c79ae..b11e5aa3ce2 100644 --- a/Samples/SentrySampleShared/SentrySampleShared/SpanObserver.swift +++ b/Samples/SentrySampleShared/SentrySampleShared/SpanObserver.swift @@ -10,7 +10,7 @@ public class SpanObserver: NSObject { } convenience init?(callback: @escaping (Span) -> Void) { - guard let span = SentrySDK.span else { return nil } + guard let span = SentrySDKSwift.span else { return nil } self.init(span: span) self.performOnFinish(callback: callback) } diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 5a7adfa2d09..9b98bbbfc2b 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -1119,6 +1119,8 @@ FAE2DAB82E1F317900262307 /* SentryProfilingSwiftHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = FAE2DAB72E1F317900262307 /* SentryProfilingSwiftHelpers.m */; }; FAE2DABA2E1F318900262307 /* SentryProfilingSwiftHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE2DAB92E1F318900262307 /* SentryProfilingSwiftHelpers.h */; }; FAE5798D2E7D9D4C00B710F9 /* SentrySysctl.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE579872E7D9D4900B710F9 /* SentrySysctl.swift */; }; + FAE57A252E819A8300B710F9 /* SentrySDK.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE57A1F2E819A8000B710F9 /* SentrySDK.h */; settings = {ATTRIBUTES = (Public, ); }; }; + FAE57A272E819ADC00B710F9 /* SentrySDK.m in Sources */ = {isa = PBXBuildFile; fileRef = FAE57A262E819ADA00B710F9 /* SentrySDK.m */; }; FAE80C242E4695B40010A595 /* SentryEvent+Serialize.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE80C232E4695AE0010A595 /* SentryEvent+Serialize.h */; }; FAEC270E2DF3526000878871 /* SentryUserFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */; }; FAEC273D2DF3933A00878871 /* NSData+Unzip.m in Sources */ = {isa = PBXBuildFile; fileRef = FAEC273C2DF3933200878871 /* NSData+Unzip.m */; }; @@ -2466,6 +2468,8 @@ FAE2DAB72E1F317900262307 /* SentryProfilingSwiftHelpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryProfilingSwiftHelpers.m; sourceTree = ""; }; FAE2DAB92E1F318900262307 /* SentryProfilingSwiftHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryProfilingSwiftHelpers.h; path = Sources/Sentry/include/SentryProfilingSwiftHelpers.h; sourceTree = SOURCE_ROOT; }; FAE579872E7D9D4900B710F9 /* SentrySysctl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySysctl.swift; sourceTree = ""; }; + FAE57A1F2E819A8000B710F9 /* SentrySDK.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySDK.h; path = Public/SentrySDK.h; sourceTree = ""; }; + FAE57A262E819ADA00B710F9 /* SentrySDK.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySDK.m; sourceTree = ""; }; FAE80C232E4695AE0010A595 /* SentryEvent+Serialize.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryEvent+Serialize.h"; path = "include/SentryEvent+Serialize.h"; sourceTree = ""; }; FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUserFeedback.swift; sourceTree = ""; }; FAEC273C2DF3933200878871 /* NSData+Unzip.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+Unzip.m"; sourceTree = ""; }; @@ -2900,6 +2904,8 @@ 639889D51EDF10BE00EA7442 /* Helper */ = { isa = PBXGroup; children = ( + FAE57A1F2E819A8000B710F9 /* SentrySDK.h */, + FAE57A262E819ADA00B710F9 /* SentrySDK.m */, 63AA76951EB9C1C200D153DE /* SentryDefines.h */, 627E7588299F6FE40085504D /* SentryInternalDefines.h */, 0A9E917028DC7E7000FB4182 /* SentryInternalCDefines.h */, @@ -4919,6 +4925,7 @@ 8E133FA625E72EB400ABD0BF /* SentrySamplingContext.h in Headers */, 0A9BF4E428A114B50068D266 /* SentryViewHierarchyIntegration.h in Headers */, D8BBD32728FD9FC00011F850 /* SentrySwift.h in Headers */, + FAE57A252E819A8300B710F9 /* SentrySDK.h in Headers */, 84CFA4CE2C9E0CA3008DA5F4 /* SentryUserFeedbackIntegration.h in Headers */, 8482FA9B2DD7C397000E9283 /* SentryFeedbackAPI.h in Headers */, 8E4E7C7425DAAB49006AB9E2 /* SentrySpanProtocol.h in Headers */, @@ -5959,6 +5966,7 @@ 63FE710B20DA4C1000CDBAE8 /* SentryCrashMach.c in Sources */, 63FE707720DA4C1000CDBAE8 /* SentryDictionaryDeepSearch.m in Sources */, FACEED132E3179A10007B4AC /* SentyOptionsInternal.m in Sources */, + FAE57A272E819ADC00B710F9 /* SentrySDK.m in Sources */, 8482FA9C2DD7C397000E9283 /* SentryFeedbackAPI.m in Sources */, 7BC9A20628F41781001E7C4C /* SentryMeasurementUnit.m in Sources */, 63FE71A020DA4C1100CDBAE8 /* SentryCrashInstallation.m in Sources */, diff --git a/Sources/Sentry/PrivateSentrySDKOnly.m b/Sources/Sentry/PrivateSentrySDKOnly.m index d82a14874af..a359de3d9be 100644 --- a/Sources/Sentry/PrivateSentrySDKOnly.m +++ b/Sources/Sentry/PrivateSentrySDKOnly.m @@ -363,7 +363,7 @@ + (NSString *__nullable)getReplayId { __block NSString *__nullable replayId; - [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { replayId = scope.replayId; }]; + [SentrySDKSwift configureScope:^(SentryScope *_Nonnull scope) { replayId = scope.replayId; }]; return replayId; } diff --git a/Sources/Sentry/Public/Sentry.h b/Sources/Sentry/Public/Sentry.h index d1f1919853b..04189c74583 100644 --- a/Sources/Sentry/Public/Sentry.h +++ b/Sources/Sentry/Public/Sentry.h @@ -34,6 +34,7 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[]; # import # import # import +# import # import # import # import diff --git a/Sources/Sentry/Public/SentrySDK.h b/Sources/Sentry/Public/SentrySDK.h new file mode 100644 index 00000000000..f3fd63ef172 --- /dev/null +++ b/Sources/Sentry/Public/SentrySDK.h @@ -0,0 +1,416 @@ +#if !SDK_V9 + +# import + +@class SentryOptions; +@class SentryEvent; +@class SentryScope; +@class SentryId; +@class SentryTransactionContext; +@class SentryUserFeedback; +@class SentryUser; +@class SentryFeedback; +@class SentryBreadcrumb; +@class SentryReplayApi; +@class SentryLogger; +@class SentryUser; +@class SentryFeedbackAPI; + +@protocol SentrySpan; + +@interface SentrySDK : NSObject + +@property (nullable, class, nonatomic, readonly) id span; + +/// Indicates whether the Sentry SDK is enabled. +@property (class, nonatomic, readonly) BOOL isEnabled; + +# if SENTRY_TARGET_REPLAY_SUPPORTED +/** + * API to control session replay + */ +@property (class, nonatomic, readonly) SentryReplayApi *_Nonnull replay; +# endif + +/// API to access Sentry logs +@property (class, nonatomic, readonly) SentryLogger *_Nonnull logger; + +/// Inits and configures Sentry (SentryHub, SentryClient) and sets up all +/// integrations. Make sure to set a valid DSN. note: Call this method on the main thread. When +/// calling it from a background thread, the SDK starts on the main thread async. ++ (void)startWithOptions:(SentryOptions *_Nonnull)options NS_SWIFT_NAME(start(options:)); + +/// Inits and configures Sentry (SentryHub, SentryClient) and sets up all +/// integrations. Make sure to set a valid DSN. note: Call this method on the main thread. When +/// calling it from a background thread, the SDK starts on the main thread async. ++ (void)startWithConfigureOptions:(void (^_Nonnull)(SentryOptions *_Nonnull))configureOptions + NS_SWIFT_NAME(start(configureOptions:)); + +/// Captures a manually created event and sends it to Sentry. +/// \param event The event to send to Sentry. +/// +/// +/// returns: +/// The SentryId of the event or SentryId.empty if the event is not sent. ++ (SentryId *_Nonnull)captureEvent:(SentryEvent *_Nonnull)event NS_SWIFT_NAME(capture(event:)); + +/// Captures a manually created event and sends it to Sentry. Only the data in this scope object +/// will be added to the event. The global scope will be ignored. +/// \param event The event to send to Sentry. +/// +/// \param scope The scope containing event metadata. +/// +/// +/// returns: +/// The SentryId of the event or SentryId.empty if the event is not sent. ++ (SentryId *_Nonnull)captureEvent:(SentryEvent *_Nonnull)event + withScope:(SentryScope *_Nonnull)scope + NS_SWIFT_NAME(capture(event:scope:)); + +/// Captures a manually created event and sends it to Sentry. Maintains the global scope but mutates +/// scope data for only this call. +/// \param event The event to send to Sentry. +/// +/// \param block The block mutating the scope only for this call. +/// +/// +/// returns: +/// The SentryId of the event or SentryId.empty if the event is not sent. ++ (SentryId *_Nonnull)captureEvent:(SentryEvent *_Nonnull)event + withScopeBlock:(void (^_Nonnull)(SentryScope *_Nonnull))block + NS_SWIFT_NAME(capture(event:block:)); + +/// Creates a transaction, binds it to the hub and returns the instance. +/// \param name The transaction name. +/// +/// \param operation Short code identifying the type of operation the span is measuring. +/// +/// +/// returns: +/// The created transaction. ++ (id _Nonnull)startTransactionWithName:(NSString *_Nonnull)name + operation:(NSString *_Nonnull)operation + NS_SWIFT_NAME(startTransaction(name:operation:)); + +/// Creates a transaction, binds it to the hub and returns the instance. +/// \param name The transaction name. +/// +/// \param operation Short code identifying the type of operation the span is measuring. +/// +/// \param bindToScope Indicates whether the SDK should bind the new transaction to the scope. +/// +/// +/// returns: +/// The created transaction. ++ (id _Nonnull)startTransactionWithName:(NSString *_Nonnull)name + operation:(NSString *_Nonnull)operation + bindToScope:(BOOL)bindToScope + NS_SWIFT_NAME(startTransaction(name:operation:bindToScope:)); + +/// Creates a transaction, binds it to the hub and returns the instance. +/// \param transactionContext The transaction context. +/// +/// +/// returns: +/// The created transaction. ++ (id _Nonnull)startTransactionWithContext: + (SentryTransactionContext *_Nonnull)transactionContext + NS_SWIFT_NAME(startTransaction(transactionContext:)); + +/// Creates a transaction, binds it to the hub and returns the instance. +/// \param transactionContext The transaction context. +/// +/// \param bindToScope Indicates whether the SDK should bind the new transaction to the scope. +/// +/// +/// returns: +/// The created transaction. ++ (id _Nonnull)startTransactionWithContext: + (SentryTransactionContext *_Nonnull)transactionContext + bindToScope:(BOOL)bindToScope + NS_SWIFT_NAME(startTransaction(transactionContext:bindToScope:)); + +/// Creates a transaction, binds it to the hub and returns the instance. +/// \param transactionContext The transaction context. +/// +/// \param bindToScope Indicates whether the SDK should bind the new transaction to the scope. +/// +/// \param customSamplingContext Additional information about the sampling context. +/// +/// +/// returns: +/// The created transaction. ++ (id _Nonnull) + startTransactionWithContext:(SentryTransactionContext *_Nonnull)transactionContext + bindToScope:(BOOL)bindToScope + customSamplingContext:(NSDictionary *_Nonnull)customSamplingContext + NS_SWIFT_NAME(startTransaction(transactionContext:bindToScope:customSamplingContext:)); + +/// Creates a transaction, binds it to the hub and returns the instance. +/// \param transactionContext The transaction context. +/// +/// \param customSamplingContext Additional information about the sampling context. +/// +/// +/// returns: +/// The created transaction. ++ (id _Nonnull) + startTransactionWithContext:(SentryTransactionContext *_Nonnull)transactionContext + customSamplingContext:(NSDictionary *_Nonnull)customSamplingContext + NS_SWIFT_NAME(startTransaction(transactionContext:customSamplingContext:)); + +/// Captures an error event and sends it to Sentry. +/// \param error The error to send to Sentry. +/// +/// +/// returns: +/// The SentryId of the event or SentryId.empty if the event is not sent. ++ (SentryId *_Nonnull)captureError:(NSError *_Nonnull)error NS_SWIFT_NAME(capture(error:)); + +/// Captures an error event and sends it to Sentry. Only the data in this scope object will be added +/// to the event. The global scope will be ignored. +/// \param error The error to send to Sentry. +/// +/// \param scope The scope containing event metadata. +/// +/// +/// returns: +/// The SentryId of the event or SentryId.empty if the event is not sent. ++ (SentryId *_Nonnull)captureError:(NSError *_Nonnull)error + withScope:(SentryScope *_Nonnull)scope + NS_SWIFT_NAME(capture(error:scope:)); + +/// Captures an error event and sends it to Sentry. Maintains the global scope but mutates scope +/// data for only this call. +/// \param error The error to send to Sentry. +/// +/// \param block The block mutating the scope only for this call. +/// +/// +/// returns: +/// The SentryId of the event or SentryId.empty if the event is not sent. ++ (SentryId *_Nonnull)captureError:(NSError *_Nonnull)error + withScopeBlock:(void (^_Nonnull)(SentryScope *_Nonnull))block + NS_SWIFT_NAME(capture(error:block:)); + +/// Captures an exception event and sends it to Sentry. +/// \param exception The exception to send to Sentry. +/// +/// +/// returns: +/// The SentryId of the event or SentryId.empty if the event is not sent. ++ (SentryId *_Nonnull)captureException:(NSException *_Nonnull)exception + NS_SWIFT_NAME(capture(exception:)); + +/// Captures an exception event and sends it to Sentry. Only the data in this scope object will be +/// added to the event. The global scope will be ignored. +/// \param exception The exception to send to Sentry. +/// +/// \param scope The scope containing event metadata. +/// +/// +/// returns: +/// The SentryId of the event or SentryId.empty if the event is not sent. ++ (SentryId *_Nonnull)captureException:(NSException *_Nonnull)exception + withScope:(SentryScope *_Nonnull)scope + NS_SWIFT_NAME(capture(exception:scope:)); + +/// Captures an exception event and sends it to Sentry. Maintains the global scope but mutates scope +/// data for only this call. +/// \param exception The exception to send to Sentry. +/// +/// \param block The block mutating the scope only for this call. +/// +/// +/// returns: +/// The SentryId of the event or SentryId.empty if the event is not sent. ++ (SentryId *_Nonnull)captureException:(NSException *_Nonnull)exception + withScopeBlock:(void (^_Nonnull)(SentryScope *_Nonnull))block + NS_SWIFT_NAME(capture(exception:block:)); + +/// Captures a message event and sends it to Sentry. +/// \param message The message to send to Sentry. +/// +/// +/// returns: +/// The SentryId of the event or SentryId.empty if the event is not sent. ++ (SentryId *_Nonnull)captureMessage:(NSString *_Nonnull)message NS_SWIFT_NAME(capture(message:)); + +/// Captures a message event and sends it to Sentry. Only the data in this scope object will be +/// added to the event. The global scope will be ignored. +/// \param message The message to send to Sentry. +/// +/// \param scope The scope containing event metadata. +/// +/// +/// returns: +/// The SentryId of the event or SentryId.empty if the event is not sent. ++ (SentryId *_Nonnull)captureMessage:(NSString *_Nonnull)message + withScope:(SentryScope *_Nonnull)scope + NS_SWIFT_NAME(capture(message:scope:)); + +/// Captures a message event and sends it to Sentry. Maintains the global scope but mutates scope +/// data for only this call. +/// \param message The message to send to Sentry. +/// +/// \param block The block mutating the scope only for this call. +/// +/// +/// returns: +/// The SentryId of the event or SentryId.empty if the event is not sent. ++ (SentryId *_Nonnull)captureMessage:(NSString *_Nonnull)message + withScopeBlock:(void (^_Nonnull)(SentryScope *_Nonnull))block + NS_SWIFT_NAME(capture(message:block:)); + +/// Captures user feedback that was manually gathered and sends it to Sentry. +/// \param userFeedback The user feedback to send to Sentry. +/// ++ (void)captureUserFeedback:(SentryUserFeedback *_Nonnull)userFeedback + NS_SWIFT_NAME(capture(userFeedback:)) + DEPRECATED_MSG_ATTRIBUTE("Use SentrySDK.back or use or configure our new managed UX with " + "SentryOptions.configureUserFeedback."); + +/// Captures user feedback that was manually gathered and sends it to Sentry. +/// warning: +/// This is an experimental feature and may still have bugs. +/// note: +/// If you’d prefer not to have to build the UI required to gather the feedback from the user, +/// see SentryOptions.configureUserFeedback to customize a fully managed integration. +/// See https://docs.sentry.io/platforms/apple/user-feedback/ for more information. +/// \param feedback The feedback to send to Sentry. +/// ++ (void)captureFeedback:(SentryFeedback *_Nonnull)feedback NS_SWIFT_NAME(capture(feedback:)); + +# if TARGET_OS_IOS && SENTRY_HAS_UIKIT + +@property (nonatomic, class, readonly) + SentryFeedbackAPI *_Nonnull feedback NS_EXTENSION_UNAVAILABLE( + "Sentry User Feedback UI cannot be used from app extensions."); + +# endif // TARGET_OS_IOS && SENTRY_HAS_UIKIT + +/// Adds a Breadcrumb to the current Scope of the current +/// Hub. If the total number of breadcrumbs exceeds the +/// SentryOptions.maxBreadcrumbs the SDK removes the oldest breadcrumb. +/// \param crumb The Breadcrumb to add to the current Scope of the current +/// Hub. +/// ++ (void)addBreadcrumb:(SentryBreadcrumb *_Nonnull)crumb NS_SWIFT_NAME(addBreadcrumb(_:)); + +/// Use this method to modify the current Scope of the current Hub. The +/// SDK uses the Scope to attach contextual data to events. +/// \param callback The callback for configuring the current Scope of the current +/// Hub. +/// ++ (void)configureScope:(void (^_Nonnull)(SentryScope *_Nonnull))callback; + +/// Checks if the last program execution terminated with a crash. ++ (BOOL)crashedLastRun; + +/// Checks if the SDK detected a start-up crash during SDK initialization. +/// note: +/// The SDK init waits synchronously for up to 5 seconds to flush out events if the app crashes +/// within 2 seconds after the SDK init. +/// +/// returns: +/// true if the SDK detected a start-up crash and false if not. ++ (BOOL)detectedStartUpCrash; + +/// Set user to the current Scope of the current Hub. +/// note: +/// You must start the SDK before calling this method, otherwise it doesn’t set the user. +/// \param user The user to set to the current Scope. +/// ++ (void)setUser:(SentryUser *_Nullable)user; + +/// Starts a new SentrySession. If there’s a running SentrySession, it +/// ends it before starting the new one. You can use this method in combination with +/// endSession to manually track sessions. The SDK uses SentrySession to +/// inform Sentry about release and project associated project health. ++ (void)startSession; + +/// Ends the current SentrySession. You can use this method in combination with +/// startSession to manually track SentrySessions. The SDK uses +/// SentrySession to inform Sentry about release and project associated project health. ++ (void)endSession; + +/// This forces a crash, useful to test the SentryCrash integration. +/// note: +/// The SDK can’t report a crash when a debugger is attached. Your application needs to run +/// without a debugger attached to capture the crash and send it to Sentry the next time you launch +/// your application. ++ (void)crash; + +/// Reports to the ongoing UIViewController transaction +/// that the screen contents are fully loaded and displayed, +/// which will create a new span. +/// seealso: +/// +/// https://docs.sentry.io/platforms/cocoa/performance/instrumentation/automatic-instrumentation/#time-to-full-display ++ (void)reportFullyDisplayed; + +/// Pauses sending detected app hangs to Sentry. +/// This method doesn’t close the detection of app hangs. Instead, the app hang detection +/// will ignore detected app hangs until you call resumeAppHangTracking. ++ (void)pauseAppHangTracking; + +/// Resumes sending detected app hangs to Sentry. ++ (void)resumeAppHangTracking; + +/// Waits synchronously for the SDK to flush out all queued and cached items for up to the specified +/// timeout in seconds. If there is no internet connection, the function returns immediately. The +/// SDK doesn’t dispose the client or the hub. note: This might take slightly longer than the +/// specified timeout if there are many batched logs to capture. +/// \param timeout The time to wait for the SDK to complete the flush. +/// ++ (void)flush:(NSTimeInterval)timeout NS_SWIFT_NAME(flush(timeout:)); + +/// Closes the SDK, uninstalls all the integrations, and calls flush with +/// SentryOptions.shutdownTimeInterval. ++ (void)close; + +/// Start a new continuous profiling session if one is not already running. +/// warning: +/// Continuous profiling mode is experimental and may still contain bugs. +/// note: +/// Unlike transaction-based profiling, continuous profiling does not take into account +/// SentryOptions.profilesSampleRate or SentryOptions.profilesSampler. If +/// either of those options are set, this method does nothing. note: Taking into account the above +/// note, if SentryOptions.configureProfiling is not set, calls to this method will +/// always start a profile if one is not already running. This includes app launch profiles +/// configured with SentryOptions.enableAppLaunchProfiling. note: If neither +/// SentryOptions.profilesSampleRate nor SentryOptions.profilesSampler are +/// set, and SentryOptions.configureProfiling is set, this method does nothing if the +/// profiling session is not sampled with respect to +/// SentryOptions.profileSessionSampleRate, or if it is sampled but the profiler is +/// already running. note: If neither SentryOptions.profilesSampleRate nor +/// SentryOptions.profilesSampler are set, and +/// SentryOptions.configureProfiling is set, this method does nothing if +/// SentryOptions.profileLifecycle is set to trace. In this scenario, the +/// profiler is automatically started and stopped depending on whether there is an active sampled +/// span, so it is not permitted to manually start profiling. note: Profiling is automatically +/// disabled if a thread sanitizer is attached. seealso: +/// https://docs.sentry.io/platforms/apple/guides/ios/profiling/#continuous-profiling ++ (void)startProfiler; + +/// Stop a continuous profiling session if there is one ongoing. +/// warning: +/// Continuous profiling mode is experimental and may still contain bugs. +/// note: +/// Does nothing if SentryOptions.profileLifecycle is set to trace. +/// note: +/// Does not immediately stop the profiler. Profiling data is uploaded at regular timed +/// intervals; when the current interval completes, then the profiler stops and the data gathered +/// during that last interval is uploaded. +/// note: +/// If a new call to startProfiler that would start the profiler is made before the +/// last interval completes, the profiler will continue running until another call to stop is made. +/// note: +/// Profiling is automatically disabled if a thread sanitizer is attached. +/// seealso: +/// https://docs.sentry.io/platforms/apple/guides/ios/profiling/#continuous-profiling ++ (void)stopProfiler; + +@end + +#endif // !SDK_V9 diff --git a/Sources/Sentry/Public/SentryWithoutUIKit.h b/Sources/Sentry/Public/SentryWithoutUIKit.h index 508d9b09348..74db6c9f726 100644 --- a/Sources/Sentry/Public/SentryWithoutUIKit.h +++ b/Sources/Sentry/Public/SentryWithoutUIKit.h @@ -7,6 +7,7 @@ FOUNDATION_EXPORT double SentryVersionNumber; //! Project version string for Sentry. FOUNDATION_EXPORT const unsigned char SentryVersionString[]; +# import # import # import # import diff --git a/Sources/Sentry/SentryANRTrackingIntegration.m b/Sources/Sentry/SentryANRTrackingIntegration.m index ad3662a41cc..7b61d783d3f 100644 --- a/Sources/Sentry/SentryANRTrackingIntegration.m +++ b/Sources/Sentry/SentryANRTrackingIntegration.m @@ -185,7 +185,7 @@ - (void)anrDetectedWithType:(enum SentryANRType)type [self.fileManager storeAppHangEvent:event]; } else { #endif // SENTRY_HAS_UIKIT - [SentrySDK captureEvent:event]; + [SentrySDKSwift captureEvent:event]; #if SENTRY_HAS_UIKIT } #endif // SENTRY_UIKIT_AVAILABLE @@ -233,7 +233,7 @@ - (void)anrStoppedWithResult:(SentryANRStoppedResult *_Nullable)result // We already applied the scope. We use an empty scope to avoid overwriting exising fields on // the event. - [SentrySDK captureEvent:event withScope:[[SentryScope alloc] init]]; + [SentrySDKSwift captureEvent:event withScope:[[SentryScope alloc] init]]; #endif // SENTRY_HAS_UIKIT } @@ -257,7 +257,7 @@ - (void)captureStoredAppHangEvent // The app crashed during an ongoing app hang. Capture the stored app hang as it is. // We already applied the scope. We use an empty scope to avoid overwriting exising // fields on the event. - [SentrySDK captureEvent:event withScope:[[SentryScope alloc] init]]; + [SentrySDKSwift captureEvent:event withScope:[[SentryScope alloc] init]]; } else { // Fatal App Hang // We can't differ if the watchdog or the user terminated the app, because when the main diff --git a/Sources/Sentry/SentryFileIOTracker.m b/Sources/Sentry/SentryFileIOTracker.m index 4a7f148bf57..69aa9aceff2 100644 --- a/Sources/Sentry/SentryFileIOTracker.m +++ b/Sources/Sentry/SentryFileIOTracker.m @@ -38,7 +38,7 @@ + (instancetype _Nullable)sharedInstance // It is necessary to check if the SDK is enabled because accessing the tracker will otherwise // initialize the depency container without any configured SDK options. This is a known issue // and needs to be fixed in general. - if (!SentrySDK.isEnabled) { + if (!SentrySDKSwift.isEnabled) { return nil; } return SentryDependencyContainer.sharedInstance.fileIOTracker; diff --git a/Sources/Sentry/SentryMetricKitIntegration.m b/Sources/Sentry/SentryMetricKitIntegration.m index 7bb41352ff2..c702edcfea9 100644 --- a/Sources/Sentry/SentryMetricKitIntegration.m +++ b/Sources/Sentry/SentryMetricKitIntegration.m @@ -408,15 +408,15 @@ - (SentryEvent *)createEvent:(SentryMXExceptionParams *)params - (void)captureEvent:(SentryEvent *)event withDiagnosticJSON:(NSData *)diagnosticJSON { if (self.attachDiagnosticAsAttachment) { - [SentrySDK captureEvent:event - withScopeBlock:^(SentryScope *_Nonnull scope) { - SentryAttachment *attachment = - [[SentryAttachment alloc] initWithData:diagnosticJSON - filename:@"MXDiagnosticPayload.json"]; - [scope addAttachment:attachment]; - }]; + [SentrySDKSwift captureEvent:event + withScopeBlock:^(SentryScope *_Nonnull scope) { + SentryAttachment *attachment = + [[SentryAttachment alloc] initWithData:diagnosticJSON + filename:@"MXDiagnosticPayload.json"]; + [scope addAttachment:attachment]; + }]; } else { - [SentrySDK captureEvent:event]; + [SentrySDKSwift captureEvent:event]; } } diff --git a/Sources/Sentry/SentryNetworkTracker.m b/Sources/Sentry/SentryNetworkTracker.m index 0343099c5a9..3514b7265b7 100644 --- a/Sources/Sentry/SentryNetworkTracker.m +++ b/Sources/Sentry/SentryNetworkTracker.m @@ -475,7 +475,7 @@ - (void)captureFailedRequests:(NSURLSessionTask *)sessionTask event.context = context; - [SentrySDK captureEvent:event]; + [SentrySDKSwift captureEvent:event]; } - (BOOL)containsStatusCode:(NSInteger)statusCode @@ -544,7 +544,7 @@ - (void)addBreadcrumbForSessionTask:(NSURLSessionTask *)sessionTask } breadcrumb.data = breadcrumbData; - [SentrySDK addBreadcrumb:breadcrumb]; + [SentrySDKSwift addBreadcrumb:breadcrumb]; objc_setAssociatedObject(sessionTask, &SENTRY_NETWORK_REQUEST_TRACKER_BREADCRUMB, [NSNumber numberWithBool:YES], OBJC_ASSOCIATION_RETAIN_NONATOMIC); diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m new file mode 100644 index 00000000000..244a2b5d28c --- /dev/null +++ b/Sources/Sentry/SentrySDK.m @@ -0,0 +1,245 @@ +#if !SDK_V9 + +# import "SentrySDK.h" +# import "SentrySwift.h" + +@implementation SentrySDK + ++ (void)startWithOptions:(SentryOptions *_Nonnull)options +{ + [SentrySDKSwift startWithOptions:options]; +} + ++ (void)startWithConfigureOptions:(void (^_Nonnull)(SentryOptions *_Nonnull))configureOptions +{ + [SentrySDKSwift startWithConfigureOptions:configureOptions]; +} + ++ (SentryId *_Nonnull)captureEvent:(SentryEvent *_Nonnull)event +{ + return [SentrySDKSwift captureEvent:event]; +} + ++ (SentryId *_Nonnull)captureEvent:(SentryEvent *_Nonnull)event + withScope:(SentryScope *_Nonnull)scope +{ + return [SentrySDKSwift captureEvent:event withScope:scope]; +} + ++ (SentryId *_Nonnull)captureEvent:(SentryEvent *_Nonnull)event + withScopeBlock:(void (^_Nonnull)(SentryScope *_Nonnull))block +{ + return [SentrySDKSwift captureEvent:event withScopeBlock:block]; +} + ++ (id _Nonnull)startTransactionWithName:(NSString *_Nonnull)name + operation:(NSString *_Nonnull)operation +{ + return [SentrySDKSwift startTransactionWithName:name operation:operation]; +} + ++ (id _Nonnull)startTransactionWithName:(NSString *_Nonnull)name + operation:(NSString *_Nonnull)operation + bindToScope:(BOOL)bindToScope +{ + return [SentrySDKSwift startTransactionWithName:name + operation:operation + bindToScope:bindToScope]; +} + ++ (id _Nonnull)startTransactionWithContext: + (SentryTransactionContext *_Nonnull)transactionContext +{ + return [SentrySDKSwift startTransactionWithContext:transactionContext]; +} + ++ (id _Nonnull)startTransactionWithContext: + (SentryTransactionContext *_Nonnull)transactionContext + bindToScope:(BOOL)bindToScope +{ + return [SentrySDKSwift startTransactionWithContext:transactionContext bindToScope:bindToScope]; +} + ++ (id _Nonnull) + startTransactionWithContext:(SentryTransactionContext *_Nonnull)transactionContext + bindToScope:(BOOL)bindToScope + customSamplingContext:(NSDictionary *_Nonnull)customSamplingContext +{ + return [SentrySDKSwift startTransactionWithContext:transactionContext + bindToScope:bindToScope + customSamplingContext:customSamplingContext]; +} + ++ (id _Nonnull) + startTransactionWithContext:(SentryTransactionContext *_Nonnull)transactionContext + customSamplingContext:(NSDictionary *_Nonnull)customSamplingContext +{ + return [SentrySDKSwift startTransactionWithContext:transactionContext + customSamplingContext:customSamplingContext]; +} + ++ (SentryId *_Nonnull)captureError:(NSError *_Nonnull)error +{ + return [SentrySDKSwift captureError:error]; +} + ++ (SentryId *_Nonnull)captureError:(NSError *_Nonnull)error withScope:(SentryScope *_Nonnull)scope +{ + return [SentrySDKSwift captureError:error withScope:scope]; +} + ++ (SentryId *_Nonnull)captureError:(NSError *_Nonnull)error + withScopeBlock:(void (^_Nonnull)(SentryScope *_Nonnull))block +{ + return [SentrySDKSwift captureError:error withScopeBlock:block]; +} + ++ (SentryId *_Nonnull)captureException:(NSException *_Nonnull)exception +{ + return [SentrySDKSwift captureException:exception]; +} + ++ (SentryId *_Nonnull)captureException:(NSException *_Nonnull)exception + withScope:(SentryScope *_Nonnull)scope +{ + return [SentrySDKSwift captureException:exception withScope:scope]; +} + ++ (SentryId *_Nonnull)captureException:(NSException *_Nonnull)exception + withScopeBlock:(void (^_Nonnull)(SentryScope *_Nonnull))block +{ + return [SentrySDKSwift captureException:exception withScopeBlock:block]; +} + ++ (SentryId *_Nonnull)captureMessage:(NSString *_Nonnull)message +{ + return [SentrySDKSwift captureMessage:message]; +} + ++ (SentryId *_Nonnull)captureMessage:(NSString *_Nonnull)message + withScope:(SentryScope *_Nonnull)scope +{ + return [SentrySDKSwift captureMessage:message withScope:scope]; +} + ++ (SentryId *_Nonnull)captureMessage:(NSString *_Nonnull)message + withScopeBlock:(void (^_Nonnull)(SentryScope *_Nonnull))block +{ + return [SentrySDKSwift captureMessage:message withScopeBlock:block]; +} + ++ (void)captureUserFeedback:(SentryUserFeedback *_Nonnull)userFeedback + DEPRECATED_MSG_ATTRIBUTE("Use SentrySDK.back or use or configure our new managed UX with " + "SentryOptions.configureUserFeedback.") +{ + [SentrySDKSwift captureUserFeedback:userFeedback]; +} + ++ (void)captureFeedback:(SentryFeedback *_Nonnull)feedback +{ + [SentrySDKSwift captureFeedback:feedback]; +} + ++ (SentryFeedbackAPI *_Nonnull)feedback +{ + return [SentrySDKSwift feedback]; +} + ++ (void)addBreadcrumb:(SentryBreadcrumb *_Nonnull)crumb +{ + [SentrySDKSwift addBreadcrumb:crumb]; +} + ++ (void)configureScope:(void (^_Nonnull)(SentryScope *_Nonnull))callback +{ + [SentrySDKSwift configureScope:callback]; +} + ++ (BOOL)crashedLastRun +{ + return [SentrySDKSwift crashedLastRun]; +} + ++ (BOOL)detectedStartUpCrash +{ + return [SentrySDKSwift detectedStartUpCrash]; +} + ++ (void)setUser:(SentryUser *_Nullable)user +{ + [SentrySDKSwift setUser:user]; +} + ++ (void)startSession +{ + [SentrySDKSwift startSession]; +} + ++ (void)endSession +{ + [SentrySDKSwift endSession]; +} + ++ (void)crash +{ + [SentrySDKSwift crash]; +} + ++ (void)reportFullyDisplayed +{ + [SentrySDKSwift reportFullyDisplayed]; +} + ++ (void)pauseAppHangTracking +{ + [SentrySDKSwift pauseAppHangTracking]; +} + ++ (void)resumeAppHangTracking +{ + [SentrySDKSwift resumeAppHangTracking]; +} + ++ (void)flush:(NSTimeInterval)timeout +{ + [SentrySDKSwift flush:timeout]; +} + ++ (void)close +{ + [SentrySDKSwift close]; +} + ++ (void)startProfiler +{ + [SentrySDKSwift startProfiler]; +} + ++ (void)stopProfiler +{ + [SentrySDKSwift stopProfiler]; +} + ++ (BOOL)isEnabled +{ + return [SentrySDKSwift isEnabled]; +} + ++ (SentryLogger *)logger +{ + return [SentrySDKSwift logger]; +} + ++ (SentryReplayApi *_Nonnull)replay +{ + return [SentrySDKSwift replay]; +} + ++ (id _Nullable)span; +{ + return [SentrySDKSwift span]; +} + +@end + +#endif // !SDK_V9 diff --git a/Sources/Sentry/SentrySDKInternal.m b/Sources/Sentry/SentrySDKInternal.m index 1aa33ec6d20..4d2e15ccb30 100644 --- a/Sources/Sentry/SentrySDKInternal.m +++ b/Sources/Sentry/SentrySDKInternal.m @@ -680,7 +680,7 @@ + (void)close [SentrySDKInternal setCurrentHub:nil]; - [SentrySDK clearLogger]; + [SentrySDKSwift clearLogger]; [SentryDependencyContainer.sharedInstance.crashWrapper stopBinaryImageCache]; [SentryDependencyContainer.sharedInstance.binaryImageCache stop]; diff --git a/Sources/Sentry/SentryUserFeedbackIntegration.m b/Sources/Sentry/SentryUserFeedbackIntegration.m index 8ec08de90db..3b4a3e10848 100644 --- a/Sources/Sentry/SentryUserFeedbackIntegration.m +++ b/Sources/Sentry/SentryUserFeedbackIntegration.m @@ -46,7 +46,7 @@ - (void)hideWidget - (void)captureWithFeedback:(SentryFeedback *)feedback { - [SentrySDK captureFeedback:feedback]; + [SentrySDKSwift captureFeedback:feedback]; } @end diff --git a/Sources/Swift/Helper/SentrySDK.swift b/Sources/Swift/Helper/SentrySDK.swift index a0ef1b74c10..f3741edcb18 100644 --- a/Sources/Swift/Helper/SentrySDK.swift +++ b/Sources/Swift/Helper/SentrySDK.swift @@ -2,9 +2,13 @@ @_implementationOnly import _SentryPrivate import Foundation +#if SDK_V9 +typealias SentrySDK = SentrySDKSwift +#endif // SDK_V9 + /// The main entry point for the Sentry SDK. /// We recommend using `start(configureOptions:)` to initialize Sentry. -@objc open class SentrySDK: NSObject { +@objc open class SentrySDKSwift: NSObject { // MARK: - Public