Skip to content

Commit

Permalink
Hub uses its scope (#1821)
Browse files Browse the repository at this point in the history
When calling capture without the scope parameter, the hub created a new
empty scope. Instead, the hub should use its scope when calling such
methods.
  • Loading branch information
philipphofmann committed May 11, 2022
1 parent ec2bc56 commit b1ce7c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Allow partial SDK info override (#1816)

### Fixes

- Hub uses its scope (#1821)

## 7.15.0

### Features
Expand Down
8 changes: 4 additions & 4 deletions Sources/Sentry/SentryHub.m
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ - (SentryId *)captureTransaction:(SentryTransaction *)transaction

- (SentryId *)captureEvent:(SentryEvent *)event
{
return [self captureEvent:event withScope:[[SentryScope alloc] init]];
return [self captureEvent:event withScope:self.scope];
}

- (SentryId *)captureEvent:(SentryEvent *)event withScope:(SentryScope *)scope
Expand Down Expand Up @@ -344,7 +344,7 @@ - (SentryId *)captureEvent:(SentryEvent *)event

- (SentryId *)captureMessage:(NSString *)message
{
return [self captureMessage:message withScope:[[SentryScope alloc] init]];
return [self captureMessage:message withScope:self.scope];
}

- (SentryId *)captureMessage:(NSString *)message withScope:(SentryScope *)scope
Expand All @@ -358,7 +358,7 @@ - (SentryId *)captureMessage:(NSString *)message withScope:(SentryScope *)scope

- (SentryId *)captureError:(NSError *)error
{
return [self captureError:error withScope:[[SentryScope alloc] init]];
return [self captureError:error withScope:self.scope];
}

- (SentryId *)captureError:(NSError *)error withScope:(SentryScope *)scope
Expand All @@ -377,7 +377,7 @@ - (SentryId *)captureError:(NSError *)error withScope:(SentryScope *)scope

- (SentryId *)captureException:(NSException *)exception
{
return [self captureException:exception withScope:[[SentryScope alloc] init]];
return [self captureException:exception withScope:self.scope];
}

- (SentryId *)captureException:(NSException *)exception withScope:(SentryScope *)scope
Expand Down
16 changes: 8 additions & 8 deletions Tests/SentryTests/SentryHubTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ class SentryHubTests: XCTestCase {
}

func testCaptureEventWithoutScope() {
fixture.getSut().capture(event: fixture.event)
fixture.getSut(fixture.options, fixture.scope).capture(event: fixture.event)

XCTAssertEqual(1, fixture.client.captureEventWithScopeInvocations.count)
if let eventArguments = fixture.client.captureEventWithScopeInvocations.first {
XCTAssertEqual(fixture.event.eventId, eventArguments.event.eventId)
XCTAssertEqual(Scope(), eventArguments.scope)
XCTAssertEqual(fixture.scope, eventArguments.scope)
}
}

Expand Down Expand Up @@ -377,12 +377,12 @@ class SentryHubTests: XCTestCase {
}

func testCaptureMessageWithoutScope() {
fixture.getSut().capture(message: fixture.message)
fixture.getSut(fixture.options, fixture.scope).capture(message: fixture.message)

XCTAssertEqual(1, fixture.client.captureMessageWithScopeInvocations.count)
if let messageArguments = fixture.client.captureMessageWithScopeInvocations.first {
XCTAssertEqual(fixture.message, messageArguments.message)
XCTAssertEqual(Scope(), messageArguments.scope)
XCTAssertEqual(fixture.scope, messageArguments.scope)
}
}

Expand Down Expand Up @@ -416,12 +416,12 @@ class SentryHubTests: XCTestCase {
}

func testCatpureErrorWithoutScope() {
fixture.getSut().capture(error: fixture.error).assertIsNotEmpty()
fixture.getSut(fixture.options, fixture.scope).capture(error: fixture.error).assertIsNotEmpty()

XCTAssertEqual(1, fixture.client.captureErrorWithScopeInvocations.count)
if let errorArguments = fixture.client.captureErrorWithScopeInvocations.first {
XCTAssertEqual(fixture.error, errorArguments.error as NSError)
XCTAssertEqual(Scope(), errorArguments.scope)
XCTAssertEqual(fixture.scope, errorArguments.scope)
}
}

Expand All @@ -436,12 +436,12 @@ class SentryHubTests: XCTestCase {
}

func testCatpureExceptionWithoutScope() {
fixture.getSut().capture(exception: fixture.exception).assertIsNotEmpty()
fixture.getSut(fixture.options, fixture.scope).capture(exception: fixture.exception).assertIsNotEmpty()

XCTAssertEqual(1, fixture.client.captureExceptionWithScopeInvocations.count)
if let errorArguments = fixture.client.captureExceptionWithScopeInvocations.first {
XCTAssertEqual(fixture.exception, errorArguments.exception)
XCTAssertEqual(Scope(), errorArguments.scope)
XCTAssertEqual(fixture.scope, errorArguments.scope)
}
}

Expand Down

0 comments on commit b1ce7c5

Please sign in to comment.