Skip to content

Commit 75744da

Browse files
committed
add node integration test
1 parent adf801f commit 75744da

2 files changed

Lines changed: 154 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as Sentry from '@sentry/node-core';
2+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
3+
4+
const client = new Sentry.NodeClient({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
transport: loggingTransport,
7+
stackParser: Sentry.defaultStackParser,
8+
integrations: [],
9+
enableLogs: true,
10+
sendDefaultPii: true,
11+
});
12+
13+
const customScope = new Sentry.Scope();
14+
customScope.setClient(client);
15+
customScope.update({ user: { username: 'h4cktor' } });
16+
client.init();
17+
18+
async function run(): Promise<void> {
19+
Sentry.logger.info('test info', { foo: 'bar1' }, { scope: customScope });
20+
Sentry.logger.info('test info with {param}', [1], { foo: 'bar2' }, { scope: customScope });
21+
Sentry.logger.info(Sentry.logger.fmt`test info with fm ${1}`, [1], { foo: 'bar3' }, { scope: customScope });
22+
23+
await Sentry.flush();
24+
}
25+
26+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
27+
void run();
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import { afterAll, describe, expect, test } from 'vitest';
2+
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
3+
4+
describe('logger public API', () => {
5+
afterAll(() => {
6+
cleanupChildProcesses();
7+
});
8+
9+
test('captures logs with parameters in different forms', async () => {
10+
const runner = createRunner(__dirname, 'subject.ts')
11+
.expect({
12+
log: {
13+
items: [
14+
{
15+
attributes: {
16+
foo: {
17+
type: 'string',
18+
value: 'bar1',
19+
},
20+
'sentry.sdk.name': {
21+
type: 'string',
22+
value: 'sentry.javascript.node',
23+
},
24+
'sentry.sdk.version': {
25+
type: 'string',
26+
value: expect.any(String),
27+
},
28+
'server.address': {
29+
type: 'string',
30+
value: 'M6QX4Q5HKV.local',
31+
},
32+
'user.name': {
33+
type: 'string',
34+
value: 'h4cktor',
35+
},
36+
},
37+
body: 'test info',
38+
level: 'info',
39+
severity_number: 9,
40+
timestamp: expect.any(Number),
41+
trace_id: expect.stringMatching(/^[\da-f]{32}$/),
42+
},
43+
{
44+
attributes: {
45+
foo: {
46+
type: 'string',
47+
value: 'bar2',
48+
},
49+
'sentry.message.parameter.0': {
50+
type: 'integer',
51+
value: 1,
52+
},
53+
'sentry.message.template': {
54+
type: 'string',
55+
value: 'test info with {param}',
56+
},
57+
'sentry.sdk.name': {
58+
type: 'string',
59+
value: 'sentry.javascript.node',
60+
},
61+
'sentry.sdk.version': {
62+
type: 'string',
63+
value: expect.any(String),
64+
},
65+
'server.address': {
66+
type: 'string',
67+
value: 'M6QX4Q5HKV.local',
68+
},
69+
'user.name': {
70+
type: 'string',
71+
value: 'h4cktor',
72+
},
73+
},
74+
body: 'test info with {param} 1',
75+
level: 'info',
76+
severity_number: 9,
77+
timestamp: expect.any(Number),
78+
trace_id: expect.stringMatching(/^[\da-f]{32}$/),
79+
},
80+
{
81+
attributes: {
82+
foo: {
83+
type: 'string',
84+
value: 'bar3',
85+
},
86+
'sentry.message.parameter.0': {
87+
type: 'integer',
88+
value: 1,
89+
},
90+
'sentry.message.template': {
91+
type: 'string',
92+
value: '"test info with fm 1"',
93+
},
94+
'sentry.sdk.name': {
95+
type: 'string',
96+
value: 'sentry.javascript.node',
97+
},
98+
'sentry.sdk.version': {
99+
type: 'string',
100+
value: expect.any(String),
101+
},
102+
'server.address': {
103+
type: 'string',
104+
value: 'M6QX4Q5HKV.local',
105+
},
106+
'user.name': {
107+
type: 'string',
108+
value: 'h4cktor',
109+
},
110+
},
111+
body: `[String: 'test info with fm 1'] {
112+
__sentry_template_string__: 'test info with fm %s',
113+
__sentry_template_values__: [ 1 ]
114+
} 1`,
115+
level: 'info',
116+
severity_number: 9,
117+
timestamp: expect.any(Number),
118+
trace_id: expect.stringMatching(/^[\da-f]{32}$/),
119+
},
120+
],
121+
},
122+
})
123+
.start();
124+
125+
await runner.completed();
126+
});
127+
});

0 commit comments

Comments
 (0)