-
- Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(node-core): Handle custom scope in log messages without parameters #18322
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits Select commit Hold shift + click to select a range
adf801f fix(node): Always use custom scope when calling `Sentry.logger.*`
Lms24 75744da add node integration test
Lms24 c166bbc add unit tests
Lms24 915ff9a fix incorrect usage in integration test
Lms24 efb7672 Update dev-packages/node-core-integration-tests/suites/public-api/log…
Lms24 4150a62 lint
Lms24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add node integration test
- Loading branch information
commit 75744da04becc4aededc51b9b6490d419af62d74
There are no files selected for viewing
27 changes: 27 additions & 0 deletions 27 dev-packages/node-core-integration-tests/suites/public-api/logs/subject.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import * as Sentry from '@sentry/node-core'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
| | ||
| const client = new Sentry.NodeClient({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| transport: loggingTransport, | ||
| stackParser: Sentry.defaultStackParser, | ||
| integrations: [], | ||
| enableLogs: true, | ||
| sendDefaultPii: true, | ||
| }); | ||
| | ||
| const customScope = new Sentry.Scope(); | ||
| customScope.setClient(client); | ||
| customScope.update({ user: { username: 'h4cktor' } }); | ||
| client.init(); | ||
| | ||
| async function run(): Promise<void> { | ||
| Sentry.logger.info('test info', { foo: 'bar1' }, { scope: customScope }); | ||
| Sentry.logger.info('test info with {param}', [1], { foo: 'bar2' }, { scope: customScope }); | ||
| Sentry.logger.info(Sentry.logger.fmt`test info with fm ${1}`, [1], { foo: 'bar3' }, { scope: customScope }); | ||
| | ||
| await Sentry.flush(); | ||
| } | ||
| | ||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| void run(); |
127 changes: 127 additions & 0 deletions 127 dev-packages/node-core-integration-tests/suites/public-api/logs/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import { afterAll, describe, expect, test } from 'vitest'; | ||
| import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
| | ||
| describe('logger public API', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
| | ||
| test('captures logs with parameters in different forms', async () => { | ||
| const runner = createRunner(__dirname, 'subject.ts') | ||
| .expect({ | ||
| log: { | ||
| items: [ | ||
| { | ||
| attributes: { | ||
| foo: { | ||
| type: 'string', | ||
| value: 'bar1', | ||
| }, | ||
| 'sentry.sdk.name': { | ||
| type: 'string', | ||
| value: 'sentry.javascript.node', | ||
| }, | ||
| 'sentry.sdk.version': { | ||
| type: 'string', | ||
| value: expect.any(String), | ||
| }, | ||
| 'server.address': { | ||
| type: 'string', | ||
| value: 'M6QX4Q5HKV.local', | ||
| }, | ||
| 'user.name': { | ||
| type: 'string', | ||
| value: 'h4cktor', | ||
| }, | ||
| }, | ||
| body: 'test info', | ||
| level: 'info', | ||
| severity_number: 9, | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.stringMatching(/^[\da-f]{32}$/), | ||
| }, | ||
| { | ||
| attributes: { | ||
| foo: { | ||
| type: 'string', | ||
| value: 'bar2', | ||
| }, | ||
| 'sentry.message.parameter.0': { | ||
| type: 'integer', | ||
| value: 1, | ||
| }, | ||
| 'sentry.message.template': { | ||
| type: 'string', | ||
| value: 'test info with {param}', | ||
| }, | ||
| 'sentry.sdk.name': { | ||
| type: 'string', | ||
| value: 'sentry.javascript.node', | ||
| }, | ||
| 'sentry.sdk.version': { | ||
| type: 'string', | ||
| value: expect.any(String), | ||
| }, | ||
| 'server.address': { | ||
| type: 'string', | ||
| value: 'M6QX4Q5HKV.local', | ||
| }, | ||
| 'user.name': { | ||
| type: 'string', | ||
| value: 'h4cktor', | ||
| }, | ||
| }, | ||
| body: 'test info with {param} 1', | ||
| level: 'info', | ||
| severity_number: 9, | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.stringMatching(/^[\da-f]{32}$/), | ||
| }, | ||
| { | ||
| attributes: { | ||
| foo: { | ||
| type: 'string', | ||
| value: 'bar3', | ||
| }, | ||
| 'sentry.message.parameter.0': { | ||
| type: 'integer', | ||
| value: 1, | ||
| }, | ||
| 'sentry.message.template': { | ||
| type: 'string', | ||
| value: '"test info with fm 1"', | ||
| }, | ||
| 'sentry.sdk.name': { | ||
| type: 'string', | ||
| value: 'sentry.javascript.node', | ||
| }, | ||
| 'sentry.sdk.version': { | ||
| type: 'string', | ||
| value: expect.any(String), | ||
| }, | ||
| 'server.address': { | ||
| type: 'string', | ||
| value: 'M6QX4Q5HKV.local', | ||
| }, | ||
| 'user.name': { | ||
| type: 'string', | ||
| value: 'h4cktor', | ||
| }, | ||
| }, | ||
| body: `[String: 'test info with fm 1'] { | ||
| __sentry_template_string__: 'test info with fm %s', | ||
| __sentry_template_values__: [ 1 ] | ||
| } 1`, | ||
| level: 'info', | ||
| severity_number: 9, | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.stringMatching(/^[\da-f]{32}$/), | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| .start(); | ||
| | ||
| await runner.completed(); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.