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 2 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
5 changes: 3 additions & 2 deletions Sources/Sentry/SentryLevelHelper.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#import "SentryLevelHelper.h"
#import "SentryBreadcrumb+Private.h"
#import "SentryLevelMapper.h"

@implementation SentryLevelHelper

+ (NSUInteger)breadcrumbLevel:(SentryBreadcrumb *)breadcrumb
+ (NSString *_Nonnull)breadcrumbLevel:(SentryBreadcrumb *)breadcrumb
{
return breadcrumb.level;
return nameForSentryLevel(breadcrumb.level);
}

@end
3 changes: 2 additions & 1 deletion Sources/Sentry/SentrySessionReplayIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# import "SentryFileManager.h"
# import "SentryGlobalEventProcessor.h"
# import "SentryHub+Private.h"
# import "SentryLevelMapper.h"
# import "SentryNSNotificationCenterWrapper.h"
# import "SentryOptions.h"
# import "SentryRandom.h"
Expand Down Expand Up @@ -254,7 +255,7 @@
return [[SentryRRWebBreadcrumbEvent alloc] initWithTimestamp:timestamp
category:category
message:message
level:level
level:nameForSentryLevel(level)

Check warning on line 258 in Sources/Sentry/SentrySessionReplayIntegration.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentrySessionReplayIntegration.m#L258

Added line #L258 was not covered by tests
data:data];
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/include/SentryLevelHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface SentryLevelHelper : NSObject

+ (NSUInteger)breadcrumbLevel:(SentryBreadcrumb *)breadcrumb;
+ (NSString *_Nonnull)breadcrumbLevel:(SentryBreadcrumb *)breadcrumb;
brustolin marked this conversation as resolved.
Show resolved Hide resolved

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
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 ]
init(timestamp: Date, category: String, message: String? = nil, level: String = "none", data: [String: Any]? = nil) {

var payload: [String: Any] = ["type": "default", "category": category, "level": level, "timestamp": timestamp.timeIntervalSince1970 ]

if let message = message {
payload["message"] = message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class SentryBreadcrumbReplayConverter: NSObject {
return SentryRRWebSpanEvent(timestamp: timestamp, endTimestamp: timestamp, operation: "resource.http", description: description, data: data)
}

private func getLevel(breadcrumb: Breadcrumb) -> SentryLevel {
return SentryLevel(rawValue: SentryLevelHelper.breadcrumbLevel(breadcrumb)) ?? .none

private func getLevel(breadcrumb: Breadcrumb) -> String {
return SentryLevelHelper.breadcrumbLevel(breadcrumb)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SentrySRDefaultBreadcrumbConverter: NSObject, SentryReplayBreadcrumbConver
return SentryRRWebSpanEvent(timestamp: startTimestamp, endTimestamp: timestamp, operation: "resource.http", description: description, data: data)
}

private func getLevel(breadcrumb: Breadcrumb) -> SentryLevel {
return SentryLevel(rawValue: SentryLevelHelper.breadcrumbLevel(breadcrumb)) ?? .none
private func getLevel(breadcrumb: Breadcrumb) -> String {
return SentryLevelHelper.breadcrumbLevel(breadcrumb)
}
}
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