Skip to content

Commit

Permalink
ref: Send frames for all spans
Browse files Browse the repository at this point in the history
Initially, we wanted to send frame data only for spans started on the
main thread, but we decided that the frame data makes sense for all
spans. This PR fixes that.
  • Loading branch information
philipphofmann committed Dec 5, 2023
1 parent ef5821b commit 47ae280
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Features

- Add slow and frozen frames to spans (#3450)
- Add slow and frozen frames to spans (#3450, #3478)

## 8.17.1

Expand Down
21 changes: 10 additions & 11 deletions Sources/Sentry/SentrySpan.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,21 @@ - (instancetype)initWithContext:(SentrySpanContext *)context

if ([NSThread isMainThread]) {
_data[SPAN_DATA_THREAD_NAME] = @"main";

#if SENTRY_HAS_UIKIT
// Only track frames if running on main thread.
_framesTracker = framesTracker;
if (_framesTracker.isRunning) {
SentryScreenFrames *currentFrames = _framesTracker.currentFrames;
initTotalFrames = currentFrames.total;
initSlowFrames = currentFrames.slow;
initFrozenFrames = currentFrames.frozen;
}
#endif // SENTRY_HAS_UIKIT
} else {
_data[SPAN_DATA_THREAD_NAME] = [SentryDependencyContainer.sharedInstance.threadInspector
getThreadName:currentThread];
}

#if SENTRY_HAS_UIKIT
_framesTracker = framesTracker;
if (_framesTracker.isRunning) {
SentryScreenFrames *currentFrames = _framesTracker.currentFrames;
initTotalFrames = currentFrames.total;
initSlowFrames = currentFrames.slow;
initFrozenFrames = currentFrames.frozen;
}
#endif // SENTRY_HAS_UIKIT

_tags = [[NSMutableDictionary alloc] init];
_stateLock = [[NSObject alloc] init];
_isFinished = NO;
Expand Down
9 changes: 4 additions & 5 deletions Tests/SentryTests/Transaction/SentrySpanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ class SentrySpanTests: XCTestCase {
expect(sut.data["frames.frozen"]) == nil
}

func testDontAddZeroSlowFrozenFrames_WhenSpanStartedBackgroundThread() {
func testAddZeroSlowFrozenFrames_WhenSpanStartedBackgroundThread() {
let (displayLinkWrapper, framesTracker) = givenFramesTracker()

let expectation = expectation(description: "SpanStarted on a background thread")
Expand All @@ -513,10 +513,9 @@ class SentrySpanTests: XCTestCase {

sut.finish()

expect(sut.data["frames.total"]) == nil
expect(sut.data["frames.slow"]) == nil
expect(sut.data["frames.frozen"]) == nil

expect(sut.data["frames.total"] as? NSNumber) == NSNumber(value: slow + frozen + normal)
expect(sut.data["frames.slow"] as? NSNumber) == NSNumber(value: slow)
expect(sut.data["frames.frozen"] as? NSNumber) == NSNumber(value: frozen)
expectation.fulfill()
}

Expand Down

0 comments on commit 47ae280

Please sign in to comment.