-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SentryRequest context for HttpException and SocketException (#1118)
- Loading branch information
Showing
19 changed files
with
390 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
dart/lib/src/event_processor/enricher/enricher_event_processor.dart
This file contains 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,9 @@ | ||
import '../../event_processor.dart'; | ||
import '../../sentry_options.dart'; | ||
import 'io_enricher_event_processor.dart' | ||
if (dart.library.html) 'web_enricher_event_processor.dart'; | ||
|
||
abstract class EnricherEventProcessor implements EventProcessor { | ||
factory EnricherEventProcessor(SentryOptions options) => | ||
enricherEventProcessor(options); | ||
} |
This file contains 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
10 changes: 5 additions & 5 deletions
10
...nricher/web_enricher_event_processor.dart → ...nricher/web_enricher_event_processor.dart
This file contains 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
9 changes: 9 additions & 0 deletions
9
dart/lib/src/event_processor/exception/exception_event_processor.dart
This file contains 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,9 @@ | ||
import '../../event_processor.dart'; | ||
import '../../sentry_options.dart'; | ||
import 'io_exception_event_processor.dart' | ||
if (dart.library.html) 'web_exception_event_processor.dart'; | ||
|
||
abstract class ExceptionEventProcessor implements EventProcessor { | ||
factory ExceptionEventProcessor(SentryOptions options) => | ||
exceptionEventProcessor(options); | ||
} |
116 changes: 116 additions & 0 deletions
116
dart/lib/src/event_processor/exception/io_exception_event_processor.dart
This file contains 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,116 @@ | ||
import 'dart:io'; | ||
|
||
import '../../protocol.dart'; | ||
import '../../sentry_options.dart'; | ||
import 'exception_event_processor.dart'; | ||
|
||
ExceptionEventProcessor exceptionEventProcessor(SentryOptions options) => | ||
IoExceptionEventProcessor(options); | ||
|
||
class IoExceptionEventProcessor implements ExceptionEventProcessor { | ||
IoExceptionEventProcessor(this._options); | ||
|
||
final SentryOptions _options; | ||
|
||
@override | ||
SentryEvent apply(SentryEvent event, {dynamic hint}) { | ||
final throwable = event.throwable; | ||
if (throwable is HttpException) { | ||
return _applyHttpException(throwable, event); | ||
} | ||
if (throwable is SocketException) { | ||
return _applySocketException(throwable, event); | ||
} | ||
if (throwable is FileSystemException) { | ||
return _applyFileSystemException(throwable, event); | ||
} | ||
|
||
return event; | ||
} | ||
|
||
// https://api.dart.dev/stable/dart-io/HttpException-class.html | ||
SentryEvent _applyHttpException(HttpException exception, SentryEvent event) { | ||
final uri = exception.uri; | ||
if (uri == null) { | ||
return event; | ||
} | ||
return event.copyWith( | ||
request: event.request ?? SentryRequest.fromUri(uri: uri), | ||
); | ||
} | ||
|
||
// https://api.dart.dev/stable/dart-io/SocketException-class.html | ||
SentryEvent _applySocketException( | ||
SocketException exception, | ||
SentryEvent event, | ||
) { | ||
final address = exception.address; | ||
final osError = exception.osError; | ||
if (address == null) { | ||
return event.copyWith( | ||
exceptions: [ | ||
// OSError is the underlying error | ||
// https://api.dart.dev/stable/dart-io/SocketException/osError.html | ||
// https://api.dart.dev/stable/dart-io/OSError-class.html | ||
if (osError != null) _sentryExceptionfromOsError(osError), | ||
...?event.exceptions, | ||
], | ||
); | ||
} | ||
SentryRequest? request; | ||
try { | ||
var uri = Uri.parse(address.host); | ||
request = SentryRequest.fromUri(uri: uri); | ||
} catch (exception, stackTrace) { | ||
_options.logger( | ||
SentryLevel.error, | ||
'Could not parse ${address.host} to Uri', | ||
exception: exception, | ||
stackTrace: stackTrace, | ||
); | ||
} | ||
|
||
return event.copyWith( | ||
request: event.request ?? request, | ||
exceptions: [ | ||
// OSError is the underlying error | ||
// https://api.dart.dev/stable/dart-io/SocketException/osError.html | ||
// https://api.dart.dev/stable/dart-io/OSError-class.html | ||
if (osError != null) _sentryExceptionfromOsError(osError), | ||
...?event.exceptions, | ||
], | ||
); | ||
} | ||
|
||
// https://api.dart.dev/stable/dart-io/FileSystemException-class.html | ||
SentryEvent _applyFileSystemException( | ||
FileSystemException exception, | ||
SentryEvent event, | ||
) { | ||
final osError = exception.osError; | ||
return event.copyWith( | ||
exceptions: [ | ||
// OSError is the underlying error | ||
// https://api.dart.dev/stable/dart-io/FileSystemException/osError.html | ||
// https://api.dart.dev/stable/dart-io/OSError-class.html | ||
if (osError != null) _sentryExceptionfromOsError(osError), | ||
...?event.exceptions, | ||
], | ||
); | ||
} | ||
} | ||
|
||
SentryException _sentryExceptionfromOsError(OSError osError) { | ||
return SentryException( | ||
type: osError.runtimeType.toString(), | ||
value: osError.toString(), | ||
// osError.errorCode is likely a posix signal | ||
// https://develop.sentry.dev/sdk/event-payloads/types/#mechanismmeta | ||
mechanism: Mechanism( | ||
type: 'OSError', | ||
meta: { | ||
'errno': {'number': osError.errorCode}, | ||
}, | ||
), | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
dart/lib/src/event_processor/exception/web_exception_event_processor.dart
This file contains 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,11 @@ | ||
import '../../protocol.dart'; | ||
import '../../sentry_options.dart'; | ||
import 'exception_event_processor.dart'; | ||
|
||
ExceptionEventProcessor exceptionEventProcessor(SentryOptions _) => | ||
WebExcptionEventProcessor(); | ||
|
||
class WebExcptionEventProcessor implements ExceptionEventProcessor { | ||
@override | ||
SentryEvent apply(SentryEvent event, {dynamic hint}) => event; | ||
} |
This file contains 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 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 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
6 changes: 3 additions & 3 deletions
6
dart/test/enricher/io_enricher_test.dart → ..._processor/enricher/io_enricher_test.dart
This file contains 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 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.