Skip to content

Commit e69c2d9

Browse files
committed
add node integration tests
1 parent 89c5c2e commit e69c2d9

File tree

4 files changed

+362
-1
lines changed

4 files changed

+362
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
2+
import * as Sentry from '@sentry/node';
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
environment: 'test',
8+
_experiments: {
9+
enableLogs: true,
10+
},
11+
transport: loggingTransport,
12+
});
13+
14+
async function run(): Promise<void> {
15+
Sentry.logger.trace('test trace');
16+
Sentry.logger.debug('test debug');
17+
Sentry.logger.info('test info');
18+
Sentry.logger.warn('test warn');
19+
Sentry.logger.error('test error');
20+
Sentry.logger.fatal('test fatal');
21+
22+
const formattedMessage = (
23+
message: string,
24+
stringArg: string,
25+
boolArg: boolean,
26+
numberArg: number,
27+
): ReturnType<typeof Sentry.logger.fmt> => {
28+
return Sentry.logger.fmt`test ${message} ${stringArg} ${boolArg} ${numberArg}`;
29+
};
30+
31+
Sentry.logger.trace(formattedMessage('trace', 'stringArg', false, 123));
32+
Sentry.logger.debug(formattedMessage('debug', 'stringArg', false, 123));
33+
Sentry.logger.info(formattedMessage('info', 'stringArg', false, 123));
34+
Sentry.logger.warn(formattedMessage('warn', 'stringArg', false, 123));
35+
Sentry.logger.error(formattedMessage('error', 'stringArg', false, 123));
36+
Sentry.logger.fatal(formattedMessage('fatal', 'stringArg', false, 123));
37+
38+
Sentry.logger.trace('test %s with node format', ['trace']);
39+
Sentry.logger.debug('test %s with node format', ['debug']);
40+
Sentry.logger.info('test %s with node format', ['info']);
41+
Sentry.logger.warn('test %s with node format', ['warn']);
42+
Sentry.logger.error('test %s with node format', ['error']);
43+
Sentry.logger.fatal('test %s with node format', ['fatal']);
44+
45+
await Sentry.flush();
46+
}
47+
48+
run().catch(() => undefined);
Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
import { afterAll, expect, test } from 'vitest';
2+
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
3+
4+
afterAll(() => {
5+
cleanupChildProcesses();
6+
});
7+
8+
test('should log messages with different levels and formats', async () => {
9+
await createRunner(__dirname, 'scenario.ts')
10+
.expect({
11+
otel_log: {
12+
severityText: 'trace',
13+
severityNumber: 1, // TRACE
14+
body: {
15+
stringValue: 'test trace',
16+
},
17+
attributes: [
18+
{ key: 'release', value: { stringValue: '1.0' } },
19+
{ key: 'environment', value: { stringValue: 'test' } },
20+
],
21+
},
22+
})
23+
.expect({
24+
otel_log: {
25+
severityText: 'debug',
26+
severityNumber: 5, // DEBUG
27+
body: {
28+
stringValue: 'test debug',
29+
},
30+
attributes: [
31+
{ key: 'release', value: { stringValue: '1.0' } },
32+
{ key: 'environment', value: { stringValue: 'test' } },
33+
],
34+
},
35+
})
36+
.expect({
37+
otel_log: {
38+
severityText: 'info',
39+
severityNumber: 9, // INFO
40+
body: {
41+
stringValue: 'test info',
42+
},
43+
attributes: [
44+
{ key: 'release', value: { stringValue: '1.0' } },
45+
{ key: 'environment', value: { stringValue: 'test' } },
46+
],
47+
},
48+
})
49+
.expect({
50+
otel_log: {
51+
severityText: 'warn',
52+
severityNumber: 13, // WARN
53+
body: {
54+
stringValue: 'test warn',
55+
},
56+
attributes: [
57+
{ key: 'release', value: { stringValue: '1.0' } },
58+
{ key: 'environment', value: { stringValue: 'test' } },
59+
],
60+
},
61+
})
62+
.expect({
63+
otel_log: {
64+
severityText: 'error',
65+
severityNumber: 17, // ERROR
66+
body: {
67+
stringValue: 'test error',
68+
},
69+
attributes: [
70+
{ key: 'release', value: { stringValue: '1.0' } },
71+
{ key: 'environment', value: { stringValue: 'test' } },
72+
],
73+
},
74+
})
75+
.expect({
76+
otel_log: {
77+
severityText: 'fatal',
78+
severityNumber: 21, // FATAL
79+
body: {
80+
stringValue: 'test fatal',
81+
},
82+
attributes: [
83+
{ key: 'release', value: { stringValue: '1.0' } },
84+
{ key: 'environment', value: { stringValue: 'test' } },
85+
],
86+
},
87+
})
88+
.expect({
89+
otel_log: {
90+
severityText: 'trace',
91+
severityNumber: 1, // TRACE
92+
body: {
93+
stringValue: 'test trace stringArg false 123',
94+
},
95+
attributes: [
96+
{ key: 'release', value: { stringValue: '1.0' } },
97+
{ key: 'environment', value: { stringValue: 'test' } },
98+
{ key: 'sentry.message.template', value: { stringValue: 'test %s %s %s %s' } },
99+
{ key: 'sentry.message.param.0', value: { stringValue: 'trace' } },
100+
{ key: 'sentry.message.param.1', value: { stringValue: 'stringArg' } },
101+
{ key: 'sentry.message.param.2', value: { boolValue: false } },
102+
{ key: 'sentry.message.param.3', value: { doubleValue: 123 } },
103+
],
104+
},
105+
})
106+
.expect({
107+
otel_log: {
108+
severityText: 'debug',
109+
severityNumber: 5, // DEBUG
110+
body: {
111+
stringValue: 'test debug stringArg false 123',
112+
},
113+
attributes: [
114+
{ key: 'release', value: { stringValue: '1.0' } },
115+
{ key: 'environment', value: { stringValue: 'test' } },
116+
{ key: 'sentry.message.template', value: { stringValue: 'test %s %s %s %s' } },
117+
{ key: 'sentry.message.param.0', value: { stringValue: 'debug' } },
118+
{ key: 'sentry.message.param.1', value: { stringValue: 'stringArg' } },
119+
{ key: 'sentry.message.param.2', value: { boolValue: false } },
120+
{ key: 'sentry.message.param.3', value: { doubleValue: 123 } },
121+
],
122+
},
123+
})
124+
.expect({
125+
otel_log: {
126+
severityText: 'info',
127+
severityNumber: 9, // INFO
128+
body: {
129+
stringValue: 'test info stringArg false 123',
130+
},
131+
attributes: [
132+
{ key: 'release', value: { stringValue: '1.0' } },
133+
{ key: 'environment', value: { stringValue: 'test' } },
134+
{ key: 'sentry.message.template', value: { stringValue: 'test %s %s %s %s' } },
135+
{ key: 'sentry.message.param.0', value: { stringValue: 'info' } },
136+
{ key: 'sentry.message.param.1', value: { stringValue: 'stringArg' } },
137+
{ key: 'sentry.message.param.2', value: { boolValue: false } },
138+
{ key: 'sentry.message.param.3', value: { doubleValue: 123 } },
139+
],
140+
},
141+
})
142+
.expect({
143+
otel_log: {
144+
severityText: 'warn',
145+
severityNumber: 13, // WARN
146+
body: {
147+
stringValue: 'test warn stringArg false 123',
148+
},
149+
attributes: [
150+
{ key: 'release', value: { stringValue: '1.0' } },
151+
{ key: 'environment', value: { stringValue: 'test' } },
152+
{ key: 'sentry.message.template', value: { stringValue: 'test %s %s %s %s' } },
153+
{ key: 'sentry.message.param.0', value: { stringValue: 'warn' } },
154+
{ key: 'sentry.message.param.1', value: { stringValue: 'stringArg' } },
155+
{ key: 'sentry.message.param.2', value: { boolValue: false } },
156+
{ key: 'sentry.message.param.3', value: { doubleValue: 123 } },
157+
],
158+
},
159+
})
160+
.expect({
161+
otel_log: {
162+
severityText: 'error',
163+
severityNumber: 17, // ERROR
164+
body: {
165+
stringValue: 'test error stringArg false 123',
166+
},
167+
attributes: [
168+
{ key: 'release', value: { stringValue: '1.0' } },
169+
{ key: 'environment', value: { stringValue: 'test' } },
170+
{ key: 'sentry.message.template', value: { stringValue: 'test %s %s %s %s' } },
171+
{ key: 'sentry.message.param.0', value: { stringValue: 'error' } },
172+
{ key: 'sentry.message.param.1', value: { stringValue: 'stringArg' } },
173+
{ key: 'sentry.message.param.2', value: { boolValue: false } },
174+
{ key: 'sentry.message.param.3', value: { doubleValue: 123 } },
175+
],
176+
},
177+
})
178+
.expect({
179+
otel_log: {
180+
severityText: 'fatal',
181+
severityNumber: 21, // FATAL
182+
body: {
183+
stringValue: 'test fatal stringArg false 123',
184+
},
185+
attributes: [
186+
{ key: 'release', value: { stringValue: '1.0' } },
187+
{ key: 'environment', value: { stringValue: 'test' } },
188+
{ key: 'sentry.message.template', value: { stringValue: 'test %s %s %s %s' } },
189+
{ key: 'sentry.message.param.0', value: { stringValue: 'fatal' } },
190+
{ key: 'sentry.message.param.1', value: { stringValue: 'stringArg' } },
191+
{ key: 'sentry.message.param.2', value: { boolValue: false } },
192+
{ key: 'sentry.message.param.3', value: { doubleValue: 123 } },
193+
],
194+
},
195+
})
196+
.expect({
197+
otel_log: {
198+
severityText: 'trace',
199+
severityNumber: 1, // TRACE
200+
body: {
201+
stringValue: 'test trace with node format',
202+
},
203+
attributes: [
204+
{ key: 'sentry.message.template', value: { stringValue: 'test %s with node format' } },
205+
{ key: 'sentry.message.param.0', value: { stringValue: 'trace' } },
206+
{ key: 'release', value: { stringValue: '1.0' } },
207+
{ key: 'environment', value: { stringValue: 'test' } },
208+
],
209+
},
210+
})
211+
.expect({
212+
otel_log: {
213+
severityText: 'debug',
214+
severityNumber: 5, // DEBUG
215+
body: {
216+
stringValue: 'test debug with node format',
217+
},
218+
attributes: [
219+
{ key: 'sentry.message.template', value: { stringValue: 'test %s with node format' } },
220+
{ key: 'sentry.message.param.0', value: { stringValue: 'debug' } },
221+
{ key: 'release', value: { stringValue: '1.0' } },
222+
{ key: 'environment', value: { stringValue: 'test' } },
223+
],
224+
},
225+
})
226+
.expect({
227+
otel_log: {
228+
severityText: 'info',
229+
severityNumber: 9, // INFO
230+
body: {
231+
stringValue: 'test info with node format',
232+
},
233+
attributes: [
234+
{ key: 'sentry.message.template', value: { stringValue: 'test %s with node format' } },
235+
{ key: 'sentry.message.param.0', value: { stringValue: 'info' } },
236+
{ key: 'release', value: { stringValue: '1.0' } },
237+
{ key: 'environment', value: { stringValue: 'test' } },
238+
],
239+
},
240+
})
241+
.expect({
242+
otel_log: {
243+
severityText: 'warn',
244+
severityNumber: 13, // WARN
245+
body: {
246+
stringValue: 'test warn with node format',
247+
},
248+
attributes: [
249+
{ key: 'sentry.message.template', value: { stringValue: 'test %s with node format' } },
250+
{ key: 'sentry.message.param.0', value: { stringValue: 'warn' } },
251+
{ key: 'release', value: { stringValue: '1.0' } },
252+
{ key: 'environment', value: { stringValue: 'test' } },
253+
],
254+
},
255+
})
256+
.expect({
257+
otel_log: {
258+
severityText: 'error',
259+
severityNumber: 17, // ERROR
260+
body: {
261+
stringValue: 'test error with node format',
262+
},
263+
attributes: [
264+
{ key: 'sentry.message.template', value: { stringValue: 'test %s with node format' } },
265+
{ key: 'sentry.message.param.0', value: { stringValue: 'error' } },
266+
{ key: 'release', value: { stringValue: '1.0' } },
267+
{ key: 'environment', value: { stringValue: 'test' } },
268+
],
269+
},
270+
})
271+
.expect({
272+
otel_log: {
273+
severityText: 'fatal',
274+
severityNumber: 21, // FATAL
275+
body: {
276+
stringValue: 'test fatal with node format',
277+
},
278+
attributes: [
279+
{ key: 'sentry.message.template', value: { stringValue: 'test %s with node format' } },
280+
{ key: 'sentry.message.param.0', value: { stringValue: 'fatal' } },
281+
{ key: 'release', value: { stringValue: '1.0' } },
282+
{ key: 'environment', value: { stringValue: 'test' } },
283+
],
284+
},
285+
})
286+
.start()
287+
.completed();
288+
});

dev-packages/node-integration-tests/utils/assertions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
Envelope,
55
Event,
66
SerializedCheckIn,
7+
SerializedOtelLog,
78
SerializedSession,
89
SessionAggregates,
910
TransactionEvent,
@@ -66,6 +67,12 @@ export function assertSentryClientReport(actual: ClientReport, expected: Partial
6667
});
6768
}
6869

70+
export function assertSentryOtelLog(actual: SerializedOtelLog, expected: Partial<SerializedOtelLog>): void {
71+
expect(actual).toMatchObject({
72+
...expected,
73+
});
74+
}
75+
6976
export function assertEnvelopeHeader(actual: Envelope[0], expected: Partial<Envelope[0]>): void {
7077
expect(actual).toEqual({
7178
event_id: expect.any(String),

0 commit comments

Comments
 (0)