-
-
Notifications
You must be signed in to change notification settings - Fork 121
feat(crashlytics): support custom properties in recordException(...)
method
#825
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
Conversation
* adds the possibility to add custom properties when recording a non-fatal exception as outlined here: > https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#log-excepts
* correct usage of `JSONObject` instead of `JSObject` * testing done
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,
},
],
}); |
There was a problem hiding this 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.
actually it looks like its not supported the same way on iOS.. (i also added it to the issue #824) maybe it could be achieved tho..
i just feel like it would be all reported as string then? so theoretically not the same.. but i could be wrong here. |
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: 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) |
In this case just ignore the |
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^^ |
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. |
valid point... seems to be suboptimal either way 🫤 i will try my luck with implementing this then. |
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? |
yes, i think i'm pretty close :) |
…ations as outlined in the changeset/readme * updates the definitions, readme and changeset
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:
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 |
.changeset/giant-kids-tell.md
Outdated
- adds the possibility to add dedicated custom properties when recording a non-fatal exception as outlined here: | ||
- https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#log-excepts | ||
- https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=ios#log-excepts | ||
> Note: on iOS this cannot be combined with `stacktrace` due to [limitations in the ios-sdk](https://github.com/firebase/firebase-ios-sdk/discussions/11452#discussioncomment-6277129). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- adds the possibility to add dedicated custom properties when recording a non-fatal exception as outlined here: | |
- https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#log-excepts | |
- https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=ios#log-excepts | |
> Note: on iOS this cannot be combined with `stacktrace` due to [limitations in the ios-sdk](https://github.com/firebase/firebase-ios-sdk/discussions/11452#discussioncomment-6277129). | |
feat: support custom properties in `recordException(...)` method |
Please just use a one-liner here.
@@ -56,9 +59,67 @@ public void deleteUnsentReports() { | |||
getFirebaseCrashlyticsInstance().deleteUnsentReports(); | |||
} | |||
|
|||
public void recordException(String message, JSArray stacktrace) { | |||
public void recordException(String message, JSArray stacktrace, JSArray customProperties) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void recordException(String message, JSArray stacktrace, JSArray customProperties) { | |
public void recordException(String message, JSArray stacktrace, @Nullable JSArray customProperties) { |
Let's add the @Nullable
annotation to make it easier to maintain.
...rc/main/java/io/capawesome/capacitorjs/plugins/firebase/crashlytics/FirebaseCrashlytics.java
Outdated
Show resolved
Hide resolved
packages/crashlytics/ios/Plugin/FirebaseCrashlyticsPlugin.swift
Outdated
Show resolved
Hide resolved
packages/crashlytics/ios/Plugin/FirebaseCrashlyticsPlugin.swift
Outdated
Show resolved
Hide resolved
packages/crashlytics/ios/Plugin/FirebaseCrashlyticsPlugin.swift
Outdated
Show resolved
Hide resolved
@adrenaline15 FYI: I'm releasing a new version of Capacitor Firebase tomorrow. It would be cool if we could include your feature there. |
i did now update the MR with the desired changes 🤞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run npm run fmt
to format your code.
> `npm run fmt`
@capacitor-firebase/analytics
@capacitor-firebase/app
@capacitor-firebase/app-check
@capacitor-firebase/authentication
@capacitor-firebase/crashlytics
@capacitor-firebase/firestore
@capacitor-firebase/functions
@capacitor-firebase/messaging
@capacitor-firebase/performance
@capacitor-firebase/remote-config
@capacitor-firebase/storage
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
recordException(...)
method
@adrenaline15 I just noticed that these custom properties are called keys and values in Crashlytics. I have therefore renamed the option, see #835. Please don't be surprised and thank you for your contribution! |
no worries :) thanks for your great contributions to the capacitor-ecosystem <3 |
Hi guys, I updated my project to v7.1.0, and it seems there's an error when calling the To fix the issue, I had to pass
|
This is already fixed and will be published soon: #842 |
Thank you @robingenz |
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run changeset
).