Skip to content

Ensure Breadcrumbs and SentryEvents are always serialisable #1582

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

Closed
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Ensure Breadcrumbs and SentryEvents are always serialisable ([#1582](https://github.com/getsentry/sentry-dart/pull/1582))

## 7.9.0

### Features
Expand Down
8 changes: 4 additions & 4 deletions logging/lib/src/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ extension LogRecordX on LogRecord {
level: level.toSentryLevel(),
message: message,
data: <String, Object>{
if (object != null) 'LogRecord.object': object!,
if (error != null) 'LogRecord.error': error!,
if (stackTrace != null) 'LogRecord.stackTrace': stackTrace!,
if (object != null) 'LogRecord.object': object!.toString(),
if (error != null) 'LogRecord.error': error!.toString(),
if (stackTrace != null) 'LogRecord.stackTrace': stackTrace!.toString(),
'LogRecord.loggerName': loggerName,
'LogRecord.sequenceNumber': sequenceNumber,
},
Expand All @@ -30,7 +30,7 @@ extension LogRecordX on LogRecord {
throwable: error,
// ignore: deprecated_member_use
extra: <String, Object>{
if (object != null) 'LogRecord.object': object!,
if (object != null) 'LogRecord.object': object!.toString(),
'LogRecord.sequenceNumber': sequenceNumber,
},
);
Expand Down
41 changes: 41 additions & 0 deletions logging/test/extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import 'package:logging/logging.dart';
import 'package:sentry_logging/src/extension.dart';
import 'package:test/test.dart';

class _TestObject {}

class _TestErrorObject {}

void main() {
test('breadcrumb time is always utc', () {
final log = LogRecord(Level.CONFIG, 'foo bar', 'test logger');
Expand All @@ -14,4 +18,41 @@ void main() {

expect(log.toEvent().timestamp?.isUtc, true);
});

test('user defined objects are converted to string', () {
// Every value in the data and extra map must be convertible to by the
// StandardMessageCodec. We convert all user supplied types and the
// StackTrace to a string to make this property hold.

final object = _TestObject();
final error = _TestErrorObject();
final stackTrace = StackTrace.current;

final log = LogRecord(
Level.CONFIG,
'foo bar',
'test logger',
error,
stackTrace,
null,
object,
);

final breadcrumb = log.toBreadcrumb();
expect(
breadcrumb.data,
containsPair('LogRecord.object', object.toString()),
);
expect(
log.toBreadcrumb().data,
containsPair('LogRecord.stackTrace', stackTrace.toString()),
);

final event = log.toEvent();
expect(
// ignore: deprecated_member_use
event.extra,
containsPair('LogRecord.object', object.toString()),
);
});
}