Skip to content

Commit

Permalink
feat: Add synthetic for mechanism (#2501)
Browse files Browse the repository at this point in the history
Add synthetic property for SentryMechanism.
  • Loading branch information
philipphofmann authored Dec 7, 2022
1 parent f8045b6 commit 2bdea22
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This version adds a dependency on Swift.

- Properly demangle Swift class name (#2162)
- Enable File I/O APM by default (#2497)
- Add synthetic for mechanism (#2501)

### Fixes

Expand Down
6 changes: 6 additions & 0 deletions Sources/Sentry/Public/SentryMechanism.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ SENTRY_NO_INIT
*/
@property (nonatomic, copy) NSNumber *_Nullable handled;

/**
* An optional flag indicating a synthetic exception. For more info visit
* https://develop.sentry.dev/sdk/event-payloads/exception/#exception-mechanism.
*/
@property (nonatomic, copy, nullable) NSNumber *synthetic;

/**
* Fully qualified URL to an online help resource, possible
* interpolated with error parameters
Expand Down
1 change: 1 addition & 0 deletions Sources/Sentry/SentryMechanism.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ - (instancetype)initWithType:(NSString *)type
NSMutableDictionary *serializedData = @{ @"type" : self.type }.mutableCopy;

[serializedData setValue:self.handled forKey:@"handled"];
[serializedData setValue:self.synthetic forKey:@"synthetic"];
[serializedData setValue:self.desc forKey:@"description"];
[serializedData setValue:[self.data sentry_sanitize] forKey:@"data"];
[serializedData setValue:self.helpLink forKey:@"help_link"];
Expand Down
10 changes: 10 additions & 0 deletions Tests/SentryTests/Protocol/SentryMechanismTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SentryMechanismTests: XCTestCase {
XCTAssertEqual(expected.type, actual["type"] as! String)
XCTAssertEqual(expected.desc, actual["description"] as? String)
XCTAssertEqual(expected.handled, actual["handled"] as? NSNumber)
XCTAssertEqual(expected.synthetic, actual["synthetic"] as? NSNumber)
XCTAssertEqual(expected.helpLink, actual["help_link"] as? String)

guard let something = (actual["data"] as? [String: Any])?["something"] as? [String: Any] else {
Expand All @@ -28,4 +29,13 @@ class SentryMechanismTests: XCTestCase {

XCTAssertNotNil(actual["meta"])
}

func testSerialize_OnlyType_NullablePropertiesNotAdded() {
let type = "type"
let mechanism = Mechanism(type: type)

let actual = mechanism.serialize()
XCTAssertEqual(1, actual.count)
XCTAssertEqual(type, actual["type"] as? String)
}
}
1 change: 1 addition & 0 deletions Tests/SentryTests/Protocol/TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class TestData {
mechanism.data = ["something": ["date": currentDateProvider.date()]]
mechanism.desc = "desc"
mechanism.handled = true
mechanism.synthetic = false
mechanism.helpLink = "https://www.sentry.io"
mechanism.meta = mechanismMeta

Expand Down

0 comments on commit 2bdea22

Please sign in to comment.