Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
change to Spotlight class
  • Loading branch information
buenaflor committed Dec 18, 2023
commit 6784f06aca40e21c214d1e8778deb3c2d468ce50
2 changes: 2 additions & 0 deletions dart/lib/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ export 'src/utils/http_header_utils.dart';
export 'src/sentry_trace_origins.dart';
// ignore: invalid_export_of_internal_element
export 'src/utils.dart';
// spotlight debugging
export 'src/spotlight.dart';
2 changes: 1 addition & 1 deletion dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SentryClient {
final rateLimiter = RateLimiter(options);
options.transport = HttpTransport(options, rateLimiter);
}
if (options.enableSpotlight) {
if (options.spotlight.enabled) {
options.transport = SpotlightHttpTransport(options, options.transport);
}
return SentryClient._(options);
Expand Down
16 changes: 6 additions & 10 deletions dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:developer';
import 'dart:io';

import 'package:meta/meta.dart';
import 'package:http/http.dart';
Expand Down Expand Up @@ -375,15 +374,12 @@ class SentryOptions {
/// Settings this to `false` will set the `level` to [SentryLevel.error].
bool markAutomaticallyCollectedErrorsAsFatal = true;

/// Whether to enable Spotlight for local development.
bool enableSpotlight = false;

/// The Spotlight URL.
/// Defaults to http://10.0.2.2:8969/stream due to Emulator on Android.
/// Otherwise defaults to http://localhost:8969/stream.
String spotlightUrl = PlatformChecker().platform.isAndroid
? 'http://10.0.2.2:8969/stream'
: 'http://localhost:8969/stream';
/// The Spotlight configuration.
/// Disabled by default.
/// ```dart
/// spotlight = Spotlight(enabled: true)
/// ```
Spotlight spotlight = Spotlight(enabled: false);

SentryOptions({this.dsn, PlatformChecker? checker}) {
if (checker != null) {
Expand Down
21 changes: 21 additions & 0 deletions dart/lib/src/spotlight.dart
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');
}
2 changes: 1 addition & 1 deletion dart/lib/src/transport/spotlight_http_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SpotlightHttpTransport extends Transport {

SpotlightHttpTransport._(this._options, this._transport)
: _requestHandler = HttpTransportRequestHandler(
_options, Uri.parse(_options.spotlightUrl));
_options, Uri.parse(_options.spotlight.url));

@override
Future<SentryId?> send(SentryEnvelope envelope) async {
Expand Down
2 changes: 1 addition & 1 deletion dart/test/transport/spotlight_http_transport_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {

final httpMock = MockClient((http.Request request) async {
body = request.bodyBytes;
if (request.url.toString() == fixture.options.spotlightUrl) {
if (request.url.toString() == fixture.options.spotlight.url) {
return http.Response('{}', 500);
}
return http.Response('{}', 200);
Expand Down