-
-
Notifications
You must be signed in to change notification settings - Fork 341
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
fix: Propagate span when copying scope #2952
fix: Propagate span when copying scope #2952
Conversation
@@ -108,6 +108,36 @@ class SentryScopeSwiftTests: XCTestCase { | |||
XCTAssertNil(actual["transaction"]) | |||
XCTAssertNotNil(actual["breadcrumbs"]) | |||
} | |||
|
|||
func testInitWithScope() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is mostly a direct translation of the ObjC version, but with the addition of a check that calling cloned.applyTo
has the same effect as calling it on the original scope. The new check would have failed without the change to the copy constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some validation for assigning self.span = scope.span
in the initWithScope
. So basically if I remove self.span = scope.span
from initWithScope
this test should fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, this was what the Event
comparison was supposed to validate, but I forgot to assign a span to the scope. Removing that line goes from green -> red as expected now.
Thanks for the PR, @kabiroberai. We didn't get to this today, but we'll have a look tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @kabiroberai. Could you please split this PR up into two PRs? One for fixing the copy and another one for startWithOptions:andScope
. Those are two independent changes, and they should have extra Changelog entries, PR titles etc.
Before you open the PR for startWithOptions:andScope
, we still need to clarify if we want to add this method to the SDK cause it's not part of our unified API, and maybe we want to add it to all of our SDKs with a static API. I will get back to you.
@kabiroberai, could you elaborate on the race condition you experience between |
57f55f3
to
bc83334
Compare
👍 moved the Taking a step back, the reason we need to subclass |
@kabiroberai, JavaScript the concept of the initialScope on the options. We could do the same on Cocoa. I guess that would work for you.
At some point, we should implement thread-local hubs, but if initialScope solves your problem, I would like to delay that a bit, as initialScope is also useful for other users. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this @kabiroberai 👏
Please add an entry to the changelog under a section Fixed with Propagate span when copying scope
. CI fails for the benchmarks and release builds, cause that doesn't work for contributors yet. Just focus on the lints and unit tests. FYI, our unit test are a bit flaky at the moment. We did several fixes on the main branch, so merging main into this PR should help.
@@ -108,6 +108,36 @@ class SentryScopeSwiftTests: XCTestCase { | |||
XCTAssertNil(actual["transaction"]) | |||
XCTAssertNotNil(actual["breadcrumbs"]) | |||
} | |||
|
|||
func testInitWithScope() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some validation for assigning self.span = scope.span
in the initWithScope
. So basically if I remove self.span = scope.span
from initWithScope
this test should fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kabiroberai !!
This looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @kabiroberai 💯; LGTM. Just waiting for CI to be green.
I will fix the Changelog entry so that we can merge this PR. |
📜 Description
This PR updates the
SentryScope
copy constructor to copy over the parent's span.💡 Motivation and Context
Previously, copied scopes (such as those created in
-[SentrySDK captureEvent:withScopeBlock:]
) did not inherit the original scope'sspan
. This resulted in emitted events not linking back to the relevant span. Other SDKs do copy over the parent span/transaction (for example here's the equivalent code in sentry-java).💚 How did you test it?
I tested these changes in a production iOS app, ensuring that spans now propagate as expected.
📝 Checklist
You have to check all boxes before merging:
sendDefaultPII
is enabled.