Skip to content

fix(ios): Add event.origin and event.environment on unhandled exception on iOS #1419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- Fix `event.origin` and `event.environment` on unhandled exceptions ([#1419](https://github.com/getsentry/sentry-dart/pull/1419))

### Dependencies

- Bump Android SDK from v6.17.0 to v6.18.1 ([#1415](https://github.com/getsentry/sentry-dart/pull/1415))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private var framesTracker: ActivityFramesTracker? = null
private var autoPerformanceTracingEnabled = false

private val flutterSdk = "sentry.dart.flutter"
private val androidSdk = "sentry.java.android.flutter"
private val nativeSdk = "sentry.native.android"

override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
context = flutterPluginBinding.applicationContext
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "sentry_flutter")
Expand Down Expand Up @@ -169,17 +173,15 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {

args.getIfNotNull<Long>("maxAttachmentSize") { options.maxAttachmentSize = it }

val name = "sentry.java.android.flutter"

var sdkVersion = options.sdkVersion
if (sdkVersion == null) {
sdkVersion = SdkVersion(name, VERSION_NAME)
sdkVersion = SdkVersion(androidSdk, VERSION_NAME)
} else {
sdkVersion.name = name
sdkVersion.name = androidSdk
}

options.sdkVersion = sdkVersion
options.sentryClientName = "$name/$VERSION_NAME"
options.sentryClientName = "$androidSdk/$VERSION_NAME"

options.setBeforeSend { event, _ ->
setEventOriginTag(event)
Expand Down Expand Up @@ -464,10 +466,6 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
result.success("")
}

private val flutterSdk = "sentry.dart.flutter"
private val androidSdk = "sentry.java.android"
private val nativeSdk = "sentry.native"

private fun setEventOriginTag(event: SentryEvent) {
event.sdk?.let {
when (it.name) {
Expand Down
7 changes: 4 additions & 3 deletions flutter/ios/Classes/SentryFlutterPluginApple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import AppKit
// swiftlint:disable:next type_body_length
public class SentryFlutterPluginApple: NSObject, FlutterPlugin {

private static let nativeClientName = "sentry.cocoa.flutter"

// The Cocoa SDK is init. after the notification didBecomeActiveNotification is registered.
// We need to be able to receive this notification and start a session when the SDK is fully operational.
private var didReceiveDidBecomeActiveNotification = false
Expand Down Expand Up @@ -257,9 +259,8 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
#endif
}

let name = "sentry.cocoa.flutter"
let version = PrivateSentrySDKOnly.getSdkVersionString()
PrivateSentrySDKOnly.setSdkName(name, andVersionString: version)
PrivateSentrySDKOnly.setSdkName(SentryFlutterPluginApple.nativeClientName, andVersionString: version)

// note : for now, in sentry-cocoa, beforeSend is not called before captureEnvelope
options.beforeSend = { event in
Expand Down Expand Up @@ -409,7 +410,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
if isValidSdk(sdk: sdk) {

switch sdk["name"] as? String {
case "sentry.cocoa":
case SentryFlutterPluginApple.nativeClientName:
#if os(OSX)
let origin = "mac"
#elseif os(watchOS)
Expand Down