-
-
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.
* Implement spotlight support (screenshots are currently disabled and removed from the envelope)
- Loading branch information
Showing
13 changed files
with
322 additions
and
118 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 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
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,21 @@ | ||
import 'platform_checker.dart'; | ||
|
||
/// Spotlight configuration class. | ||
class Spotlight { | ||
/// Whether to enable Spotlight for local development. | ||
bool enabled; | ||
|
||
/// The Spotlight Sidecar URL. | ||
/// Defaults to http://10.0.2.2:8969/stream due to Emulator on Android. | ||
/// Otherwise defaults to http://localhost:8969/stream. | ||
String url; | ||
|
||
Spotlight({required this.enabled, String? url}) | ||
: url = url ?? _defaultSpotlightUrl(); | ||
} | ||
|
||
String _defaultSpotlightUrl() { | ||
return (PlatformChecker().platform.isAndroid | ||
? 'http://10.0.2.2:8969/stream' | ||
: 'http://localhost:8969/stream'); | ||
} |
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
98 changes: 98 additions & 0 deletions
98
dart/lib/src/transport/http_transport_request_handler.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,98 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:http/http.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
import 'noop_encode.dart' if (dart.library.io) 'encode.dart'; | ||
import '../protocol.dart'; | ||
import '../sentry_options.dart'; | ||
import '../sentry_envelope.dart'; | ||
|
||
@internal | ||
class HttpTransportRequestHandler { | ||
final SentryOptions _options; | ||
final Dsn _dsn; | ||
final Map<String, String> _headers; | ||
final Uri _requestUri; | ||
late _CredentialBuilder _credentialBuilder; | ||
|
||
HttpTransportRequestHandler(this._options, this._requestUri) | ||
: _dsn = Dsn.parse(_options.dsn!), | ||
_headers = _buildHeaders( | ||
_options.platformChecker.isWeb, | ||
_options.sentryClientName, | ||
) { | ||
_credentialBuilder = _CredentialBuilder( | ||
_dsn, | ||
_options.sentryClientName, | ||
); | ||
} | ||
|
||
Future<StreamedRequest> createRequest(SentryEnvelope envelope) async { | ||
final streamedRequest = StreamedRequest('POST', _requestUri); | ||
|
||
if (_options.compressPayload) { | ||
final compressionSink = compressInSink(streamedRequest.sink, _headers); | ||
envelope | ||
.envelopeStream(_options) | ||
.listen(compressionSink.add) | ||
.onDone(compressionSink.close); | ||
} else { | ||
envelope | ||
.envelopeStream(_options) | ||
.listen(streamedRequest.sink.add) | ||
.onDone(streamedRequest.sink.close); | ||
} | ||
|
||
streamedRequest.headers.addAll(_credentialBuilder.configure(_headers)); | ||
return streamedRequest; | ||
} | ||
} | ||
|
||
Map<String, String> _buildHeaders(bool isWeb, String sdkIdentifier) { | ||
final headers = {'Content-Type': 'application/x-sentry-envelope'}; | ||
// NOTE(lejard_h) overriding user agent on VM and Flutter not sure why | ||
// for web it use browser user agent | ||
if (!isWeb) { | ||
headers['User-Agent'] = sdkIdentifier; | ||
} | ||
return headers; | ||
} | ||
|
||
class _CredentialBuilder { | ||
final String _authHeader; | ||
|
||
_CredentialBuilder._(String authHeader) : _authHeader = authHeader; | ||
|
||
factory _CredentialBuilder(Dsn dsn, String sdkIdentifier) { | ||
final authHeader = _buildAuthHeader( | ||
publicKey: dsn.publicKey, | ||
secretKey: dsn.secretKey, | ||
sdkIdentifier: sdkIdentifier, | ||
); | ||
|
||
return _CredentialBuilder._(authHeader); | ||
} | ||
|
||
static String _buildAuthHeader({ | ||
required String publicKey, | ||
String? secretKey, | ||
required String sdkIdentifier, | ||
}) { | ||
var header = 'Sentry sentry_version=7, sentry_client=$sdkIdentifier, ' | ||
'sentry_key=$publicKey'; | ||
|
||
if (secretKey != null) { | ||
header += ', sentry_secret=$secretKey'; | ||
} | ||
|
||
return header; | ||
} | ||
|
||
Map<String, String> configure(Map<String, String> headers) { | ||
return headers | ||
..addAll( | ||
<String, String>{'X-Sentry-Auth': _authHeader}, | ||
); | ||
} | ||
} |
Oops, something went wrong.