Skip to content

Commit

Permalink
Merge branch 'main' into kw-maestro
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich authored Oct 11, 2024
2 parents 051ec98 + 5a6e387 commit d7c5b54
Show file tree
Hide file tree
Showing 24 changed files with 339 additions and 464 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features

- feat: API to manually start/stop Session Replay (#4414)
- Custom redact modifier for SwiftUI (#4362, #4392)

### Removal of Experimental API
Expand All @@ -15,11 +16,13 @@
- Edge case for swizzleClassNameExclude (#4405): Skip creating transactions for UIViewControllers ignored for swizzling
via the option `swizzleClassNameExclude`.
- Add TTID/TTFD spans when loadView gets skipped (#4415)
- Finish TTID correctly when viewWillAppear is skipped (#4417)
- Swizzling RootUIViewController if ignored by `swizzleClassNameExclude` (#4407)

### Improvements

- Serializing profile on a BG Thread (#4377) to avoid potentially slightly blocking the main thread.
- Session Replay performance for SwiftUI (#4419)

## 8.38.0-beta.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
6250B97C2CB69C96009512D6 /* NoARCCrash.m in Sources */ = {isa = PBXBuildFile; fileRef = 6250B97B2CB69C96009512D6 /* NoARCCrash.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
630853492440C46E00DDE4CE /* Sentry.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6308533B2440C45500DDE4CE /* Sentry.framework */; };
6308534A2440C46E00DDE4CE /* Sentry.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6308533B2440C45500DDE4CE /* Sentry.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
637AFDCB243B036B0034958B /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 637AFDCA243B036B0034958B /* AppDelegate.m */; };
Expand Down Expand Up @@ -95,6 +96,8 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
6250B9752CB69C86009512D6 /* NoARCCrash.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NoARCCrash.h; sourceTree = "<group>"; };
6250B97B2CB69C96009512D6 /* NoARCCrash.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NoARCCrash.m; sourceTree = "<group>"; };
630853352440C45500DDE4CE /* Sentry.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Sentry.xcodeproj; path = ../../Sentry.xcodeproj; sourceTree = "<group>"; };
634C7EC724406A4900AFDE9F /* Sentry.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Sentry.framework; sourceTree = BUILT_PRODUCTS_DIR; };
637AFDC6243B036B0034958B /* iOS-ObjectiveC.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "iOS-ObjectiveC.app"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -186,6 +189,8 @@
637AFDD0243B036B0034958B /* ViewController.m */,
7B8A5C9C2715B5CF008ACD3B /* InitializerViewController.h */,
7B8A5C9D2715B5DE008ACD3B /* InitializerViewController.m */,
6250B9752CB69C86009512D6 /* NoARCCrash.h */,
6250B97B2CB69C96009512D6 /* NoARCCrash.m */,
637AFDD2243B036B0034958B /* Main.storyboard */,
637AFDD5243B036D0034958B /* Assets.xcassets */,
7B3427F925876DDB00056519 /* Tongariro.jpg */,
Expand Down Expand Up @@ -415,6 +420,7 @@
637AFDCB243B036B0034958B /* AppDelegate.m in Sources */,
84BA72AB2C9369A40045B828 /* GitInjections.swift in Sources */,
637AFDDC243B036D0034958B /* main.m in Sources */,
6250B97C2CB69C96009512D6 /* NoARCCrash.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
15 changes: 11 additions & 4 deletions Samples/iOS-ObjectiveC/iOS-ObjectiveC/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -24,7 +24,7 @@
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="AVC-4r-eVc">
<rect key="frame" x="8" y="120.5" width="398" height="240"/>
<rect key="frame" x="8" y="120.5" width="398" height="270"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rUC-at-hwU">
<rect key="frame" x="0.0" y="0.0" width="398" height="30"/>
Expand Down Expand Up @@ -77,8 +77,15 @@
<action selector="crash:" destination="BYZ-38-t0r" eventType="touchUpInside" id="6xT-zA-EZI"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7cg-k4-wJ5" userLabel="oomCrash">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="eUX-Yi-7fo">
<rect key="frame" x="0.0" y="210" width="398" height="30"/>
<state key="normal" title="sigsevCrash"/>
<connections>
<action selector="sigsevCrash:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Z0n-Rw-Tpu"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7cg-k4-wJ5" userLabel="oomCrash">
<rect key="frame" x="0.0" y="240" width="398" height="30"/>
<state key="normal" title="OOM Crash"/>
<connections>
<action selector="oomCrash:" destination="BYZ-38-t0r" eventType="touchUpInside" id="6Eb-uS-ljp"/>
Expand Down
6 changes: 6 additions & 0 deletions Samples/iOS-ObjectiveC/iOS-ObjectiveC/NoARCCrash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* We need to this into an extra file so we can disable ARC with the -fno-objc-arc Compiler flag.
* Otherwise, we can't call [NSObject release].
*
*/
void callMessageOnDeallocatedObject(void);
10 changes: 10 additions & 0 deletions Samples/iOS-ObjectiveC/iOS-ObjectiveC/NoARCCrash.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#import "NoARCCrash.h"
#import <Foundation/Foundation.h>

void
callMessageOnDeallocatedObject(void)
{
NSObject *obj = [[NSObject alloc] init];
[obj release]; // Manually releasing in MRC, making `obj` a dangling pointer
[obj description]; // Sending a message to a deallocated object causes a SIGSEGV
}
6 changes: 6 additions & 0 deletions Samples/iOS-ObjectiveC/iOS-ObjectiveC/ViewController.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "ViewController.h"
#import "NoARCCrash.h"

@import Sentry;

Expand Down Expand Up @@ -123,6 +124,11 @@ - (IBAction)crash:(id)sender
[SentrySDK crash];
}

- (IBAction)sigsevCrash:(id)sender
{
callMessageOnDeallocatedObject();
}

- (IBAction)oomCrash:(id)sender
{
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down
11 changes: 0 additions & 11 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@
621D9F2F2B9B0320003D94DE /* SentryCurrentDateProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621D9F2E2B9B0320003D94DE /* SentryCurrentDateProvider.swift */; };
621F61F12BEA073A005E654F /* SentryEnabledFeaturesBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621F61F02BEA073A005E654F /* SentryEnabledFeaturesBuilder.swift */; };
6221BBCA2CAA932100C627CA /* SentryANRType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6221BBC92CAA932100C627CA /* SentryANRType.swift */; };
62262B862BA1C46D004DA3DD /* SentryStatsdClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 62262B852BA1C46D004DA3DD /* SentryStatsdClient.h */; };
62262B882BA1C490004DA3DD /* SentryStatsdClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 62262B872BA1C490004DA3DD /* SentryStatsdClient.m */; };
62262B8B2BA1C4C1004DA3DD /* EncodeMetrics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62262B8A2BA1C4C1004DA3DD /* EncodeMetrics.swift */; };
62262B8D2BA1C4DB004DA3DD /* Metric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62262B8C2BA1C4DB004DA3DD /* Metric.swift */; };
62262B912BA1C520004DA3DD /* CounterMetric.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62262B902BA1C520004DA3DD /* CounterMetric.swift */; };
6229416A2BB2F123004765D1 /* SentryNSDataUtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 622941692BB2F123004765D1 /* SentryNSDataUtilsTests.swift */; };
622C08D829E546F4002571D4 /* SentryTraceOrigins.h in Headers */ = {isa = PBXBuildFile; fileRef = 622C08D729E546F4002571D4 /* SentryTraceOrigins.h */; };
622C08DB29E554B9002571D4 /* SentrySpanContext+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 622C08D929E554B9002571D4 /* SentrySpanContext+Private.h */; };
Expand Down Expand Up @@ -1077,12 +1072,6 @@
621D9F2E2B9B0320003D94DE /* SentryCurrentDateProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCurrentDateProvider.swift; sourceTree = "<group>"; };
621F61F02BEA073A005E654F /* SentryEnabledFeaturesBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryEnabledFeaturesBuilder.swift; sourceTree = "<group>"; };
6221BBC92CAA932100C627CA /* SentryANRType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryANRType.swift; sourceTree = "<group>"; };
62262B852BA1C46D004DA3DD /* SentryStatsdClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryStatsdClient.h; path = include/SentryStatsdClient.h; sourceTree = "<group>"; };
62262B872BA1C490004DA3DD /* SentryStatsdClient.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryStatsdClient.m; sourceTree = "<group>"; };
62262B8A2BA1C4C1004DA3DD /* EncodeMetrics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncodeMetrics.swift; sourceTree = "<group>"; };
62262B8C2BA1C4DB004DA3DD /* Metric.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Metric.swift; sourceTree = "<group>"; };
62262B902BA1C520004DA3DD /* CounterMetric.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterMetric.swift; sourceTree = "<group>"; };
62262B952BA1C564004DA3DD /* EncodeMetricTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncodeMetricTests.swift; sourceTree = "<group>"; };
622941692BB2F123004765D1 /* SentryNSDataUtilsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSDataUtilsTests.swift; sourceTree = "<group>"; };
622C08D729E546F4002571D4 /* SentryTraceOrigins.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTraceOrigins.h; path = include/SentryTraceOrigins.h; sourceTree = "<group>"; };
622C08D929E554B9002571D4 /* SentrySpanContext+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentrySpanContext+Private.h"; path = "include/SentrySpanContext+Private.h"; sourceTree = "<group>"; };
Expand Down
14 changes: 14 additions & 0 deletions Sources/Sentry/Public/SentryReplayApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)resume;

/**
* Start recording a session replay if not started.
*
* @warning This is an experimental feature and may still have bugs.
*/
- (void)start;

/**
* Stop the current session replay recording.
*
* @warning This is an experimental feature and may still have bugs.
*/
- (void)stop;

@end

NS_ASSUME_NONNULL_END
Expand Down
1 change: 0 additions & 1 deletion Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -804,5 +804,4 @@ - (NSString *)debugDescription
return [NSString stringWithFormat:@"<%@: {\n%@\n}>", self, propertiesDescription];
}
#endif // defined(DEBUG) || defined(TEST) || defined(TESTCI)

@end
39 changes: 34 additions & 5 deletions Sources/Sentry/SentryReplayApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#if SENTRY_TARGET_REPLAY_SUPPORTED

# import "SentryHub+Private.h"
# import "SentryOptions+Private.h"
# import "SentrySDK+Private.h"
# import "SentrySessionReplayIntegration.h"
# import "SentrySessionReplayIntegration+Private.h"
# import "SentrySwift.h"
# import <UIKit/UIKit.h>

Expand All @@ -22,18 +23,46 @@ - (void)unmaskView:(UIView *)view

- (void)pause
{
SentrySessionReplayIntegration *replayIntegration =
[SentrySDK.currentHub getInstalledIntegration:SentrySessionReplayIntegration.class];
SentrySessionReplayIntegration *replayIntegration
= (SentrySessionReplayIntegration *)[SentrySDK.currentHub
getInstalledIntegration:SentrySessionReplayIntegration.class];
[replayIntegration pause];
}

- (void)resume
{
SentrySessionReplayIntegration *replayIntegration =
[SentrySDK.currentHub getInstalledIntegration:SentrySessionReplayIntegration.class];
SentrySessionReplayIntegration *replayIntegration
= (SentrySessionReplayIntegration *)[SentrySDK.currentHub
getInstalledIntegration:SentrySessionReplayIntegration.class];
[replayIntegration resume];
}

- (void)start
{
SentrySessionReplayIntegration *replayIntegration
= (SentrySessionReplayIntegration *)[SentrySDK.currentHub
getInstalledIntegration:SentrySessionReplayIntegration.class];

if (replayIntegration == nil) {
SentryOptions *currentOptions = SentrySDK.currentHub.client.options;
replayIntegration =
[[SentrySessionReplayIntegration alloc] initForManualUse:currentOptions];

[SentrySDK.currentHub addInstalledIntegration:replayIntegration
name:NSStringFromClass(SentrySessionReplay.class)];
}

[replayIntegration start];
}

- (void)stop
{
SentrySessionReplayIntegration *replayIntegration
= (SentrySessionReplayIntegration *)[SentrySDK.currentHub
getInstalledIntegration:SentrySessionReplayIntegration.class];
[replayIntegration stop];
}

@end

#endif
83 changes: 58 additions & 25 deletions Sources/Sentry/SentrySessionReplayIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
*/
static SentryTouchTracker *_touchTracker;

static SentrySessionReplayIntegration *_installedInstance;

@interface SentrySessionReplayIntegration () <SentryReachabilityObserver>
- (void)newSceneActivate;
@end
Expand All @@ -50,9 +48,20 @@ @implementation SentrySessionReplayIntegration {
SentryOnDemandReplay *_resumeReplayMaker;
}

+ (nullable SentrySessionReplayIntegration *)installed
- (instancetype)init
{
self = [super init];
return self;
}

- (instancetype)initForManualUse:(nonnull SentryOptions *)options
{
return _installedInstance;
if (self = [super init]) {
[self setupWith:options.experimental.sessionReplay
enableTouchTracker:options.enableSwizzling];
[self startWithOptions:options.experimental.sessionReplay fullSession:YES];
}
return self;
}

- (BOOL)installWithOptions:(nonnull SentryOptions *)options
Expand All @@ -61,14 +70,19 @@ - (BOOL)installWithOptions:(nonnull SentryOptions *)options
return NO;
}

_replayOptions = options.experimental.sessionReplay;
_viewPhotographer =
[[SentryViewPhotographer alloc] initWithRedactOptions:options.experimental.sessionReplay];
[self setupWith:options.experimental.sessionReplay enableTouchTracker:options.enableSwizzling];
return YES;
}

- (void)setupWith:(SentryReplayOptions *)replayOptions enableTouchTracker:(BOOL)touchTracker
{
_replayOptions = replayOptions;
_viewPhotographer = [[SentryViewPhotographer alloc] initWithRedactOptions:replayOptions];

if (options.enableSwizzling) {
if (touchTracker) {
_touchTracker = [[SentryTouchTracker alloc]
initWithDateProvider:SentryDependencyContainer.sharedInstance.dateProvider
scale:options.experimental.sessionReplay.sizeScale];
scale:replayOptions.sizeScale];
[self swizzleApplicationTouch];
}

Expand All @@ -87,9 +101,6 @@ - (BOOL)installWithOptions:(nonnull SentryOptions *)options
}];

[SentryDependencyContainer.sharedInstance.reachability addObserver:self];

_installedInstance = self;
return YES;
}

/**
Expand Down Expand Up @@ -212,23 +223,30 @@ - (void)startSession
return;
}

[self runReplayForAvailableWindow];
}

- (void)runReplayForAvailableWindow
{
if (SentryDependencyContainer.sharedInstance.application.windows.count > 0) {
// If a window its already available start replay right away
[self startWithOptions:_replayOptions fullSession:_startedAsFullSession];
} else {
} else if (@available(iOS 13.0, tvOS 13.0, *)) {
// Wait for a scene to be available to started the replay
if (@available(iOS 13.0, tvOS 13.0, *)) {
[_notificationCenter addObserver:self
selector:@selector(newSceneActivate)
name:UISceneDidActivateNotification];
}
[_notificationCenter addObserver:self
selector:@selector(newSceneActivate)
name:UISceneDidActivateNotification];
}
}

- (void)newSceneActivate
{
[SentryDependencyContainer.sharedInstance.notificationCenterWrapper removeObserver:self];
[self startWithOptions:_replayOptions fullSession:_startedAsFullSession];
if (@available(iOS 13.0, tvOS 13.0, *)) {
[SentryDependencyContainer.sharedInstance.notificationCenterWrapper
removeObserver:self
name:UISceneDidActivateNotification];
[self startWithOptions:_replayOptions fullSession:_startedAsFullSession];
}
}

- (void)startWithOptions:(SentryReplayOptions *)replayOptions
Expand Down Expand Up @@ -277,7 +295,7 @@ - (void)startWithOptions:(SentryReplayOptions *)replayOptions

[self.sessionReplay
startWithRootView:SentryDependencyContainer.sharedInstance.application.windows.firstObject
fullSession:[self shouldReplayFullSession:replayOptions.sessionSampleRate]];
fullSession:shouldReplayFullSession];

[_notificationCenter addObserver:self
selector:@selector(pause)
Expand Down Expand Up @@ -351,6 +369,25 @@ - (void)resume
[self.sessionReplay resume];
}

- (void)start
{
if (self.sessionReplay != nil) {
if (self.sessionReplay.isFullSession == NO) {
[self.sessionReplay captureReplay];
}
return;
}

_startedAsFullSession = YES;
[self runReplayForAvailableWindow];
}

- (void)stop
{
[self.sessionReplay pause];
self.sessionReplay = nil;
}

- (void)sentrySessionEnded:(SentrySession *)session
{
[self pause];
Expand Down Expand Up @@ -395,10 +432,6 @@ - (void)uninstall
[SentrySDK.currentHub unregisterSessionListener:self];
_touchTracker = nil;
[self pause];

if (_installedInstance == self) {
_installedInstance = nil;
}
}

- (void)dealloc
Expand Down
Loading

0 comments on commit d7c5b54

Please sign in to comment.