Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryANRTrackingIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ @interface SentryANRTrackingIntegration () <SentryANRTrackerDelegate>
@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueueWrapper;
@property (nonatomic, strong) SentryCrashWrapper *crashWrapper;
@property (nonatomic, strong) SentryDebugImageProvider *debugImageProvider;
@property (nonatomic, strong) id<SentryThreadInspector> threadInspector;
@property (nonatomic, strong) SentryThreadInspector *threadInspector;
@property (atomic, assign) BOOL reportAppHangs;
@property (atomic, assign) BOOL enableReportNonFullyBlockingAppHangs;

Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryDefaultThreadInspector.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ - (id)initWithStacktraceBuilder:(SentryStacktraceBuilder *)stacktraceBuilder
return self;
}

- (instancetype)initWithOptions:(SentryOptions *)options
- (instancetype)initWithOptions:(SentryOptions *_Nullable)options
{
SentryInAppLogic *inAppLogic =
[[SentryInAppLogic alloc] initWithInAppIncludes:options.inAppIncludes
Expand Down
10 changes: 3 additions & 7 deletions Sources/Sentry/SentryDependencyContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@
@interface SentryFileManager () <SentryFileManagerProtocol>
@end

@interface SentryDefaultThreadInspector () <SentryThreadInspector>
@end

@interface SentryDefaultAppStateManager () <SentryAppStateManager>
@end

Expand Down Expand Up @@ -153,7 +150,7 @@ - (instancetype)init

_notificationCenterWrapper = NSNotificationCenter.defaultCenter;

_processInfoWrapper = NSProcessInfo.processInfo;
_processInfoWrapper = SentryDependencies.processInfoWrapper;
_crashWrapper = [[SentryCrashWrapper alloc] initWithProcessInfoWrapper:_processInfoWrapper];
#if SENTRY_HAS_UIKIT
_uiDeviceWrapper = SentryDependencies.uiDeviceWrapper;
Expand Down Expand Up @@ -227,10 +224,9 @@ - (nullable SentryFileManager *)fileManager SENTRY_THREAD_SANITIZER_DOUBLE_CHECK
notificationCenterWrapper:self.notificationCenterWrapper]);
}

- (id<SentryThreadInspector>)threadInspector SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
- (SentryThreadInspector *)threadInspector SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
{
SENTRY_LAZY_INIT(_threadInspector,
[[SentryDefaultThreadInspector alloc] initWithOptions:SentrySDKInternal.options]);
return SentryDependencies.threadInspector;
}

- (SentryFileIOTracker *)fileIOTracker SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
Expand Down
6 changes: 3 additions & 3 deletions Sources/Sentry/SentryFileIOTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ @interface SentryFileIOTracker ()

@property (nonatomic, assign) BOOL isEnabled;
@property (nonatomic, strong) NSMutableSet<NSData *> *processingData;
@property (nonatomic, strong) id<SentryThreadInspector> threadInspector;
@property (nonatomic, strong) SentryThreadInspector *threadInspector;
@property (nonatomic, strong) id<SentryProcessInfoSource> processInfoWrapper;

@end
Expand All @@ -42,7 +42,7 @@ + (instancetype _Nullable)sharedInstance
return SentryDependencyContainer.sharedInstance.fileIOTracker;
}

- (instancetype)initWithThreadInspector:(id<SentryThreadInspector>)threadInspector
- (instancetype)initWithThreadInspector:(SentryThreadInspector *)threadInspector
processInfoWrapper:(id<SentryProcessInfoSource>)processInfoWrapper
{
if (self = [super init]) {
Expand Down Expand Up @@ -245,7 +245,7 @@ - (void)mainThreadExtraInfo:(id<SentrySpan>)span
return;
}

id<SentryThreadInspector> threadInspector = self.threadInspector;
SentryThreadInspector *threadInspector = self.threadInspector;
SentryStacktrace *stackTrace = [threadInspector stacktraceForCurrentThreadAsyncUnsafe];

NSArray *frames = [stackTrace.frames
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@class SentryOptions;
@class SentrySessionTracker;
@class SentryGlobalEventProcessor;
@class SentryThreadInspector;
@class SentryReachability;

@protocol SentryAppStateManager;
Expand All @@ -33,7 +34,6 @@
@protocol SentryApplication;
@protocol SentryProcessInfoSource;
@protocol SentryNSNotificationCenterWrapper;
@protocol SentryThreadInspector;
@protocol SentryObjCRuntimeWrapper;

#if SENTRY_HAS_METRIC_KIT
Expand Down Expand Up @@ -100,7 +100,7 @@ SENTRY_NO_INIT

@property (nonatomic, strong, nullable) SentryFileManager *fileManager;
@property (nonatomic, strong) id<SentryAppStateManager> appStateManager;
@property (nonatomic, strong) id<SentryThreadInspector> threadInspector;
@property (nonatomic, strong, readonly) SentryThreadInspector *threadInspector;
@property (nonatomic, strong) SentryFileIOTracker *fileIOTracker;
@property (nonatomic, strong) SentryCrash *crashReporter;
@property (nonatomic, strong) SentryScopePersistentStore *scopePersistentStore;
Expand Down
6 changes: 4 additions & 2 deletions Sources/Sentry/include/SentryDefaultThreadInspector.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "SentryCrashMachineContextWrapper.h"
#import "SentryCrashThread.h"
#import "SentryDefines.h"
#import <Foundation/Foundation.h>

Expand All @@ -7,6 +7,8 @@
@class SentryStacktraceBuilder;
@class SentryThread;

@protocol SentryCrashMachineContextWrapper;

NS_ASSUME_NONNULL_BEGIN

@interface SentryDefaultThreadInspector : NSObject
Expand All @@ -16,7 +18,7 @@ SENTRY_NO_INIT
andMachineContextWrapper:(id<SentryCrashMachineContextWrapper>)machineContextWrapper
symbolicate:(BOOL)symbolicate;

- (instancetype)initWithOptions:(SentryOptions *)options;
- (instancetype)initWithOptions:(SentryOptions *_Nullable)options;

- (nullable SentryStacktrace *)stacktraceForCurrentThreadAsyncUnsafe;

Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/include/SentryFileIOTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
NS_ASSUME_NONNULL_BEGIN

@protocol SentryProcessInfoSource;
@protocol SentryThreadInspector;
@class SentryThreadInspector;

@interface SentryFileIOTracker : NSObject
SENTRY_NO_INIT
Expand All @@ -18,7 +18,7 @@ SENTRY_NO_INIT
*/
+ (instancetype _Nullable)sharedInstance;

- (instancetype)initWithThreadInspector:(id<SentryThreadInspector>)threadInspector
- (instancetype)initWithThreadInspector:(SentryThreadInspector *)threadInspector
processInfoWrapper:(id<SentryProcessInfoSource>)processInfoWrapper;

- (void)enable;
Expand Down
1 change: 1 addition & 0 deletions Sources/Sentry/include/SentryPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#import "SentryCrashMonitor_AppState.h"
#import "SentryCrashMonitor_System.h"
#import "SentryDateUtils.h"
#import "SentryDefaultThreadInspector.h"
#import "SentryDependencyContainerSwiftHelper.h"
#import "SentryEvent+Serialize.h"
#import "SentryFileIOTracker.h"
Expand Down
6 changes: 6 additions & 0 deletions Sources/Swift/Helper/Dependencies.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
@_implementationOnly import _SentryPrivate

@objc(SentryDependencies) @_spi(Private) public final class Dependencies: NSObject {
@objc public static let processInfoWrapper: SentryProcessInfoSource = ProcessInfo.processInfo
@objc public static let dispatchQueueWrapper = SentryDispatchQueueWrapper()
@objc public static let dateProvider = SentryDefaultCurrentDateProvider()
public static let objcRuntimeWrapper = SentryDefaultObjCRuntimeWrapper()
#if !os(watchOS) && !os(macOS) && !SENTRY_NO_UIKIT
@objc public static let uiDeviceWrapper = SentryDefaultUIDeviceWrapper(queueWrapper: Dependencies.dispatchQueueWrapper)
#endif // !os(watchOS) && !os(macOS) && !SENTRY_NO_UIKIT

@objc public static var threadInspector: SentryThreadInspector = SentryThreadInspector()

}
28 changes: 24 additions & 4 deletions Sources/Swift/SentryCrash/SentryThreadInspector.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
@_spi(Private) @objc public protocol SentryThreadInspector {
func stacktraceForCurrentThreadAsyncUnsafe() -> SentryStacktrace?
func getCurrentThreadsWithStackTrace() -> [SentryThread]
func getThreadName(_ thread: UInt) -> String?
@_implementationOnly import _SentryPrivate

@_spi(Private) @objc public class SentryThreadInspector: NSObject {
private let internalHelper: SentryDefaultThreadInspector

override init() {
internalHelper = SentryDefaultThreadInspector(options: SentrySDKInternal.options)
}

@objc public init(options: Options) {
internalHelper = SentryDefaultThreadInspector(options: options)
}

@objc public func stacktraceForCurrentThreadAsyncUnsafe() -> SentryStacktrace? {
internalHelper.stacktraceForCurrentThreadAsyncUnsafe()
}

@objc public func getCurrentThreadsWithStackTrace() -> [SentryThread] {
internalHelper.getCurrentThreadsWithStackTrace()
}

@objc public func getThreadName(_ thread: UInt) -> String? {
internalHelper.getThreadName(thread)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,6 @@ class SentryANRTrackingIntegrationTests: SentrySDKIntegrationTestsBase {
threadInspector.allThreads = []
}

Dynamic(SentryDependencyContainer.sharedInstance()).threadInspector = threadInspector
Dependencies.threadInspector = threadInspector
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class SentryFeedbackTests: XCTestCase {
dispatchQueueWrapper: TestSentryDispatchQueueWrapper()
)),
deleteOldEnvelopeItems: false,
threadInspector: TestThreadInspector.instance,
threadInspector: TestDefaultThreadInspector.instance,
debugImageProvider: TestDebugImageProvider(),
random: TestRandom(value: 1.0),
locale: Locale(identifier: "en_US"),
Expand Down Expand Up @@ -251,7 +251,7 @@ class SentryFeedbackTests: XCTestCase {
dispatchQueueWrapper: TestSentryDispatchQueueWrapper()
)),
deleteOldEnvelopeItems: false,
threadInspector: TestThreadInspector.instance,
threadInspector: TestDefaultThreadInspector.instance,
debugImageProvider: TestDebugImageProvider(),
random: TestRandom(value: 1.0),
locale: Locale(identifier: "en_US"),
Expand Down Expand Up @@ -294,7 +294,7 @@ class SentryFeedbackTests: XCTestCase {
dispatchQueueWrapper: TestSentryDispatchQueueWrapper()
)),
deleteOldEnvelopeItems: false,
threadInspector: TestThreadInspector.instance,
threadInspector: TestDefaultThreadInspector.instance,
debugImageProvider: TestDebugImageProvider(),
random: TestRandom(value: 1.0),
locale: Locale(identifier: "en_US"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SentryCoreDataTrackerTests: XCTestCase {
lazy var context: TestNSManagedObjectContext = {
coreDataStack.managedObjectContext
}()
let threadInspector = TestThreadInspector.instance
let threadInspector = TestDefaultThreadInspector.instance
let imageProvider = TestDebugImageProvider()

init(testName: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// swiftlint:disable file_length
@testable import Sentry
@_spi(Private) @testable import Sentry
@_spi(Private) import SentryTestUtils
import XCTest

Expand Down Expand Up @@ -29,7 +29,7 @@ class SentryFileIOTrackerSwiftHelpersTests: XCTestCase {
SentrySDKInternal.setCurrentHub(hub)

tracker = SentryFileIOTracker(
threadInspector: TestThreadInspector(options: .noIntegrations()),
threadInspector: SentryThreadInspector(),
processInfoWrapper: MockSentryProcessInfo()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ - (void)setUpNSFileManagerSwizzlingWithEnabledFlag:(bool)enableFileManagerSwizzl
SentryOptions *options = [[SentryOptions alloc] init];
options.experimental.enableFileManagerSwizzling = enableFileManagerSwizzling;

SentryDefaultThreadInspector *threadInspector =
[[SentryDefaultThreadInspector alloc] initWithOptions:options];
SentryThreadInspector *threadInspector =
[[SentryThreadInspector alloc] initWithOptions:options];
id<SentryProcessInfoSource> processInfoWrapper =
[SentryDependencyContainer.sharedInstance processInfoWrapper];
self->tracker = [[SentryFileIOTracker alloc] initWithThreadInspector:threadInspector
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/SentryClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SentryClientTests: XCTestCase {

let dateProvider = TestCurrentDateProvider()
let debugImageProvider = TestDebugImageProvider()
let threadInspector = TestThreadInspector.instance
let threadInspector = TestDefaultThreadInspector.instance

let session: SentrySession
let event: Event
Expand Down
28 changes: 22 additions & 6 deletions Tests/SentryTests/SentryCrash/TestThreadInspector.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import Foundation
@_spi(Private) import Sentry
@_spi(Private) @testable import Sentry

@_spi(Private) extension SentryDefaultThreadInspector: SentryThreadInspector { }

class TestThreadInspector: SentryDefaultThreadInspector {
class TestDefaultThreadInspector: SentryDefaultThreadInspector {

var allThreads: [SentryThread]?

static var instance: TestThreadInspector {
static var instance: TestDefaultThreadInspector {
// We need something to pass to the super initializer, because the empty initializer has been marked unavailable.
let inAppLogic = SentryInAppLogic(inAppIncludes: [], inAppExcludes: [])
let crashStackEntryMapper = SentryCrashStackEntryMapper(inAppLogic: inAppLogic)
let stacktraceBuilder = SentryStacktraceBuilder(crashStackEntryMapper: crashStackEntryMapper)
return TestThreadInspector(stacktraceBuilder: stacktraceBuilder, andMachineContextWrapper: SentryCrashDefaultMachineContextWrapper(), symbolicate: false)
return TestDefaultThreadInspector(stacktraceBuilder: stacktraceBuilder, andMachineContextWrapper: SentryCrashDefaultMachineContextWrapper(), symbolicate: false)
}

override func stacktraceForCurrentThreadAsyncUnsafe() -> SentryStacktrace? {
Expand All @@ -28,3 +26,21 @@ class TestThreadInspector: SentryDefaultThreadInspector {
}

}

class TestThreadInspector: SentryThreadInspector {

var allThreads: [SentryThread]?

static var instance: TestThreadInspector {
return TestThreadInspector()
}

override func stacktraceForCurrentThreadAsyncUnsafe() -> SentryStacktrace? {
return allThreads?.first?.stacktrace ?? TestData.thread.stacktrace
}

override func getCurrentThreadsWithStackTrace() -> [SentryThread] {
return allThreads ?? [TestData.thread]
}

}
Loading