Show Native Logs
Problem Statement
Hi,
Can we please add the native logs to Console tab as well ? Currently it is not possible to debug using only the javascript logs. Adding logs for kotlin/swift would help a lot.
Solution Brainstorm
No response
Are you willing to submit a PR?
None
Thank you for your suggestion @gajrajgchouhan 🙇 We will consider this and iterate back.
Hey @gajrajgchouhan! Could you let us know what logs do you mean? Are you talking about Session Replays and logs shown there or is there something else you meant? Thanks a lot.
Closing due to inactivity. Feel free to comment and we will be glad to resume the investigation.
Hi, sorry for the late reply. I meant the logs shown in session replay. Currently we only see from javascript side
Thank you for the clarification @gajrajgchouhan 🙇 We will consider this and iterate back.
Hello @gajrajgchouhan and thanks again for your suggestions.
The Console tab is designed to show log messages coming from your JavaScript console. If you want to combine logs from both the native side and the JavaScript side in one place, you can use the Logs feature.
This feature includes Session Replay support — all logs you send will have a session_id specified, allowing you to search and filter by session_id and even view logs in a dedicated tab for each particular session replay.
This is how it looks in practice:
In this case, all but one log message were sent by JS code, while the remaining message was sent by native Android code. As you can see, everything is displayed in one place.
Please let me know if it fits your needs.
Thanks @alwx , do you have the code of this screenshot? It would really help me here
@gajrajgchouhan sure! You can find my sample app here: https://github.com/alwx-sentry/5242-logs-and-native-logs
Here is the brief description of it:
- I've added native log statements only for Android (see
android/app/src/main/java/com/testappsentry/MainActivity.kt): after you launch the app you have to wait 5 seconds, after that a warn message will be printed from the native side. - in
App.tsx(line 34-35) you can find some code that prints two messages once you press the "Try" button on the screen. One message is being printed withconsole.warn(), and another one withSentry.logger.info(). This is done to illustrate howSentry.consoleLoggingIntegrationworks. - There are also some JS console statements I've added just to illustrate how the console output gets printed as well (you can find that in
ImageBrowserApp.tsx)
Please don't forget that in order for the app to work you need to
- specify your DSN in
App.tsx(line 14) - add
android/sentry.propertieswith the correctauth.tokenand other parameters
Let me know if there is something else I can help you with.
Hi @alwx I went throught the repo and my console logs are being captured in the logs, but my native code is not being captured "in the replay". (I am trying in iphone right now, will let you know, yet to try on android) I found the swift logs under the logs, but how do i associate with a replay id ?
SentrySDK.start { options in
options.dsn =
"SOMETHING"
options.debug = true // Enabled debug when first installing is always helpful
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
}
@gajrajgchouhan you shouldn't be doing anything special — your logs should come with the correct replay ID associated with them since that information is actually being added later, and RN SDK uses native SDKs to get the correct replay ID (https://github.com/getsentry/sentry-react-native/blob/main/packages/core/src/js/integrations/logEnricherIntegration.ts#L91). Native SDKs themselves use exactly the same function to get the correct replay ID that's why those IDs will be the same.
But in order for it all to work you need to make sure that:
- You use the latest version of RN SDK (it is 7.7.0)
- We're talking about logs and not the console output (see my previous comment)
- You've enabled logs in the configuration you've passed to
Sentry.init. It's done by addingenableLogs: true
I have done all of these, lemme check it again. @alwx
Hi, so I have tested with my Android app as well. This issue only occurs on iOS. On Android, the logs are perfectly tied with the replay, and they are present under the logs tab (in replay). What should I do about this? Should we report it to the iOS team? @alwx
@gajrajgchouhan Let me check this again. I will come back to you today or tomorrow.