Skip to content

Commit

Permalink
fix(replay): SR Breadcrumbs include level name as a string (#4141)
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich authored Jul 9, 2024
1 parent a0601b7 commit d26797f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions Sources/Sentry/SentryLevelHelper.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "SentryLevelHelper.h"
#import "SentryBreadcrumb+Private.h"
#import "SentryLevelMapper.h"

@implementation SentryLevelHelper

Expand All @@ -8,4 +9,9 @@ + (NSUInteger)breadcrumbLevel:(SentryBreadcrumb *)breadcrumb
return breadcrumb.level;
}

+ (NSString *_Nonnull)getNameFor:(NSUInteger)level
{
return nameForSentryLevel(level);
}

@end
2 changes: 2 additions & 0 deletions Sources/Sentry/include/SentryLevelHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ NS_ASSUME_NONNULL_BEGIN

+ (NSUInteger)breadcrumbLevel:(SentryBreadcrumb *)breadcrumb;

+ (NSString *_Nonnull)getNameFor:(NSUInteger)level;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit d26797f

Please sign in to comment.