Skip to content

Commit

Permalink
Chore: Migrate to sentry cocoa v8 (#1197)
Browse files Browse the repository at this point in the history
Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com>
Co-authored-by: Manoel Aranda Neto <marandaneto@gmail.com>
Closes #1161
Closes #1185
  • Loading branch information
denrase authored Jan 16, 2023
1 parent fab2a9a commit 8bea1f1
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 46 deletions.
20 changes: 17 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## Unreleased

### Breaking Changes

- Rename APM tracking feature flags to tracing ([#1222](https://github.com/getsentry/sentry-dart/pull/1222))
- Rename
- enableAutoPerformanceTracking to enableAutoPerformanceTracing
- enableOutOfMemoryTracking to enableWatchdogTerminationTracking

### Enhancements

- Migrate to sentry cocoa v8 ([#1197](https://github.com/getsentry/sentry-dart/pull/1197))

## 7.0.0-alpha.2

### Features
Expand All @@ -9,9 +22,10 @@
### Breaking Changes

- Enable APM features by default ([#1217](https://github.com/getsentry/sentry-dart/pull/1217))
- captureFailedRequests
- enableStructuredDataTracing
- enableUserInteractionTracing
- Enable by default
- captureFailedRequests
- enableStructuredDataTracing
- enableUserInteractionTracing
- Mark transaction as internal_error in case of unhandled errors ([#1218](https://github.com/getsentry/sentry-dart/pull/1218))

## 7.0.0-alpha.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ import java.lang.ref.WeakReference
import java.util.Locale
import java.util.UUID

@Suppress("TooManyFunctions")
class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private lateinit var channel: MethodChannel
private lateinit var context: Context

private var activity: WeakReference<Activity>? = null
private var framesTracker: ActivityFramesTracker? = null
private var autoPerformanceTrackingEnabled = false
private var autoPerformanceTracingEnabled = false

override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
context = flutterPluginBinding.applicationContext
Expand Down Expand Up @@ -155,28 +154,38 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
// options.isEnableNdk = false
}

args.getIfNotNull<Boolean>("enableAutoPerformanceTracking") { enableAutoPerformanceTracking ->
if (enableAutoPerformanceTracking) {
autoPerformanceTrackingEnabled = true
args.getIfNotNull<Boolean>("enableAutoPerformanceTracing") { enableAutoPerformanceTracing ->
if (enableAutoPerformanceTracing) {
autoPerformanceTracingEnabled = true
framesTracker = ActivityFramesTracker(LoadClass(), options)
}
}

args.getIfNotNull<Boolean>("sendClientReports") { options.isSendClientReports = it }

args.getIfNotNull<Map<String, Any>>("sdk") { sdk ->
val name = sdk["name"] as? String
val version = sdk["version"] as? String
if (name != null && version != null) {
val sdkVersion = SdkVersion(name, version)
options.setSentryClientName(name)
options.setSdkVersion(sdkVersion)
}
}

options.setBeforeSend { event, _ ->
setEventOriginTag(event)
addPackages(event, options.sdkVersion)
event
}

// missing proxy, enableScopeSync
// missing proxy
}
result.success("")
}

private fun fetchNativeAppStart(result: Result) {
if (!autoPerformanceTrackingEnabled) {
if (!autoPerformanceTracingEnabled) {
result.success(null)
return
}
Expand All @@ -199,7 +208,7 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}

private fun beginNativeFrames(result: Result) {
if (!autoPerformanceTrackingEnabled) {
if (!autoPerformanceTracingEnabled) {
result.success(null)
return
}
Expand All @@ -212,7 +221,7 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {

private fun endNativeFrames(id: String?, result: Result) {
val activity = activity?.get()
if (!autoPerformanceTrackingEnabled || activity == null || id == null) {
if (!autoPerformanceTracingEnabled || activity == null || id == null) {
if (id == null) {
Log.w("Sentry", "Parameter id cannot be null when calling endNativeFrames.")
}
Expand Down Expand Up @@ -263,7 +272,6 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}
}

@Suppress("ComplexMethod")
private fun setUser(user: Map<String, Any?>?, result: Result) {
if (user == null) {
Sentry.setUser(null)
Expand Down
3 changes: 3 additions & 0 deletions flutter/config/detekt-bl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>ComplexMethod:SentryFlutterPlugin.kt$SentryFlutterPlugin$override fun onMethodCall(call: MethodCall, result: Result)</ID>
<ID>ComplexMethod:SentryFlutterPlugin.kt$SentryFlutterPlugin$private fun setUser(user: Map&lt;String, Any?&gt;?, result: Result)</ID>
<ID>LongMethod:SentryFlutterPlugin.kt$SentryFlutterPlugin$private fun initNativeSdk(call: MethodCall, result: Result)</ID>
<ID>MagicNumber:MainActivity.kt$MainActivity$6_000</ID>
<ID>TooGenericExceptionCaught:MainActivity.kt$MainActivity$e: Exception</ID>
<ID>TooGenericExceptionThrown:MainActivity.kt$MainActivity$throw Exception("Catch this java exception thrown from Kotlin thread!")</ID>
<ID>TooGenericExceptionThrown:MainActivity.kt$MainActivity$throw RuntimeException("Catch this java exception!")</ID>
<ID>TooGenericExceptionThrown:MainActivity.kt$MainActivity$throw RuntimeException("Catch this platform exception!")</ID>
<ID>TooManyFunctions:SentryFlutterPlugin.kt$SentryFlutterPlugin : FlutterPluginMethodCallHandlerActivityAware</ID>
</CurrentIssues>
</SmellBaseline>
2 changes: 1 addition & 1 deletion flutter/example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion flutter/example/macos/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :osx, '10.11'
platform :osx, '10.13'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
6 changes: 3 additions & 3 deletions flutter/example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down Expand Up @@ -491,7 +491,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -538,7 +538,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
16 changes: 11 additions & 5 deletions flutter/ios/Classes/SentryFlutterPluginApple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,19 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
SentrySDK.start { options in
self.updateOptions(arguments: arguments, options: options)

if arguments["enableAutoPerformanceTracking"] as? Bool ?? false {
if arguments["enableAutoPerformanceTracing"] as? Bool ?? false {
PrivateSentrySDKOnly.appStartMeasurementHybridSDKMode = true
#if os(iOS) || targetEnvironment(macCatalyst)
PrivateSentrySDKOnly.framesTrackingMeasurementHybridSDKMode = true
#endif
}

if let sdk = arguments["sdk"] as? [String: Any?],
let name = sdk["name"] as? String,
let version = sdk["version"] as? String {
PrivateSentrySDKOnly.setSdkName(name, andVersionString: version)
}

// note : for now, in sentry-cocoa, beforeSend is not called before captureEnvelope
options.beforeSend = { event in
self.setEventOriginTag(event: event)
Expand Down Expand Up @@ -233,7 +239,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {

if didReceiveDidBecomeActiveNotification &&
(PrivateSentrySDKOnly.options.enableAutoSessionTracking ||
PrivateSentrySDKOnly.options.enableOutOfMemoryTracking) {
PrivateSentrySDKOnly.options.enableWatchdogTerminationTracking) {
// We send a SentryHybridSdkDidBecomeActive to the Sentry Cocoa SDK, so the SDK will mimics
// the didBecomeActiveNotification notification. This is needed for session and OOM tracking.
NotificationCenter.default.post(name: Notification.Name("SentryHybridSdkDidBecomeActive"), object: nil)
Expand Down Expand Up @@ -313,8 +319,8 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
options.maxCacheItems = maxCacheItems
}

if let enableOutOfMemoryTracking = arguments["enableOutOfMemoryTracking"] as? Bool {
options.enableOutOfMemoryTracking = enableOutOfMemoryTracking
if let enableWatchdogTerminationTracking = arguments["enableWatchdogTerminationTracking"] as? Bool {
options.enableWatchdogTerminationTracking = enableWatchdogTerminationTracking
}

if let sendClientReports = arguments["sendClientReports"] as? Bool {
Expand Down Expand Up @@ -581,7 +587,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
breadcrumbInstance.data = data
}

SentrySDK.addBreadcrumb(crumb: breadcrumbInstance)
SentrySDK.addBreadcrumb(breadcrumbInstance)

result("")
}
Expand Down
6 changes: 3 additions & 3 deletions flutter/ios/sentry_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Sentry SDK for Flutter with support to native through sentry-cocoa.
:tag => s.version.to_s }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Sentry/HybridSDK', '7.31.5'
s.dependency 'Sentry/HybridSDK', '8.0.0-rc.1'
s.ios.dependency 'Flutter'
s.osx.dependency 'FlutterMacOS'
s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.11'
s.ios.deployment_target = '11.0'
s.osx.deployment_target = '10.13'

# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
s.ios.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
Expand Down
9 changes: 7 additions & 2 deletions flutter/lib/src/integrations/native_sdk_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ class NativeSdkIntegration extends Integration<SentryFlutterOptions> {
'enableAutoNativeBreadcrumbs': options.enableAutoNativeBreadcrumbs,
'maxCacheItems': options.maxCacheItems,
'sendDefaultPii': options.sendDefaultPii,
'enableOutOfMemoryTracking': options.enableOutOfMemoryTracking,
'enableWatchdogTerminationTracking':
options.enableWatchdogTerminationTracking,
'enableNdkScopeSync': options.enableNdkScopeSync,
'enableAutoPerformanceTracking': options.enableAutoPerformanceTracking,
'enableAutoPerformanceTracing': options.enableAutoPerformanceTracing,
'sendClientReports': options.sendClientReports,
'sdk': {
'name': options.sdk.name,
'version': options.sdk.version,
},
});

options.sdk.addIntegration('nativeSdkIntegration');
Expand Down
4 changes: 2 additions & 2 deletions flutter/lib/src/sentry_flutter_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ class SentryFlutterOptions extends SentryOptions {
/// Enables Out of Memory Tracking for iOS and macCatalyst.
/// See the following link for more information and possible restrictions:
/// https://docs.sentry.io/platforms/apple/guides/ios/configuration/out-of-memory/
bool enableOutOfMemoryTracking = true;
bool enableWatchdogTerminationTracking = true;

/// Enable scope sync from Java to NDK.
/// Only available on Android.
bool enableNdkScopeSync = false;

/// Enable auto performance tracking by default.
bool enableAutoPerformanceTracking = true;
bool enableAutoPerformanceTracing = true;

/// Automatically track app start measurement and send it with the
/// first transaction. Set to false when configuring option to disable or if
Expand Down
39 changes: 28 additions & 11 deletions flutter/test/integrations/init_native_sdk_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void main() {
'dist': null,
'integrations': <String>[],
'packages': [
{'name': 'pub:sentry', 'version': sdkVersion}
{'name': 'pub:sentry_flutter', 'version': sdkVersion}
],
'diagnosticLevel': 'debug',
'maxBreadcrumbs': 100,
Expand All @@ -52,10 +52,14 @@ void main() {
'enableAutoNativeBreadcrumbs': true,
'maxCacheItems': 30,
'sendDefaultPii': false,
'enableOutOfMemoryTracking': true,
'enableWatchdogTerminationTracking': true,
'enableNdkScopeSync': false,
'enableAutoPerformanceTracking': true,
'sendClientReports': true
'enableAutoPerformanceTracing': true,
'sendClientReports': true,
'sdk': {
'name': 'sentry.dart.flutter',
'version': sdkVersion,
},
});
});

Expand Down Expand Up @@ -85,9 +89,9 @@ void main() {
..enableAutoNativeBreadcrumbs = false
..maxCacheItems = 0
..sendDefaultPii = true
..enableOutOfMemoryTracking = false
..enableWatchdogTerminationTracking = false
..enableNdkScopeSync = true
..enableAutoPerformanceTracking = false
..enableAutoPerformanceTracing = false
..sendClientReports = false;

options.sdk.addIntegration('foo');
Expand All @@ -111,7 +115,7 @@ void main() {
'dist': 'distfoo',
'integrations': ['foo'],
'packages': [
{'name': 'pub:sentry', 'version': sdkVersion},
{'name': 'pub:sentry_flutter', 'version': sdkVersion},
{'name': 'bar', 'version': '1'},
],
'diagnosticLevel': 'error',
Expand All @@ -121,10 +125,14 @@ void main() {
'enableAutoNativeBreadcrumbs': false,
'maxCacheItems': 0,
'sendDefaultPii': true,
'enableOutOfMemoryTracking': false,
'enableWatchdogTerminationTracking': false,
'enableNdkScopeSync': true,
'enableAutoPerformanceTracking': false,
'sendClientReports': false
'enableAutoPerformanceTracing': false,
'sendClientReports': false,
'sdk': {
'name': 'sentry.dart.flutter',
'version': sdkVersion,
},
});
});

Expand Down Expand Up @@ -166,7 +174,16 @@ MethodChannel createChannelWithCallback(

SentryFlutterOptions createOptions() {
final mockPlatformChecker = MockPlatformChecker(hasNativeIntegration: true);
return SentryFlutterOptions(dsn: fakeDsn, checker: mockPlatformChecker);
final options = SentryFlutterOptions(
dsn: fakeDsn,
checker: mockPlatformChecker,
);
options.sdk = SdkVersion(
name: sdkName,
version: sdkVersion,
);
options.sdk.addPackage('pub:sentry_flutter', sdkVersion);
return options;
}

class Fixture {
Expand Down
2 changes: 1 addition & 1 deletion min_version_test/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion min_version_test/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
Loading

0 comments on commit 8bea1f1

Please sign in to comment.