Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
buenaflor committed Sep 12, 2024
1 parent 3cc09ec commit c107ffb
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 17 deletions.
7 changes: 6 additions & 1 deletion dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ class SentryClient {
final rateLimiter = RateLimiter(options);
options.transport = HttpTransport(options, rateLimiter);
}
if (options.spotlight.enabled) {
// TODO: Web might change soon to use the JS SDK so we can remove it here later on
final enableSpotlight = (options.spotlight.enabled &&
(options.platformChecker.isWeb ||
options.platformChecker.platform.isLinux ||
options.platformChecker.platform.isWindows));
if (enableSpotlight) {
options.transport = SpotlightHttpTransport(options, options.transport);
}
return SentryClient._(options);
Expand Down
11 changes: 2 additions & 9 deletions dart/lib/src/spotlight.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ class Spotlight {
/// 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;
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');
Spotlight({required this.enabled, this.url});
}
10 changes: 8 additions & 2 deletions dart/lib/src/transport/spotlight_http_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import '../http_client/client_provider.dart'
if (dart.library.io) '../http_client/io_client_provider.dart';

/// Spotlight HTTP transport decorator that sends Sentry envelopes to both Sentry and Spotlight.
/// This will be used on platforms that do not have native SDK support.
/// Platforms with native SDK support will configure spotlight directly in the native SDK options.
class SpotlightHttpTransport extends Transport {
final SentryOptions _options;
final Transport _transport;
Expand All @@ -21,8 +23,8 @@ class SpotlightHttpTransport extends Transport {
}

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

@override
Future<SentryId?> send(SentryEnvelope envelope) async {
Expand All @@ -48,3 +50,7 @@ class SpotlightHttpTransport extends Transport {
target: 'Spotlight');
}
}

String _defaultSpotlightUrl() {
return 'http://localhost:8969/stream';
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ class SentryFlutter(
data.getIfNotNull<String>("proguardUuid") {
options.proguardUuid = it
}
data.getIfNotNull<Boolean>("enableSpotlight") {
options.isEnableSpotlight = it
}
data.getIfNotNull<String>("spotlightUrl") {
options.spotlightConnectionUrl = it
}

val nativeCrashHandling = (data["enableNativeCrashHandling"] as? Boolean) ?: true
// nativeCrashHandling has priority over anrEnabled
Expand Down
8 changes: 8 additions & 0 deletions flutter/example/android/app/local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Sep 10 17:20:30 CEST 2024
sdk.dir=/Users/giancarlobuenaflor/Library/Android/sdk
3 changes: 2 additions & 1 deletion flutter/example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
android:allowBackup="false"
android:label="sentry_flutter_example"
android:icon="@mipmap/ic_launcher"
android:extractNativeLibs="true">
android:extractNativeLibs="true"
android:networkSecurityConfig="@xml/network">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
Expand Down
8 changes: 8 additions & 0 deletions flutter/example/android/app/src/main/res/xml/network.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<!-- Allow cleartext traffic from the emulator to the host machine -->
<!-- See https://developer.android.com/studio/run/emulator-networking for more details -->
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>
</network-security-config>
2 changes: 1 addition & 1 deletion flutter/example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit
import Flutter
import Sentry

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
private let _channel = "example.flutter.sentry.io"

Expand Down
4 changes: 2 additions & 2 deletions flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ Future<void> setupSentry(
options.maxResponseBodySize = MaxResponseBodySize.always;
options.navigatorKey = navigatorKey;

options.experimental.replay.sessionSampleRate = 1.0;
options.experimental.replay.onErrorSampleRate = 1.0;
// options.experimental.replay.sessionSampleRate = 1.0;
// options.experimental.replay.onErrorSampleRate = 1.0;

_isIntegrationTest = isIntegrationTest;
if (_isIntegrationTest) {
Expand Down
6 changes: 6 additions & 0 deletions flutter/ios/Classes/SentryFlutter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public final class SentryFlutter {
if let appHangTimeoutIntervalMillis = data["appHangTimeoutIntervalMillis"] as? NSNumber {
options.appHangTimeoutInterval = appHangTimeoutIntervalMillis.doubleValue / 1000
}
if let spotlightUrl = data["spotlightUrl"] as? String {
options.spotlightUrl = spotlightUrl
}
if let enableSpotlight = data["enableSpotlight"] as? Bool {
options.enableSpotlight = enableSpotlight
}
if let proxy = data["proxy"] as? [String: Any] {
guard let host = proxy["host"] as? String,
let port = proxy["port"] as? Int,
Expand Down
2 changes: 2 additions & 0 deletions flutter/lib/src/native/sentry_native_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class SentryNativeChannel
'sessionSampleRate': options.experimental.replay.sessionSampleRate,
'onErrorSampleRate': options.experimental.replay.onErrorSampleRate,
},
'enableSpotlight': options.spotlight.enabled,
'spotlightUrl': options.spotlight.url,
});
}

Expand Down
8 changes: 7 additions & 1 deletion flutter/test/integrations/init_native_sdk_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ void main() {
'sessionSampleRate': null,
'onErrorSampleRate': null,
},
'enableSpotlight': false,
'spotlightUrl': null,
});
});

Expand Down Expand Up @@ -118,7 +120,9 @@ void main() {
pass: '0000',
)
..experimental.replay.sessionSampleRate = 0.1
..experimental.replay.onErrorSampleRate = 0.2;
..experimental.replay.onErrorSampleRate = 0.2
..spotlight =
Spotlight(enabled: true, url: 'http://localhost:8969/stream');

fixture.options.sdk.addIntegration('foo');
fixture.options.sdk.addPackage('bar', '1');
Expand Down Expand Up @@ -174,6 +178,8 @@ void main() {
'sessionSampleRate': 0.1,
'onErrorSampleRate': 0.2,
},
'enableSpotlight': true,
'spotlightUrl': 'http://localhost:8969/stream',
});
});
}
Expand Down

0 comments on commit c107ffb

Please sign in to comment.