Skip to content

Commit

Permalink
feat: Send debug meta for app start transactions (#3543)
Browse files Browse the repository at this point in the history
Send the complete list of debug meta for app start transactions so we
can calculate statistics on the number and size of libraries loaded on
the backend when the app starts.

Fixes GH-3541
  • Loading branch information
philipphofmann committed Jan 10, 2024
1 parent dbaf866 commit 9901d21
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 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 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
26 changes: 26 additions & 0 deletions Tests/SentryTests/Transaction/SentryTracerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SentryTracerTests: XCTestCase {
let hub: TestHub
let scope: Scope
let dispatchQueue = TestSentryDispatchQueueWrapper()
let debugImageProvider = TestDebugImageProvider()
let timerFactory = TestSentryNSTimerFactory()

let transactionName = "Some Transaction"
Expand Down Expand Up @@ -53,6 +54,9 @@ class SentryTracerTests: XCTestCase {

SentryDependencyContainer.sharedInstance().dateProvider = currentDateProvider
SentryDependencyContainer.sharedInstance().dispatchQueueWrapper = dispatchQueue

debugImageProvider.debugImages = [TestData.debugImage]
SentryDependencyContainer.sharedInstance().debugImageProvider = debugImageProvider
appStart = currentDateProvider.date()
appStartEnd = appStart.addingTimeInterval(appStartDuration)

Expand Down Expand Up @@ -865,6 +869,28 @@ class SentryTracerTests: XCTestCase {

assertAppStartMeasurementNotPutOnTransaction()
}

func testAppStartTransaction_AddsDebugMeta() {
let appStartMeasurement = fixture.getAppStartMeasurement(type: .cold)
SentrySDK.setAppStartMeasurement(appStartMeasurement)

whenFinishingAutoUITransaction(startTimestamp: 5)

expect(self.fixture.hub.capturedEventsWithScopes.count) == 1
let serializedTransaction = fixture.hub.capturedEventsWithScopes.first?.event.serialize()

let debugMeta = serializedTransaction?["debug_meta"] as? [String: Any]
expect(debugMeta?.count) == fixture.debugImageProvider.getDebugImagesCrashed(false).count
}

func testNoAppStartTransaction_AddsNoDebugMeta() {
whenFinishingAutoUITransaction(startTimestamp: 5)

expect(self.fixture.hub.capturedEventsWithScopes.count) == 1
let serializedTransaction = fixture.hub.capturedEventsWithScopes.first?.event.serialize()

expect(serializedTransaction?["debug_meta"]) == nil
}

#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)

Expand Down

0 comments on commit 9901d21

Please sign in to comment.