Skip to content

Commit 5053159

Browse files
committed
add node integration test
1 parent f4e19a2 commit 5053159

File tree

4 files changed

+164
-9
lines changed

4 files changed

+164
-9
lines changed

dev-packages/browser-integration-tests/suites/public-api/logger/scopeAttributes/subject.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
// only log attribute
22
Sentry.logger.info('log_before_any_scope', { log_attr: 'log_attr_1' });
33

4-
Sentry.getGlobalScope().setAttribute('global_scope_attr', true);
4+
Sentry.getGlobalScope().setAttributes({ global_scope_attr: true });
55

66
// global scope, log attribute
77
Sentry.logger.info('log_after_global_scope', { log_attr: 'log_attr_2' });
88

99
Sentry.withIsolationScope(isolationScope => {
10-
isolationScope.setAttribute('isolation_scope_1_attr', { value: 100, unit: 'ms' });
10+
isolationScope.setAttribute('isolation_scope_1_attr', { value: 100, unit: 'millisecond' });
1111

1212
// global scope, isolation scope, log attribute
1313
Sentry.logger.info('log_with_isolation_scope', { log_attr: 'log_attr_3' });
1414

1515
Sentry.withScope(scope => {
16-
scope.setAttribute('scope_attr', { value: 200, unit: 'ms' });
16+
scope.setAttributes({ scope_attr: { value: 200, unit: 'millisecond' } });
1717

1818
// global scope, isolation scope, current scope attribute, log attribute
1919
Sentry.logger.info('log_with_scope', { log_attr: 'log_attr_4' });
2020
});
2121

2222
Sentry.withScope(scope2 => {
23-
scope2.setAttribute('scope_2_attr', { value: 300, unit: 'ms' });
23+
scope2.setAttribute('scope_2_attr', { value: 300, unit: 'millisecond' });
2424

2525
// global scope, isolation scope, current scope attribute, log attribute
2626
Sentry.logger.info('log_with_scope_2', { log_attr: 'log_attr_5' });

dev-packages/browser-integration-tests/suites/public-api/logger/scopeAttributes/test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ sentryTest('captures logs with scope attributes', async ({ getLocalTestUrl, page
5858
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
5959
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
6060
global_scope_attr: { value: true, type: 'boolean' },
61-
isolation_scope_1_attr: { value: 100, unit: 'ms', type: 'integer' },
61+
isolation_scope_1_attr: { value: 100, unit: 'millisecond', type: 'integer' },
6262
log_attr: { value: 'log_attr_3', type: 'string' },
6363
},
6464
},
@@ -72,8 +72,8 @@ sentryTest('captures logs with scope attributes', async ({ getLocalTestUrl, page
7272
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
7373
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
7474
global_scope_attr: { value: true, type: 'boolean' },
75-
isolation_scope_1_attr: { value: 100, unit: 'ms', type: 'integer' },
76-
scope_attr: { value: 200, unit: 'ms', type: 'integer' },
75+
isolation_scope_1_attr: { value: 100, unit: 'millisecond', type: 'integer' },
76+
scope_attr: { value: 200, unit: 'millisecond', type: 'integer' },
7777
log_attr: { value: 'log_attr_4', type: 'string' },
7878
},
7979
},
@@ -87,8 +87,8 @@ sentryTest('captures logs with scope attributes', async ({ getLocalTestUrl, page
8787
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
8888
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
8989
global_scope_attr: { value: true, type: 'boolean' },
90-
isolation_scope_1_attr: { value: 100, unit: 'ms', type: 'integer' },
91-
scope_2_attr: { value: 300, unit: 'ms', type: 'integer' },
90+
isolation_scope_1_attr: { value: 100, unit: 'millisecond', type: 'integer' },
91+
scope_2_attr: { value: 300, unit: 'millisecond', type: 'integer' },
9292
log_attr: { value: 'log_attr_5', type: 'string' },
9393
},
9494
},
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as Sentry from '@sentry/node';
2+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
release: '1.0.0',
7+
environment: 'test',
8+
enableLogs: true,
9+
transport: loggingTransport,
10+
});
11+
12+
async function run(): Promise<void> {
13+
// only log attribute
14+
Sentry.logger.info('log_before_any_scope', { log_attr: 'log_attr_1' });
15+
16+
Sentry.getGlobalScope().setAttribute('global_scope_attr', true);
17+
18+
// global scope, log attribute
19+
Sentry.logger.info('log_after_global_scope', { log_attr: 'log_attr_2' });
20+
21+
Sentry.withIsolationScope(isolationScope => {
22+
isolationScope.setAttribute('isolation_scope_1_attr', { value: 100, unit: 'millisecond' });
23+
24+
// global scope, isolation scope, log attribute
25+
Sentry.logger.info('log_with_isolation_scope', { log_attr: 'log_attr_3' });
26+
27+
Sentry.withScope(scope => {
28+
scope.setAttribute('scope_attr', { value: 200, unit: 'millisecond' });
29+
30+
// global scope, isolation scope, current scope attribute, log attribute
31+
Sentry.logger.info('log_with_scope', { log_attr: 'log_attr_4' });
32+
});
33+
34+
Sentry.withScope(scope2 => {
35+
scope2.setAttribute('scope_2_attr', { value: 300, unit: 'millisecond' });
36+
37+
// global scope, isolation scope, current scope attribute, log attribute
38+
Sentry.logger.info('log_with_scope_2', { log_attr: 'log_attr_5' });
39+
});
40+
});
41+
42+
await Sentry.flush();
43+
}
44+
45+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
46+
run();
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import type { SerializedLog } from '@sentry/core';
2+
import { afterAll, describe, expect, test } from 'vitest';
3+
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
4+
5+
const commonAttributes: SerializedLog['attributes'] = {
6+
'sentry.environment': {
7+
type: 'string',
8+
value: 'test',
9+
},
10+
'sentry.release': {
11+
type: 'string',
12+
value: '1.0.0',
13+
},
14+
'sentry.sdk.name': {
15+
type: 'string',
16+
value: 'sentry.javascript.node',
17+
},
18+
'sentry.sdk.version': {
19+
type: 'string',
20+
value: expect.any(String),
21+
},
22+
'server.address': {
23+
type: 'string',
24+
value: expect.any(String),
25+
},
26+
};
27+
28+
describe('metrics', () => {
29+
afterAll(() => {
30+
cleanupChildProcesses();
31+
});
32+
33+
test('should capture all metric types', async () => {
34+
const runner = createRunner(__dirname, 'scenario.ts')
35+
.expect({
36+
log: {
37+
items: [
38+
{
39+
timestamp: expect.any(Number),
40+
level: 'info',
41+
body: 'log_before_any_scope',
42+
severity_number: 9,
43+
trace_id: expect.any(String),
44+
attributes: {
45+
...commonAttributes,
46+
log_attr: { value: 'log_attr_1', type: 'string' },
47+
},
48+
},
49+
{
50+
timestamp: expect.any(Number),
51+
level: 'info',
52+
body: 'log_after_global_scope',
53+
severity_number: 9,
54+
trace_id: expect.any(String),
55+
attributes: {
56+
...commonAttributes,
57+
global_scope_attr: { value: true, type: 'boolean' },
58+
log_attr: { value: 'log_attr_2', type: 'string' },
59+
},
60+
},
61+
{
62+
timestamp: expect.any(Number),
63+
level: 'info',
64+
body: 'log_with_isolation_scope',
65+
severity_number: 9,
66+
trace_id: expect.any(String),
67+
attributes: {
68+
...commonAttributes,
69+
global_scope_attr: { value: true, type: 'boolean' },
70+
isolation_scope_1_attr: { value: 100, unit: 'millisecond', type: 'integer' },
71+
log_attr: { value: 'log_attr_3', type: 'string' },
72+
},
73+
},
74+
{
75+
timestamp: expect.any(Number),
76+
level: 'info',
77+
body: 'log_with_scope',
78+
severity_number: 9,
79+
trace_id: expect.any(String),
80+
attributes: {
81+
...commonAttributes,
82+
global_scope_attr: { value: true, type: 'boolean' },
83+
isolation_scope_1_attr: { value: 100, unit: 'millisecond', type: 'integer' },
84+
scope_attr: { value: 200, unit: 'millisecond', type: 'integer' },
85+
log_attr: { value: 'log_attr_4', type: 'string' },
86+
},
87+
},
88+
{
89+
timestamp: expect.any(Number),
90+
level: 'info',
91+
body: 'log_with_scope_2',
92+
severity_number: 9,
93+
trace_id: expect.any(String),
94+
attributes: {
95+
...commonAttributes,
96+
global_scope_attr: { value: true, type: 'boolean' },
97+
isolation_scope_1_attr: { value: 100, unit: 'millisecond', type: 'integer' },
98+
scope_2_attr: { value: 300, unit: 'millisecond', type: 'integer' },
99+
log_attr: { value: 'log_attr_5', type: 'string' },
100+
},
101+
},
102+
],
103+
},
104+
})
105+
.start();
106+
107+
await runner.completed();
108+
});
109+
});

0 commit comments

Comments
 (0)