Skip to content

Commit

Permalink
Adds breadcrumb.origin field
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis committed Sep 20, 2024
1 parent 90e653b commit bb67cef
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/Sentry/Public/SentryBreadcrumb.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ NS_SWIFT_NAME(Breadcrumb)
*/
@property (nonatomic, copy) NSString *_Nullable type;

/**
* Origin of the breadcrumb that is used to identify source of the breadcrumb
* For example hybrid SDKs can identify native breadcrumbs from JS or Flutter
*/
@property (nonatomic, copy) NSString *_Nullable origin;

/**
* Message for the breadcrumb
*/
Expand Down
6 changes: 6 additions & 0 deletions Sources/Sentry/SentryBreadcrumb.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
self.category = value;
} else if ([key isEqualToString:@"type"] && isString) {
self.type = value;
} else if ([key isEqualToString:@"origin"] && isString) {
self.origin = value;
} else if ([key isEqualToString:@"message"] && isString) {
self.message = value;
} else if ([key isEqualToString:@"data"] && isDictionary) {
Expand Down Expand Up @@ -69,6 +71,7 @@ - (instancetype)init
[serializedData setValue:sentry_toIso8601String(self.timestamp) forKey:@"timestamp"];
[serializedData setValue:self.category forKey:@"category"];
[serializedData setValue:self.type forKey:@"type"];
[serializedData setValue:self.origin forKey:@"origin"];
[serializedData setValue:self.message forKey:@"message"];
[serializedData setValue:sentry_sanitize(self.data) forKey:@"data"];
NSDictionary<NSString *, id> *unknown = self.unknown;
Expand Down Expand Up @@ -106,6 +109,8 @@ - (BOOL)isEqualToBreadcrumb:(SentryBreadcrumb *)breadcrumb
return NO;
if (self.type != breadcrumb.type && ![self.type isEqualToString:breadcrumb.type])
return NO;
if (self.origin != breadcrumb.origin && ![self.origin isEqualToString:breadcrumb.origin])
return NO;
if (self.message != breadcrumb.message && ![self.message isEqualToString:breadcrumb.message])
return NO;
if (self.data != breadcrumb.data && ![self.data isEqualToDictionary:breadcrumb.data])
Expand All @@ -123,6 +128,7 @@ - (NSUInteger)hash
hash = hash * 23 + [self.category hash];
hash = hash * 23 + [self.timestamp hash];
hash = hash * 23 + [self.type hash];
hash = hash * 23 + [self.origin hash];
hash = hash * 23 + [self.message hash];
hash = hash * 23 + [self.data hash];
hash = hash * 23 + [self.unknown hash];
Expand Down
1 change: 1 addition & 0 deletions Sources/Sentry/SentryCrashReportConverter.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ - (SentryUser *_Nullable)convertUser
category:storedCrumb[@"category"]];
crumb.message = storedCrumb[@"message"];
crumb.type = storedCrumb[@"type"];
crumb.origin = storedCrumb[@"origin"];
crumb.timestamp = sentry_fromIso8601String(storedCrumb[@"timestamp"]);
crumb.data = storedCrumb[@"data"];
[breadcrumbs addObject:crumb];
Expand Down
7 changes: 7 additions & 0 deletions Tests/SentryTests/Protocol/SentryBreadcrumbTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class SentryBreadcrumbTests: XCTestCase {

let category = "category"
let type = "user"
let origin = "origin"
let message = "Click something"

init() {
Expand All @@ -18,6 +19,7 @@ class SentryBreadcrumbTests: XCTestCase {
breadcrumb.timestamp = date
breadcrumb.category = category
breadcrumb.type = type
breadcrumb.origin = origin
breadcrumb.message = message
breadcrumb.data = ["some": ["data": "data", "date": date] as [String: Any]]
breadcrumb.setValue(["foo": "bar"], forKey: "unknown")
Expand All @@ -36,6 +38,7 @@ class SentryBreadcrumbTests: XCTestCase {
"timestamp": fixture.dateAs8601String,
"category": fixture.category,
"type": fixture.type,
"origin": fixture.origin,
"message": fixture.message,
"data": ["foo": "bar"],
"foo": "bar" // Unknown
Expand All @@ -46,6 +49,7 @@ class SentryBreadcrumbTests: XCTestCase {
XCTAssertEqual(breadcrumb.timestamp, fixture.date)
XCTAssertEqual(breadcrumb.category, fixture.category)
XCTAssertEqual(breadcrumb.type, fixture.type)
XCTAssertEqual(breadcrumb.origin, fixture.origin)
XCTAssertEqual(breadcrumb.message, fixture.message)
XCTAssertEqual(breadcrumb.data as? [String: String], ["foo": "bar"])
XCTAssertEqual(breadcrumb.value(forKey: "unknown") as? NSDictionary, ["foo": "bar"])
Expand Down Expand Up @@ -79,6 +83,7 @@ class SentryBreadcrumbTests: XCTestCase {
testIsNotEqual { breadcrumb in breadcrumb.category = "" }
testIsNotEqual { breadcrumb in breadcrumb.timestamp = Date() }
testIsNotEqual { breadcrumb in breadcrumb.type = "" }
testIsNotEqual { breadcrumb in breadcrumb.origin = "" }
testIsNotEqual { breadcrumb in breadcrumb.message = "" }
testIsNotEqual { breadcrumb in breadcrumb.data?.removeAll() }
testIsNotEqual { breadcrumb in breadcrumb.setValue(nil, forKey: "unknown") }
Expand All @@ -99,6 +104,7 @@ class SentryBreadcrumbTests: XCTestCase {
crumb.timestamp = nil
crumb.category = ""
crumb.type = ""
crumb.origin = ""
crumb.message = ""
crumb.data = nil
crumb.setValue(nil, forKey: "unknown")
Expand All @@ -107,6 +113,7 @@ class SentryBreadcrumbTests: XCTestCase {
XCTAssertEqual(fixture.dateAs8601String, actual["timestamp"] as? String)
XCTAssertEqual(fixture.category, actual["category"] as? String)
XCTAssertEqual(fixture.type, actual["type"] as? String)
XCTAssertEqual(fixture.origin, actual["origin"] as? String)
XCTAssertEqual(fixture.message, actual["message"] as? String)
XCTAssertEqual(["some": ["data": "data", "date": fixture.dateAs8601String]], actual["data"] as? Dictionary)
XCTAssertEqual("bar", actual["foo"] as? String)
Expand Down
2 changes: 2 additions & 0 deletions Tests/SentryTests/SentryInterfacesTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,12 @@ - (void)testBreadcrumb
crumb2.type = @"type";
crumb2.timestamp = date;
crumb2.message = @"message";
crumb2.origin = @"origin";
NSDictionary *serialized2 = @{
@"level" : @"info",
@"type" : @"type",
@"message" : @"message",
@"origin" : @"origin",
@"timestamp" : sentry_toIso8601String(date),
@"category" : @"http",
@"data" : @ { @"bla" : @"1" },
Expand Down
1 change: 1 addition & 0 deletions Tests/SentryTests/SentryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ - (void)testSDKBreadCrumbAdd
SentryBreadcrumb *crumb = [[SentryBreadcrumb alloc] initWithLevel:kSentryLevelInfo
category:@"testCategory"];
crumb.type = @"testType";
crumb.origin = @"testOrigin";
crumb.message = @"testMessage";
crumb.data = @{ @"testDataKey" : @"testDataVaue" };

Expand Down

0 comments on commit bb67cef

Please sign in to comment.