-
-
Notifications
You must be signed in to change notification settings - Fork 277
Feat: Attachment Support #505
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3d3d635
Attachment support
ueman 9ecad73
fix pr id
ueman 901f3b4
wip
ueman f6db8f1
More examples
ueman 6468814
Update dart/lib/src/sentry_envelope_item_header.dart
ueman 5e0cde0
WIP
ueman 6cca701
WIP
ueman 5445b83
more tests
ueman 32ee66b
use list unmodifiable
ueman 664617e
transport can return null
ueman 75a7b60
fix test
ueman 887adda
wip
ueman 0e41503
test
ueman 661116b
fix file system transport
ueman 3a12ed7
skip attachment if it throws
ueman 9dae6ab
fix sentry id
ueman 313d407
WIP
ueman cd6aae6
rename test file to be identified as test
ueman 20af837
fix
ueman 5727ef1
test fixture
ueman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export 'sentry.dart'; | ||
| export 'src/sentry_attachment/io_sentry_attachment.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,40 @@ | ||
| import 'package:meta/meta.dart'; | ||
| import 'package:uuid/uuid.dart'; | ||
|
|
||
| /// Hexadecimal string representing a uuid4 value | ||
| /// Hexadecimal string representing a uuid4 value. | ||
| /// The length is exactly 32 | ||
| /// characters. Dashes are not allowed. Has to be lowercase. | ||
| @immutable | ||
| class SentryId { | ||
| static final SentryId _emptyId = | ||
| SentryId.fromId('00000000-0000-0000-0000-000000000000'); | ||
|
|
||
| /// The ID Sentry.io assigned to the submitted event for future reference. | ||
| final String _id; | ||
|
|
||
| static final Uuid _uuidGenerator = Uuid(); | ||
|
|
||
| SentryId._internal({String? id}) : _id = id ?? _uuidGenerator.v4(); | ||
| SentryId._internal({String? id}) | ||
| : _id = | ||
| id?.replaceAll('-', '') ?? _uuidGenerator.v4().replaceAll('-', ''); | ||
|
|
||
| /// Generates a new SentryId | ||
| factory SentryId.newId() => SentryId._internal(); | ||
| SentryId.newId() : this._internal(); | ||
|
|
||
| /// Generates a SentryId with the given UUID | ||
| factory SentryId.fromId(String id) => SentryId._internal(id: id); | ||
| SentryId.fromId(String id) : this._internal(id: id); | ||
|
|
||
| /// SentryId with an empty UUID | ||
| factory SentryId.empty() => _emptyId; | ||
| const SentryId.empty() : _id = '00000000000000000000000000000000'; | ||
|
|
||
| @override | ||
| String toString() => _id; | ||
|
|
||
| @override | ||
| int get hashCode => _id.hashCode; | ||
|
|
||
| @override | ||
| String toString() => _id.replaceAll('-', ''); | ||
| bool operator ==(o) { | ||
| if (o is SentryId) { | ||
| return o._id == _id; | ||
| } | ||
| return false; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import 'dart:io'; | ||
|
|
||
| import 'sentry_attachment.dart'; | ||
|
|
||
| class IoSentryAttachment extends SentryAttachment { | ||
| /// Creates an attachment from a given path. | ||
| /// Only available on `dart:io` platforms. | ||
| /// Not available on web. | ||
| IoSentryAttachment.fromPath( | ||
| String path, { | ||
| String? filename, | ||
| String? attachmentType, | ||
| String? contentType, | ||
| }) : this.fromFile( | ||
| File(path), | ||
| attachmentType: attachmentType, | ||
| contentType: contentType, | ||
| filename: filename, | ||
| ); | ||
|
|
||
| /// Creates an attachment from a given [File]. | ||
| /// Only available on `dart:io` platforms. | ||
| /// Not available on web. | ||
| IoSentryAttachment.fromFile( | ||
| File file, { | ||
| String? filename, | ||
| String? attachmentType, | ||
| String? contentType, | ||
| }) : super.fromLoader( | ||
| loader: () => file.readAsBytes(), | ||
| filename: filename ?? file.uri.pathSegments.last, | ||
| attachmentType: attachmentType, | ||
| contentType: contentType, | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import 'dart:async'; | ||
| import 'dart:typed_data'; | ||
|
|
||
| // https://develop.sentry.dev/sdk/features/#attachments | ||
| // https://develop.sentry.dev/sdk/envelopes/#attachment | ||
|
|
||
| typedef ContentLoader = FutureOr<Uint8List> Function(); | ||
marandaneto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Arbitrary content which gets attached to an event. | ||
| class SentryAttachment { | ||
| /// Standard attachment without special meaning. | ||
| static const String typeAttachmentDefault = 'event.attachment'; | ||
|
|
||
| /// Minidump file that creates an error event and is symbolicated. | ||
| /// The file should start with the `MDMP` magic bytes. | ||
| static const String typeMinidump = 'event.minidump'; | ||
|
|
||
| /// Apple crash report file that creates an error event and is symbolicated. | ||
| static const String typeAppleCrashReport = 'event.applecrashreport'; | ||
|
|
||
| /// XML file containing UE4 crash meta data. | ||
| /// During event ingestion, event contexts and extra fields are extracted from | ||
| /// this file. | ||
| static const String typeUnrealContext = 'unreal.context'; | ||
|
|
||
| /// Plain-text log file obtained from UE4 crashes. | ||
| /// During event ingestion, the last logs are extracted into event | ||
| /// breadcrumbs. | ||
| static const String typeUnrealLogs = 'unreal.logs'; | ||
|
|
||
| SentryAttachment.fromLoader({ | ||
| required ContentLoader loader, | ||
| required this.filename, | ||
| String? attachmentType, | ||
| this.contentType, | ||
| }) : _loader = loader, | ||
| attachmentType = attachmentType ?? typeAttachmentDefault; | ||
|
|
||
| /// Creates an [SentryAttachment] from a [Uint8List] | ||
| SentryAttachment.fromUint8List( | ||
| Uint8List bytes, | ||
| String fileName, { | ||
| String? contentType, | ||
| String? attachmentType, | ||
| }) : this.fromLoader( | ||
| attachmentType: attachmentType, | ||
| loader: () => bytes, | ||
| filename: fileName, | ||
| contentType: contentType, | ||
| ); | ||
|
|
||
| /// Creates an [SentryAttachment] from a [List<int>] | ||
| SentryAttachment.fromIntList( | ||
| List<int> bytes, | ||
| String fileName, { | ||
| String? contentType, | ||
| String? attachmentType, | ||
| }) : this.fromLoader( | ||
| attachmentType: attachmentType, | ||
| loader: () => Uint8List.fromList(bytes), | ||
| filename: fileName, | ||
| contentType: contentType, | ||
| ); | ||
|
|
||
| /// Creates an [SentryAttachment] from [ByteData] | ||
| SentryAttachment.fromByteData( | ||
| ByteData bytes, | ||
| String fileName, { | ||
| String? contentType, | ||
| String? attachmentType, | ||
| }) : this.fromLoader( | ||
| attachmentType: attachmentType, | ||
| loader: () => bytes.buffer.asUint8List(), | ||
| filename: fileName, | ||
| contentType: contentType, | ||
| ); | ||
|
|
||
| /// Attachment type. | ||
| /// Should be one of types given in [AttachmentType]. | ||
| final String attachmentType; | ||
|
|
||
| /// Attachment content. | ||
| /// Is loaded while sending this attachment. | ||
| FutureOr<Uint8List> get bytes => _loader(); | ||
|
|
||
| final ContentLoader _loader; | ||
|
|
||
| /// Attachment file name. | ||
| final String filename; | ||
|
|
||
| /// Attachment content type. | ||
| /// Inferred by Sentry if it's not given. | ||
| final String? contentType; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.