-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[No QA][Sentry] Send App logs to Sentry #76335
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
Changes from all commits
b87c3e8
faf4ad2
b7d9894
729d0ee
a81e68c
01cf457
e28ceed
ec7789a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| "Airplus", | ||
| "airshipconfig", | ||
| "airside", | ||
| "alrt", | ||
| "Amal", | ||
| "Amal's", | ||
| "americanexpressfdx", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import * as Sentry from '@sentry/react-native'; | ||
|
|
||
| type SentryLogLevel = 'debug' | 'info' | 'warn' | 'error'; | ||
|
|
||
| /** | ||
| * Method deciding whether a log packet should be forwarded to Sentry. | ||
| * | ||
| * ATTENTION! | ||
| * Currently, this always returns false because we want to deliberately decide what is being forwarded. | ||
| * There is no redaction / filtering of sensitive data implemented yet. When you implement any log forwarding logic, make sure that you do not leak any sensitive data. | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| function shouldForwardLog(log: {message?: string; parameters?: Record<string, unknown> | undefined}) { | ||
| return false; | ||
| } | ||
|
|
||
| function mapLogMessageToSentryLevel(message: string): SentryLogLevel { | ||
| if (message.startsWith('[alrt]')) { | ||
| return 'error'; | ||
| } | ||
| if (message.startsWith('[warn]') || message.startsWith('[hmmm]')) { | ||
| return 'warn'; | ||
| } | ||
| if (message.startsWith('[info]')) { | ||
| return 'info'; | ||
| } | ||
| return 'debug'; | ||
| } | ||
|
|
||
| function forwardLogsToSentry(logPacket: string | undefined) { | ||
| if (!logPacket) { | ||
| return; | ||
| } | ||
|
|
||
| let parsedPacket: Array<{message?: string; parameters?: Record<string, unknown> | undefined}> | undefined; | ||
| try { | ||
| parsedPacket = JSON.parse(logPacket) as typeof parsedPacket; | ||
| } catch { | ||
| Sentry.logger.warn('Failed to parse log packet for Sentry forwarding', {logPacket}); | ||
| return; | ||
| } | ||
|
|
||
| if (!Array.isArray(parsedPacket)) { | ||
| return; | ||
| } | ||
|
|
||
| for (const logLine of parsedPacket) { | ||
| if (!logLine || typeof logLine.message !== 'string') { | ||
| continue; | ||
| } | ||
sosek108 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!shouldForwardLog(logLine)) { | ||
| continue; | ||
| } | ||
|
|
||
| const level = mapLogMessageToSentryLevel(logLine.message); | ||
| const logMethod = Sentry.logger[level]; | ||
| if (!logMethod) { | ||
| continue; | ||
| } | ||
|
|
||
| if (logLine.parameters) { | ||
| logMethod(logLine.message, logLine.parameters); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a good point, although I was thinking this would follow something along the lines of what we have in Auth, where we just redact parameters that are not whitelisted. So we would do something related to that in a follow up PR where we fill the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think this is good idea.
only web? what's about mobile? Maybe we could move this log forwarding after data is redacted via expensify's mechanisms?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Mobile sends to Web-E and then Web-E actually logs it, so I think this would be cumbersome, it would go something like
This would probably make logs not follow the correct timeline I think.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so we'll do redaction in follow up PR. If you're ok with:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm but if we add redaction later there will be a version of the app with no redaction of the logs, not sure if I am following. We should make sure we redact them from beginning as we dont want to be dealing with removing sensitive data from Sentry so early 😅
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My initial line of thought was that: If we don't send anything there is nothing to redact and redaction should be added alongside with logs that we add to sending. But as I understand this thinking is shady we can copy the redaction from web (mentioned here) and then push this PR to merge. |
||
| } else { | ||
| logMethod(logLine.message); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default forwardLogsToSentry; | ||
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.
We're connecting Sentry logging to server log event so the input is string here. To decide what severity of logs should be logged I parse the log entry. Maybe you see better place to put forwarding so we can have all info without parsing the string?