From d26797f3d83e1430d4b62f164788929cb6e416dd Mon Sep 17 00:00:00 2001 From: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com> Date: Tue, 9 Jul 2024 10:37:36 +0200 Subject: [PATCH] fix(replay): SR Breadcrumbs include level name as a string (#4141) --- CHANGELOG.md | 6 ++++++ Sources/Sentry/SentryLevelHelper.m | 6 ++++++ Sources/Sentry/include/SentryLevelHelper.h | 2 ++ .../RRWeb/SentryRRWebBreadcrumbEvent.swift | 4 ++-- .../SentrySRDefaultBreadcrumbConverterTests.swift | 12 ++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dae12f15062..5864a914e07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Sentry Replay Serialized Breadcrumbs include level name ([#4141](https://github.com/getsentry/sentry-cocoa/pull/4141)) + ## 8.30.0 ### Features diff --git a/Sources/Sentry/SentryLevelHelper.m b/Sources/Sentry/SentryLevelHelper.m index b27ed2365d7..a2acd95b580 100644 --- a/Sources/Sentry/SentryLevelHelper.m +++ b/Sources/Sentry/SentryLevelHelper.m @@ -1,5 +1,6 @@ #import "SentryLevelHelper.h" #import "SentryBreadcrumb+Private.h" +#import "SentryLevelMapper.h" @implementation SentryLevelHelper @@ -8,4 +9,9 @@ + (NSUInteger)breadcrumbLevel:(SentryBreadcrumb *)breadcrumb return breadcrumb.level; } ++ (NSString *_Nonnull)getNameFor:(NSUInteger)level +{ + return nameForSentryLevel(level); +} + @end diff --git a/Sources/Sentry/include/SentryLevelHelper.h b/Sources/Sentry/include/SentryLevelHelper.h index e599cfe6298..b617d8b6ad5 100644 --- a/Sources/Sentry/include/SentryLevelHelper.h +++ b/Sources/Sentry/include/SentryLevelHelper.h @@ -11,6 +11,8 @@ NS_ASSUME_NONNULL_BEGIN + (NSUInteger)breadcrumbLevel:(SentryBreadcrumb *)breadcrumb; ++ (NSString *_Nonnull)getNameFor:(NSUInteger)level; + @end NS_ASSUME_NONNULL_END diff --git a/Sources/Swift/Integrations/SessionReplay/RRWeb/SentryRRWebBreadcrumbEvent.swift b/Sources/Swift/Integrations/SessionReplay/RRWeb/SentryRRWebBreadcrumbEvent.swift index 0b7fa8cf469..d68f5717b3f 100644 --- a/Sources/Swift/Integrations/SessionReplay/RRWeb/SentryRRWebBreadcrumbEvent.swift +++ b/Sources/Swift/Integrations/SessionReplay/RRWeb/SentryRRWebBreadcrumbEvent.swift @@ -4,8 +4,8 @@ import Foundation class SentryRRWebBreadcrumbEvent: SentryRRWebCustomEvent { init(timestamp: Date, category: String, message: String? = nil, level: SentryLevel = .none, data: [String: Any]? = nil) { - var payload: [String: Any] = ["type": "default", "category": category, "level": level.rawValue, "timestamp": timestamp.timeIntervalSince1970 ] - + var payload: [String: Any] = ["type": "default", "category": category, "level": SentryLevelHelper.getNameFor(level.rawValue), "timestamp": timestamp.timeIntervalSince1970 ] + if let message = message { payload["message"] = message } diff --git a/Tests/SentryTests/Integrations/SessionReplay/SentrySRDefaultBreadcrumbConverterTests.swift b/Tests/SentryTests/Integrations/SessionReplay/SentrySRDefaultBreadcrumbConverterTests.swift index 60befc92bb9..bc4789ad201 100644 --- a/Tests/SentryTests/Integrations/SessionReplay/SentrySRDefaultBreadcrumbConverterTests.swift +++ b/Tests/SentryTests/Integrations/SessionReplay/SentrySRDefaultBreadcrumbConverterTests.swift @@ -147,4 +147,16 @@ class SentrySRDefaultBreadcrumbConverterTests: XCTestCase { XCTAssertEqual(payload["message"] as? String, "Custom message") XCTAssertEqual(payloadData["SomeInfo"] as? String, "Info") } + + func testSerializedSRBreadcrumbLevelIsString() throws { + let sut = SentrySRDefaultBreadcrumbConverter() + let breadcrumb = Breadcrumb() + breadcrumb.level = .error + + let result = try XCTUnwrap(sut.convert(from: breadcrumb) as? SentryRRWebBreadcrumbEvent) + let crumbData = try XCTUnwrap(result.data) + let payload = try XCTUnwrap(crumbData["payload"] as? [String: Any]) + + XCTAssertEqual(payload["level"] as! String, "error") + } }