feat: fix logging tags for sentry#1365
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR updates Sentry initialization in both the Next.js (frontend) and NestJS (backend) shared libraries to ensure consistent service/component tagging for both events and logs.
Changes:
- Add
beforeSendhooks to stamp Sentry events withservice/componenttags. - Add
beforeSendLoghooks to stamp Sentry logs withservice/componentattributes. - Update exposed ports in
docker-compose.dev.yamlfor pgAdmin and Temporal UI.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| libraries/react-shared-libraries/src/sentry/initialize.sentry.next.basic.ts | Adds beforeSend and beforeSendLog hooks to enforce frontend/Next.js tags on events and logs. |
| libraries/nestjs-libraries/src/sentry/initialize.sentry.ts | Adds beforeSend and beforeSendLog hooks to enforce app/service tags for NestJS events and logs. |
| docker-compose.dev.yaml | Changes dev port mappings for pgAdmin and Temporal UI. |
| beforeSendLog: (log: any) => { | ||
| log.attributes = { ...(log.attributes || {}), service: 'frontend', component: 'nextjs' }; | ||
| return log; | ||
| }, |
There was a problem hiding this comment.
Bug: The beforeSendLog hook in the Next.js Sentry config will not run because enableLogs: true is not set in the Sentry.init call.
Severity: MEDIUM
Suggested Fix
Add enableLogs: true to the Sentry.init configuration object within initialize.sentry.next.basic.ts to activate the log pipeline and ensure the beforeSendLog hook is executed for frontend log events.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location:
libraries/react-shared-libraries/src/sentry/initialize.sentry.next.basic.ts#L83-L86
Potential issue: The `beforeSendLog` hook is defined in
`initialize.sentry.next.basic.ts` to add `service` and `component` attributes to
frontend log events. However, this hook will never be triggered because the
`Sentry.init` call is missing the `enableLogs: true` option. The callers,
`initializeSentryServer` and `initializeSentryClient`, do not provide this option
through the `extension` parameter. Without `enableLogs: true`, Sentry's log pipeline is
disabled, rendering the `beforeSendLog` hook ineffective and preventing the enrichment
of frontend logs.
Did we get this right? 👍 / 👎 to inform future reviews.
What kind of change does this PR introduce?
eg: Bug fix, feature, docs update, ...
Why was this change needed?
Please link to related issues when possible, and explain WHY you changed things, not WHAT you changed.
Other information:
eg: Did you discuss this change with anybody before working on it (not required, but can be a good idea for bigger changes). Any plans for the future, etc?
Checklist:
Put a "X" in the boxes below to indicate you have followed the checklist;