Skip to content

Commit 313d407

Browse files
committed
WIP
1 parent 9dae6ab commit 313d407

File tree

7 files changed

+43
-40
lines changed

7 files changed

+43
-40
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
* Feat: Add support for attachments (#505)
4+
35
# 6.0.0-beta.1
46

57
* Feat: Browser detection (#502)
@@ -8,7 +10,6 @@
810
* Feat: Add DeduplicationEventProcessor (#498)
911
* Feat: Capture failed requests as event (#473)
1012
* Feat: `beforeSend` callback accepts async code (#494)
11-
* Feat: Add support for attachments (#505)
1213

1314
## Breaking Changes:
1415

dart/lib/src/scope.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class Scope {
120120
_breadcrumbs.add(breadcrumb);
121121
}
122122

123-
void addAttachment(SentryAttachment attachment) async {
123+
void addAttachment(SentryAttachment attachment) {
124124
_attachements.add(attachment);
125125
}
126126

@@ -299,7 +299,7 @@ class Scope {
299299
});
300300

301301
for (final attachment in _attachements) {
302-
clone._attachements.add(attachment);
302+
clone.addAttachment(attachment);
303303
}
304304

305305
return clone;

dart/lib/src/sentry_attachment/sentry_attachment.dart

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,33 @@ typedef ContentLoader = FutureOr<Uint8List> Function();
88

99
/// Arbitrary content which gets attached to an event.
1010
class SentryAttachment {
11+
/// Standard attachment without special meaning.
12+
static const String typeAttachmentDefault = 'event.attachment';
13+
14+
/// Minidump file that creates an error event and is symbolicated.
15+
/// The file should start with the `MDMP` magic bytes.
16+
static const String typeMinidump = 'event.minidump';
17+
18+
/// Apple crash report file that creates an error event and is symbolicated.
19+
static const String typeAppleCrashReport = 'event.applecrashreport';
20+
21+
/// XML file containing UE4 crash meta data.
22+
/// During event ingestion, event contexts and extra fields are extracted from
23+
/// this file.
24+
static const String typeUnrealContext = 'unreal.context';
25+
26+
/// Plain-text log file obtained from UE4 crashes.
27+
/// During event ingestion, the last logs are extracted into event
28+
/// breadcrumbs.
29+
static const String typeUnrealLogs = 'unreal.logs';
30+
1131
SentryAttachment.fromLoader({
1232
required ContentLoader loader,
1333
required this.filename,
1434
String? attachmentType,
1535
this.contentType,
1636
}) : _loader = loader,
17-
attachmentType = attachmentType ?? AttachmentType.attachment;
37+
attachmentType = attachmentType ?? typeAttachmentDefault;
1838

1939
/// Creates an [SentryAttachment] from a [Uint8List]
2040
SentryAttachment.fromUint8List(
@@ -72,26 +92,3 @@ class SentryAttachment {
7292
/// Inferred by Sentry if it's not given.
7393
final String? contentType;
7494
}
75-
76-
/// Attachment type.
77-
class AttachmentType {
78-
/// Standard attachment without special meaning.
79-
static const String attachment = 'event.attachment';
80-
81-
/// Minidump file that creates an error event and is symbolicated.
82-
/// The file should start with the `MDMP` magic bytes.
83-
static const String minidump = 'event.minidump';
84-
85-
/// Apple crash report file that creates an error event and is symbolicated.
86-
static const String appleCrashReport = 'event.applecrashreport';
87-
88-
/// XML file containing UE4 crash meta data.
89-
/// During event ingestion, event contexts and extra fields are extracted from
90-
/// this file.
91-
static const String unrealContext = 'unreal.context';
92-
93-
/// Plain-text log file obtained from UE4 crashes.
94-
/// During event ingestion, the last logs are extracted into event
95-
/// breadcrumbs.
96-
static const String unrealLogs = 'unreal.logs';
97-
}

dart/lib/src/sentry_envelope.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ class SentryEnvelope {
3737
yield utf8.encode(jsonEncode(header.toJson()));
3838
final newLineData = utf8.encode('\n');
3939
for (final item in items) {
40-
yield newLineData;
41-
yield await item.envelopeItemStream();
40+
final itemStream = await item.envelopeItemStream();
41+
if (itemStream.isNotEmpty) {
42+
yield newLineData;
43+
yield itemStream;
44+
}
4245
}
4346
}
4447
}

dart/test/sentry_attachment_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ void main() {
1313
loader: () => Uint8List.fromList([0, 0, 0, 0]),
1414
filename: 'test.txt',
1515
);
16-
expect(attachment.attachmentType, AttachmentType.attachment);
16+
expect(attachment.attachmentType, SentryAttachment.typeAttachmentDefault);
1717
expect(attachment.contentType, isNull);
1818
expect(attachment.filename, 'test.txt');
1919
await expectLater(await attachment.bytes, [0, 0, 0, 0]);
2020
});
2121

2222
test('fromIntList', () async {
2323
final attachment = SentryAttachment.fromIntList([0, 0, 0, 0], 'test.txt');
24-
expect(attachment.attachmentType, AttachmentType.attachment);
24+
expect(attachment.attachmentType, SentryAttachment.typeAttachmentDefault);
2525
expect(attachment.contentType, isNull);
2626
expect(attachment.filename, 'test.txt');
2727
await expectLater(await attachment.bytes, [0, 0, 0, 0]);
@@ -32,7 +32,7 @@ void main() {
3232
Uint8List.fromList([0, 0, 0, 0]),
3333
'test.txt',
3434
);
35-
expect(attachment.attachmentType, AttachmentType.attachment);
35+
expect(attachment.attachmentType, SentryAttachment.typeAttachmentDefault);
3636
expect(attachment.contentType, isNull);
3737
expect(attachment.filename, 'test.txt');
3838
await expectLater(await attachment.bytes, [0, 0, 0, 0]);
@@ -43,7 +43,7 @@ void main() {
4343
ByteData.sublistView(Uint8List.fromList([0, 0, 0, 0])),
4444
'test.txt',
4545
);
46-
expect(attachment.attachmentType, AttachmentType.attachment);
46+
expect(attachment.attachmentType, SentryAttachment.typeAttachmentDefault);
4747
expect(attachment.contentType, isNull);
4848
expect(attachment.filename, 'test.txt');
4949
await expectLater(await attachment.bytes, [0, 0, 0, 0]);
@@ -66,7 +66,7 @@ void main() {
6666
final attachmentEnvelope = transport.envelopes.first.items[1];
6767
expect(
6868
attachmentEnvelope.header.attachmentType,
69-
AttachmentType.attachment,
69+
SentryAttachment.typeAttachmentDefault,
7070
);
7171
expect(
7272
attachmentEnvelope.header.contentType,

dart/test/sentry_attachment_test_io.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void main() {
1111
final file = File('test_resources/testfile.txt');
1212

1313
final attachment = IoSentryAttachment.fromFile(file);
14-
expect(attachment.attachmentType, AttachmentType.attachment);
14+
expect(attachment.attachmentType, SentryAttachment.typeAttachmentDefault);
1515
expect(attachment.contentType, isNull);
1616
expect(attachment.filename, 'testfile.txt');
1717
await expectLater(
@@ -21,7 +21,7 @@ void main() {
2121
test('fromPath', () async {
2222
final attachment =
2323
IoSentryAttachment.fromPath('test_resources/testfile.txt');
24-
expect(attachment.attachmentType, AttachmentType.attachment);
24+
expect(attachment.attachmentType, SentryAttachment.typeAttachmentDefault);
2525
expect(attachment.contentType, isNull);
2626
expect(attachment.filename, 'testfile.txt');
2727
await expectLater(

dart/test/sentry_envelope_vm_test.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ void main() {
5353
final attachment =
5454
IoSentryAttachment.fromPath('this_path_does_not_exist.txt');
5555

56-
final envelope = SentryEnvelope.fromEvent(event, sdkVersion,
57-
attachments: [attachment]);
56+
final envelope = SentryEnvelope.fromEvent(
57+
event,
58+
sdkVersion,
59+
attachments: [attachment],
60+
);
5861

5962
final data =
6063
(await envelope.envelopeStream().toList()).reduce((a, b) => a + b);
@@ -292,6 +295,5 @@ final envelopeBinaryData = [
292295
48,
293296
90,
294297
34,
295-
125,
296-
10
298+
125
297299
];

0 commit comments

Comments
 (0)