Skip to content
Prev Previous commit
Next Next commit
add node integration test
  • Loading branch information
Lms24 committed Nov 25, 2025
commit 75744da04becc4aededc51b9b6490d419af62d74
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();
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();
});
});