Skip to content

Commit

Permalink
Merge branch 'main' into armcknight/test/sample-app-tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight authored Jan 8, 2024
2 parents a8a08c7 + 1734d1b commit b6afade
Show file tree
Hide file tree
Showing 19 changed files with 162 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ jobs:

- run: ./test-server-exec &

- name: Check test-server runs
run: curl http://localhost:8080/echo-baggage-header

- run: ./scripts/ci-select-xcode.sh

- name: Running tests with ThreadSanitizer
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Send debug meta for app start transactions (#3543)

## 8.18.0

### Features
Expand All @@ -19,6 +25,7 @@
- Use correct rendered frames timestamp for TTID/TTFD and app start (#3531)

- Missing transactions when not calling `reportFullyDisplayed` (#3477)
- Don't override `sentry-trace` and `baggage` headers (#3540)

## 8.17.2

Expand Down
11 changes: 10 additions & 1 deletion Samples/iOS-Swift/iOS-Swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

options.initialScope = { scope in
scope.setEnvironment("debug")
let processInfoEnvironment = ProcessInfo.processInfo.environment["io.sentry.sdk-environment"]

if processInfoEnvironment != nil {
scope.setEnvironment(processInfoEnvironment)
} else if isBenchmarking {
scope.setEnvironment("benchmarking")
} else {
scope.setEnvironment("debug")
}

scope.setTag(value: "swift", key: "language")

let user = User(userId: "1")
Expand Down
1 change: 1 addition & 0 deletions Samples/iOS-Swift/iOS-SwiftUITests/BaseUITest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class BaseUITest: XCTestCase {
continueAfterFailure = false
XCUIDevice.shared.orientation = .portrait
app.launchEnvironment["io.sentry.ui-test.test-name"] = name
app.launchEnvironment["io.sentry.sdk-environment"] = "ui-tests"
app.launch()

waitForExistenceOfMainScreen()
Expand Down
8 changes: 6 additions & 2 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
620379DD2AFE1432005AC0C1 /* SentryBuildAppStartSpans.m in Sources */ = {isa = PBXBuildFile; fileRef = 620379DC2AFE1432005AC0C1 /* SentryBuildAppStartSpans.m */; };
622C08D829E546F4002571D4 /* SentryTraceOrigins.h in Headers */ = {isa = PBXBuildFile; fileRef = 622C08D729E546F4002571D4 /* SentryTraceOrigins.h */; };
622C08DB29E554B9002571D4 /* SentrySpanContext+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 622C08D929E554B9002571D4 /* SentrySpanContext+Private.h */; };
62375FB92B47F9F000CC55F1 /* SentryDependencyContainerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62375FB82B47F9F000CC55F1 /* SentryDependencyContainerTests.swift */; };
623C45B02A651D8200D9E88B /* SentryCoreDataTracker+Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 623C45AF2A651D8200D9E88B /* SentryCoreDataTracker+Test.m */; };
627E7589299F6FE40085504D /* SentryInternalDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 627E7588299F6FE40085504D /* SentryInternalDefines.h */; };
62862B1C2B1DDBC8009B16E3 /* SentryDelayedFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 62862B1B2B1DDBC8009B16E3 /* SentryDelayedFrame.h */; };
Expand All @@ -92,9 +93,9 @@
62A456E52B0370E0003F19A1 /* SentryUIEventTrackerTransactionMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 62A456E42B0370E0003F19A1 /* SentryUIEventTrackerTransactionMode.m */; };
62B86CFC29F052BB008F3947 /* SentryTestLogConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 62B86CFB29F052BB008F3947 /* SentryTestLogConfig.m */; };
62C25C862B075F4900C68CBD /* TestOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62C25C852B075F4900C68CBD /* TestOptions.swift */; };
62C3168B2B1F865A000D7031 /* SentryTimeSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62C3168A2B1F865A000D7031 /* SentryTimeSwiftTests.swift */; };
62C316812B1F2E93000D7031 /* SentryDelayedFramesTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 62C316802B1F2E93000D7031 /* SentryDelayedFramesTracker.h */; };
62C316832B1F2EA1000D7031 /* SentryDelayedFramesTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 62C316822B1F2EA1000D7031 /* SentryDelayedFramesTracker.m */; };
62C3168B2B1F865A000D7031 /* SentryTimeSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62C3168A2B1F865A000D7031 /* SentryTimeSwiftTests.swift */; };
62E081A929ED4260000F69FC /* SentryBreadcrumbDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 62E081A829ED4260000F69FC /* SentryBreadcrumbDelegate.h */; };
62E081AB29ED4322000F69FC /* SentryBreadcrumbTestDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E081AA29ED4322000F69FC /* SentryBreadcrumbTestDelegate.swift */; };
62F226B729A37C120038080D /* SentryBooleanSerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 62F226B629A37C120038080D /* SentryBooleanSerialization.m */; };
Expand Down Expand Up @@ -996,6 +997,7 @@
620379DC2AFE1432005AC0C1 /* SentryBuildAppStartSpans.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryBuildAppStartSpans.m; 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>"; };
62375FB82B47F9F000CC55F1 /* SentryDependencyContainerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDependencyContainerTests.swift; sourceTree = "<group>"; };
623C45AE2A651C4500D9E88B /* SentryCoreDataTracker+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryCoreDataTracker+Test.h"; sourceTree = "<group>"; };
623C45AF2A651D8200D9E88B /* SentryCoreDataTracker+Test.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "SentryCoreDataTracker+Test.m"; sourceTree = "<group>"; };
627E7588299F6FE40085504D /* SentryInternalDefines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryInternalDefines.h; path = include/SentryInternalDefines.h; sourceTree = "<group>"; };
Expand All @@ -1009,9 +1011,9 @@
62A456E42B0370E0003F19A1 /* SentryUIEventTrackerTransactionMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryUIEventTrackerTransactionMode.m; sourceTree = "<group>"; };
62B86CFB29F052BB008F3947 /* SentryTestLogConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryTestLogConfig.m; sourceTree = "<group>"; };
62C25C852B075F4900C68CBD /* TestOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestOptions.swift; sourceTree = "<group>"; };
62C3168A2B1F865A000D7031 /* SentryTimeSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTimeSwiftTests.swift; sourceTree = "<group>"; };
62C316802B1F2E93000D7031 /* SentryDelayedFramesTracker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDelayedFramesTracker.h; path = include/SentryDelayedFramesTracker.h; sourceTree = "<group>"; };
62C316822B1F2EA1000D7031 /* SentryDelayedFramesTracker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryDelayedFramesTracker.m; sourceTree = "<group>"; };
62C3168A2B1F865A000D7031 /* SentryTimeSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTimeSwiftTests.swift; sourceTree = "<group>"; };
62E081A829ED4260000F69FC /* SentryBreadcrumbDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryBreadcrumbDelegate.h; path = include/SentryBreadcrumbDelegate.h; sourceTree = "<group>"; };
62E081AA29ED4322000F69FC /* SentryBreadcrumbTestDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryBreadcrumbTestDelegate.swift; sourceTree = "<group>"; };
62F226B629A37C120038080D /* SentryBooleanSerialization.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryBooleanSerialization.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2866,6 +2868,7 @@
8431EE5A29ADB8EA00D8DC56 /* SentryTimeTests.m */,
62C3168A2B1F865A000D7031 /* SentryTimeSwiftTests.swift */,
33042A1629DC2C4300C60085 /* SentryExtraContextProviderTests.swift */,
62375FB82B47F9F000CC55F1 /* SentryDependencyContainerTests.swift */,
);
path = Helper;
sourceTree = "<group>";
Expand Down Expand Up @@ -4460,6 +4463,7 @@
7B18DE4A28DA0C8B004845C6 /* SentryNSNotificationCenterWrapperTests.swift in Sources */,
7BEFB044270B0F630025F808 /* SentryTracerObjCTests.m in Sources */,
7B0002322477F0520035FEF1 /* SentrySessionTests.m in Sources */,
62375FB92B47F9F000CC55F1 /* SentryDependencyContainerTests.swift in Sources */,
7BC6EC08255C36DE0059822A /* SentryStacktraceTests.swift in Sources */,
D88817DD26D72BA500BF2251 /* SentryTraceStateTests.swift in Sources */,
7B26BBFB24C0A66D00A79CCC /* SentrySdkInfoNilTests.m in Sources */,
Expand Down
3 changes: 0 additions & 3 deletions SentryTestUtils/ClearTestState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class TestCleanup: NSObject {
setTestDefaultLogLevel()

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
let framesTracker = SentryDependencyContainer.sharedInstance().framesTracker
framesTracker.stop()
framesTracker.resetFrames()

setenv("ActivePrewarm", "0", 1)
SentryAppStartTracker.load()
Expand Down
5 changes: 0 additions & 5 deletions Sources/Sentry/SentryBaggage.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ - (instancetype)initWithTraceId:(SentryId *)traceId
return self;
}

- (NSString *)toHTTPHeader
{
return [self toHTTPHeaderWithOriginalBaggage:nil];
}

- (NSString *)toHTTPHeaderWithOriginalBaggage:(NSDictionary *_Nullable)originalBaggage
{
NSMutableDictionary *information
Expand Down
8 changes: 6 additions & 2 deletions Sources/Sentry/SentryDependencyContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ + (instancetype)sharedInstance

+ (void)reset
{
#if !TARGET_OS_WATCH
if (instance) {
#if !TARGET_OS_WATCH
[instance->_reachability removeAllObservers];
}
#endif // !TARGET_OS_WATCH

#if SENTRY_HAS_UIKIT
[instance->_framesTracker stop];
#endif // SENTRY_HAS_UIKIT
}

instance = [[SentryDependencyContainer alloc] init];
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/Sentry/SentryFramesTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ - (void)setDisplayLinkWrapper:(SentryDisplayLinkWrapper *)displayLinkWrapper
_displayLinkWrapper = displayLinkWrapper;
}

/** Internal for testing */
- (void)resetFrames
{
_totalFrames = 0;
Expand Down Expand Up @@ -277,6 +276,9 @@ - (void)stop
_isRunning = NO;
[self.displayLinkWrapper invalidate];
[self.delayedFramesTracker resetDelayedFramesTimeStamps];
@synchronized(self.listeners) {
[self.listeners removeAllObjects];
}
}

- (void)dealloc
Expand Down
20 changes: 13 additions & 7 deletions Sources/Sentry/SentryNetworkTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,23 @@ - (void)addBaggageHeader:(SentryBaggage *)baggage
NSString *baggageHeader = @"";

if (baggage != nil) {
baggageHeader =
[baggage toHTTPHeaderWithOriginalBaggage:
[SentrySerialization
decodeBaggage:sessionTask.currentRequest
.allHTTPHeaderFields[SENTRY_BAGGAGE_HEADER]]];
NSDictionary *originalBaggage = [SentrySerialization
decodeBaggage:sessionTask.currentRequest.allHTTPHeaderFields[SENTRY_BAGGAGE_HEADER]];

if (originalBaggage[@"sentry-trace_id"] == nil) {
baggageHeader = [baggage toHTTPHeaderWithOriginalBaggage:originalBaggage];
}
}

// First we check if the current request is mutable, so we could easily add a new
// header. Otherwise we try to change the current request for a new one with the extra
// header.
if ([sessionTask.currentRequest isKindOfClass:[NSMutableURLRequest class]]) {
NSMutableURLRequest *currentRequest = (NSMutableURLRequest *)sessionTask.currentRequest;
[currentRequest setValue:traceHeader.value forHTTPHeaderField:SENTRY_TRACE_HEADER];

if ([currentRequest valueForHTTPHeaderField:SENTRY_TRACE_HEADER] == nil) {
[currentRequest setValue:traceHeader.value forHTTPHeaderField:SENTRY_TRACE_HEADER];
}

if (baggageHeader.length > 0) {
[currentRequest setValue:baggageHeader forHTTPHeaderField:SENTRY_BAGGAGE_HEADER];
Expand All @@ -265,7 +269,9 @@ - (void)addBaggageHeader:(SentryBaggage *)baggage
if ([sessionTask respondsToSelector:setCurrentRequestSelector]) {
NSMutableURLRequest *newRequest = [sessionTask.currentRequest mutableCopy];

[newRequest setValue:traceHeader.value forHTTPHeaderField:SENTRY_TRACE_HEADER];
if ([newRequest valueForHTTPHeaderField:SENTRY_TRACE_HEADER] == nil) {
[newRequest setValue:traceHeader.value forHTTPHeaderField:SENTRY_TRACE_HEADER];
}

if (baggageHeader.length > 0) {
[newRequest setValue:baggageHeader forHTTPHeaderField:SENTRY_BAGGAGE_HEADER];
Expand Down
6 changes: 6 additions & 0 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
@property (nonatomic, nullable, strong) NSTimer *deadlineTimer;
@property (nonnull, strong) SentryTracerConfiguration *configuration;
@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueue;
@property (nonatomic, strong) SentryDebugImageProvider *debugImageProvider;

#if SENTRY_TARGET_PROFILING_SUPPORTED
@property (nonatomic) BOOL isProfiling;
Expand Down Expand Up @@ -134,6 +135,7 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti
_startSystemTime = SentryDependencyContainer.sharedInstance.dateProvider.systemTime;
_configuration = configuration;
_dispatchQueue = SentryDependencyContainer.sharedInstance.dispatchQueueWrapper;
_debugImageProvider = SentryDependencyContainer.sharedInstance.debugImageProvider;

self.transactionContext = transactionContext;
_children = [[NSMutableArray alloc] init];
Expand Down Expand Up @@ -751,6 +753,10 @@ - (void)addAppStartMeasurements:(SentryTransaction *)transaction
NSDictionary *appContext = @{ @"app" : @ { @"start_type" : appStartType } };
[context mergeEntriesFromDictionary:appContext];
[transaction setContext:context];

// The backend calculates statistics on the number and size of debug images for app
// start transactions. Therefore, we add all debug images here.
transaction.debugMeta = [self.debugImageProvider getDebugImagesCrashed:NO];
}
}
}
Expand Down
1 change: 0 additions & 1 deletion Sources/Sentry/include/SentryBaggage.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ static NSString *const SENTRY_BAGGAGE_HEADER = @"baggage";
sampleRate:(nullable NSString *)sampleRate
sampled:(nullable NSString *)sampled;

- (NSString *)toHTTPHeader;
- (NSString *)toHTTPHeaderWithOriginalBaggage:(NSDictionary *_Nullable)originalBaggage;

@end
Expand Down
15 changes: 15 additions & 0 deletions Tests/SentryTests/Helper/SentryDependencyContainerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Nimble
import XCTest

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
final class SentryDependencyContainerTests: XCTestCase {

func testReset_CallsFramesTrackerStop() throws {
let framesTracker = SentryDependencyContainer.sharedInstance().framesTracker
framesTracker.start()
SentryDependencyContainer.reset()

expect(framesTracker.isRunning) == false
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ class SentryFramesTrackerTests: XCTestCase {
expect(self.fixture.sut.isRunning) == false
}

func testKeepFrames_WhenStopped() throws {
let sut = fixture.sut
sut.start()

let displayLink = fixture.displayLinkWrapper
displayLink.call()
displayLink.normalFrame()

sut.stop()

try assert(slow: 0, frozen: 0, total: 1)
}

func testStartAfterStopped_SubscribesTwiceToDisplayLink() {
let sut = fixture.sut
sut.start()
Expand Down Expand Up @@ -550,6 +563,22 @@ class SentryFramesTrackerTests: XCTestCase {

expect(listener.newFrameInvocations.count) == 0
}

func testListenerNotCalledAfterCallingStop() {
let sut = fixture.sut
let listener1 = FrameTrackerListener()
let listener2 = FrameTrackerListener()
sut.start()
sut.add(listener1)
sut.stop()
sut.start()
sut.add(listener2)

fixture.displayLinkWrapper.normalFrame()

expect(listener1.newFrameInvocations.count) == 0
expect(listener2.newFrameInvocations.count) == 1
}

func testReleasedListener() {
let sut = fixture.sut
Expand Down Expand Up @@ -617,13 +646,13 @@ private extension SentryFramesTrackerTests {
func assert(slow: UInt? = nil, frozen: UInt? = nil, total: UInt? = nil, frameRates: UInt? = nil) throws {
let currentFrames = fixture.sut.currentFrames
if let total = total {
XCTAssertEqual(total, currentFrames.total)
expect(currentFrames.total) == total
}
if let slow = slow {
XCTAssertEqual(slow, currentFrames.slow)
expect(currentFrames.slow) == slow
}
if let frozen = frozen {
XCTAssertEqual(frozen, currentFrames.frozen)
expect(currentFrames.frozen) == frozen
}

#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class SentryNetworkTrackerIntegrationTests: XCTestCase {
self.assertNetworkError(error)
let response = String(data: data ?? Data(), encoding: .utf8) ?? ""

let expectedBaggageHeader = transaction.traceContext.toBaggage().toHTTPHeader()
let expectedBaggageHeader = transaction.traceContext.toBaggage().toHTTPHeader(withOriginalBaggage: nil)
XCTAssertEqual(expectedBaggageHeader, response)

expect.fulfill()
Expand Down
Loading

0 comments on commit b6afade

Please sign in to comment.