Skip to content
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

feat(crashlytics): Extend recordException to provide a possibility to add custom properties per exception and not only globally #825

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

adrenaline15
Copy link

@adrenaline15 adrenaline15 commented Feb 18, 2025

https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#log-excepts

Pull request checklist

Please check if your PR fulfills the following requirements:

  • The changes have been tested successfully.
  • A changeset has been created (npm run changeset).
  • I have read and followed the pull request guidelines.

@adrenaline15 adrenaline15 changed the title * fixes #824 feat(crashlytics): Extend recordException to provide a possibility to add custom properties per exception and not only globally Feb 18, 2025
* correct usage of `JSONObject` instead of `JSObject`
* testing done
@adrenaline15
Copy link
Author

image

    const stacktrace = await StackTrace.fromError(err);
    await FirebaseCrashlytics.recordException({
      message: '[NOT AN EXCEPTION]',
      stacktrace,
      customProperties: [
        {
          type: 'string',
          key: 'error_name',
          value: err?.name,
        },
        {
          type: 'string',
          key: 'error_message',
          value: err?.message,
        },
        {
          type: 'string',
          key: 'error_type',
          value: err?.type,
        },
        !!err.code && {
          type: 'string',
          key: 'error_code',
          value: err.code,
        },
      ],
    });

Copy link
Member

@robingenz robingenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add iOS support if it's supported by the Firebase iOS SDK since this plugin supports both platforms.

@adrenaline15
Copy link
Author

adrenaline15 commented Feb 18, 2025

Please also add iOS support if it's supported by the Firebase iOS SDK since this plugin supports both platforms.

actually it looks like its not supported the same way on iOS.. (i also added it to the issue #824)

firebase/firebase-ios-sdk#13153

maybe it could be achieved tho..

https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=ios#log-excepts

i just feel like it would be all reported as string then? so theoretically not the same.. but i could be wrong here.

@adrenaline15
Copy link
Author

to quickly follow-up on this topic for iOS:

looks like the userinfo-way will not work when using a custom error-model = when a stacktrace is provided:

firebase/firebase-ios-sdk#11452 (comment)

that means the only possibility to somehow achieve this would be to set them as global values before and resetting them right after the report.

Crashlytics.crashlytics().setCustomValue("value", forKey: key)
Crashlytics.crashlytics().record(exceptionModel: error)
Crashlytics.crashlytics().setCustomValue(nil, forKey: key)

@robingenz
Copy link
Member

In this case just ignore the customProperties property if a stacktrace is provided. Make sure to document this in the property description.

@adrenaline15
Copy link
Author

sadly that means there is no way to have both then right?

so a stacktrace + custom properties per non-fatal crash

which honestly was my initial motivation, since i wanted to debug keychain-errors for ios^^

@robingenz
Copy link
Member

sadly that means there is no way to have both then right?

Right. But you could implement the workaround you mentioned here yourself using the plugin API. This does not need to be implemented in the plugin itself.

@adrenaline15
Copy link
Author

valid point... seems to be suboptimal either way 🫤

i will try my luck with implementing this then.

@robingenz
Copy link
Member

Yes, i know. Unfortunately, there is nothing we can do about it. It's a limitation of the iOS SDK. Do you still want to finish the PR?

@adrenaline15
Copy link
Author

yes, i think i'm pretty close :)

…ations as outlined in the changeset/readme

* updates the definitions, readme and changeset
@adrenaline15
Copy link
Author

sorry, needed to finish some work.

i did now implement the iOS-part too, so feel free to have a look and change it accordingly 🙏

actually i forgot that this would not work in the current implementation:

Crashlytics.crashlytics().setCustomValue("value", forKey: key)
Crashlytics.crashlytics().record(exceptionModel: error)
Crashlytics.crashlytics().setCustomValue(nil, forKey: key)

for this there would need to be another method to clear/reset a global value by its key (or provide a dedicated type for it in the setCustomValue-fn)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants