Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(replay): SR Breadcrumbs include level name as a string #4141

Merged
merged 6 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
}
Loading