Skip to content

Commit

Permalink
fix(sdk): Add event.origin and event.environment on unhandled nat…
Browse files Browse the repository at this point in the history
…ive exceptions (#1419)
  • Loading branch information
krystofwoldrich authored May 5, 2023
1 parent 211a7aa commit 895becc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
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:/getsentry/sentry-dart/pull/1419))

### Dependencies

- Bump Android SDK from v6.17.0 to v6.18.1 ([#1415](https:/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

0 comments on commit 895becc

Please sign in to comment.