From 33d0587b190ef0de4ccf9e1e0f2623ffaa76cd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Andra=C5=A1ec?= Date: Tue, 25 Jul 2023 08:30:55 +0000 Subject: [PATCH] Add `appHangTimeoutInterval` to `SentryFlutterOptions` (#1568) Co-authored-by: Manoel Aranda Neto --- CHANGELOG.md | 2 ++ flutter/example/lib/main.dart | 1 - flutter/ios/Classes/SentryFlutterPluginApple.swift | 4 ++++ .../lib/src/integrations/native_sdk_integration.dart | 2 ++ flutter/lib/src/sentry_flutter_options.dart | 10 +++++++++- .../integrations/init_native_sdk_integration_test.dart | 5 ++++- 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e558039d62..152a7a9d11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ [Trace origin](https://develop.sentry.dev/sdk/performance/trace-origin/) indicates what created a trace or a span. Not all transactions and spans contain enough information to tell whether the user or what precisely in the SDK created it. Origin solves this problem. The SDK now sends origin for transactions and spans. +- Add `appHangTimeoutInterval` to `SentryFlutterOptions` ([#1568](https://github.com/getsentry/sentry-dart/pull/1568)) + ### Dependencies - Bump Cocoa SDK from v8.8.0 to v8.9.1 ([#1553](https://github.com/getsentry/sentry-dart/pull/1553)) diff --git a/flutter/example/lib/main.dart b/flutter/example/lib/main.dart index 9d02d1ecba..6d657a589e 100644 --- a/flutter/example/lib/main.dart +++ b/flutter/example/lib/main.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:io' show Platform; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; diff --git a/flutter/ios/Classes/SentryFlutterPluginApple.swift b/flutter/ios/Classes/SentryFlutterPluginApple.swift index 42f55d3f3b..e5ae1a6c13 100644 --- a/flutter/ios/Classes/SentryFlutterPluginApple.swift +++ b/flutter/ios/Classes/SentryFlutterPluginApple.swift @@ -384,6 +384,10 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin { if let enableAppHangTracking = arguments["enableAppHangTracking"] as? Bool { options.enableAppHangTracking = enableAppHangTracking } + + if let appHangTimeoutIntervalMillis = arguments["appHangTimeoutIntervalMillis"] as? UInt { + options.appHangTimeoutInterval = TimeInterval(appHangTimeoutIntervalMillis) / 1000 + } } private func logLevelFrom(diagnosticLevel: String) -> SentryLevel { diff --git a/flutter/lib/src/integrations/native_sdk_integration.dart b/flutter/lib/src/integrations/native_sdk_integration.dart index 89f0c5ada2..9c4a98379e 100644 --- a/flutter/lib/src/integrations/native_sdk_integration.dart +++ b/flutter/lib/src/integrations/native_sdk_integration.dart @@ -51,6 +51,8 @@ class NativeSdkIntegration implements Integration { 'enableAppHangTracking': options.enableAppHangTracking, 'connectionTimeoutMillis': options.connectionTimeout.inMilliseconds, 'readTimeoutMillis': options.readTimeout.inMilliseconds, + 'appHangTimeoutIntervalMillis': + options.appHangTimeoutInterval.inMilliseconds, }); options.sdk.addIntegration('nativeSdkIntegration'); diff --git a/flutter/lib/src/sentry_flutter_options.dart b/flutter/lib/src/sentry_flutter_options.dart index 2f5ccd96d1..a1d7755c3c 100644 --- a/flutter/lib/src/sentry_flutter_options.dart +++ b/flutter/lib/src/sentry_flutter_options.dart @@ -195,10 +195,18 @@ class SentryFlutterOptions extends SentryOptions { bool attachViewHierarchy = false; /// When enabled, the SDK tracks when the application stops responding for a - /// specific amount of time (default 2s). + /// specific amount of time, See [appHangTimeoutInterval]. /// Only available on iOS and macOS. bool enableAppHangTracking = true; + /// The minimum amount of time an app should be unresponsive to be classified + /// as an App Hanging. The actual amount may be a little longer. Avoid using + /// values lower than 100ms, which may cause a lot of app hangs events being + /// transmitted. + /// Default to 2s. + /// Only available on iOS and macOS. + Duration appHangTimeoutInterval = Duration(seconds: 2); + /// Connection timeout. This will only be synced to the Android native SDK. Duration connectionTimeout = Duration(seconds: 5); diff --git a/flutter/test/integrations/init_native_sdk_integration_test.dart b/flutter/test/integrations/init_native_sdk_integration_test.dart index ec1e59f94f..4ed6a3d3b9 100644 --- a/flutter/test/integrations/init_native_sdk_integration_test.dart +++ b/flutter/test/integrations/init_native_sdk_integration_test.dart @@ -62,6 +62,7 @@ void main() { 'enableAppHangTracking': true, 'connectionTimeoutMillis': 5000, 'readTimeoutMillis': 5000, + 'appHangTimeoutIntervalMillis': 2000, }); }); @@ -100,7 +101,8 @@ void main() { ..captureFailedRequests = false ..enableAppHangTracking = false ..connectionTimeout = Duration(milliseconds: 9001) - ..readTimeout = Duration(milliseconds: 9002); + ..readTimeout = Duration(milliseconds: 9002) + ..appHangTimeoutInterval = Duration(milliseconds: 9003); options.sdk.addIntegration('foo'); options.sdk.addPackage('bar', '1'); @@ -143,6 +145,7 @@ void main() { 'enableAppHangTracking': false, 'connectionTimeoutMillis': 9001, 'readTimeoutMillis': 9002, + 'appHangTimeoutIntervalMillis': 9003, }); });