newrelic / newrelic-flutter-agent

New Relic agent SDK for Flutter hybrid mobile apps
Apache License 2.0
6 stars 12 forks source link

recordError() not sending stacktrace on iOS #66

Closed asegurola closed 1 year ago

asegurola commented 1 year ago

Happening in version 1.0.4, it's an iOS-only bug.

When calling recordError() with a stacktrace on iOS the data doesn't seem to get to the newrelic portal. It's either not getting to the newrelic servers or I am failing to find it anywhere. When I execute a query like:

SELECT *
FROM MobileHandledException
WHERE  userId ='<my user id>'
since 3 day ago
limit 2000

I see exceptions from today from my testing but none of those entries have any "stacktrace" column.

I believe that it might be related to this piece of code here:

SwiftNewrelicMobilePlugin.swift

        case "recordError":
            let exceptionMessage = args!["exception"] as? String
            let reason = args!["reason"] as? String
            let fatal = args!["fatal"] as? Bool
                        let stackTraceElements = args!["stackTraceElements"] as? [[String : Any]] ?? [[String : Any]]()
            let version = Bundle.main.infoDictionary?["CFBundleVersion"] ?? "1.0.3"

            let attributes: [String:Any] = [
                "name": exceptionMessage ?? "Exception name not found",
                "reason": reason ?? "Reason not found",
                "cause": reason ?? "Reason not found",
                "fatal": fatal ?? false,
                "stackTraceElements": stackTraceElements,
                "appBuild": version,
                "appVersion": version
            ]

            NewRelic.recordHandledException(withStackTrace: attributes)

            result("return")

This piece of swift code sends a list of maps as an attribute called stackTraceElements but I can't find that with an NRQL query even though I see the handledException entry, there is no "stacktrace" data.

Looking at the dart code that calls this recordError() method there is also a plan stackTrace parameter send to the iOS module from the dart runtime. If I use that instead of stackTraceElements and the that stackTrace string as an attribute it seems to work. Although I had to send it with a different name for it to show up. Something like flutterStackTrace.

ndesai-newrelic commented 1 year ago

@asegurola let me check it from our side.

ndesai-newrelic commented 1 year ago

@asegurola In our system, stack traces are stored as blobs. This means that they are stored as binary data rather than as text. When viewing stack traces, users can check the UI to view them.

asegurola commented 1 year ago

Got it, so to view the actual stacktrace I need to go throw the web UI since it's not exposed in the NRQL query response. Thanks.