Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Send frames for all spans #3478

Merged
merged 1 commit into from
Dec 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need any kind of synchronization now that it's multithreaded?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philipphofmann please look into this and open a subsequent PR if necessary.

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