Skip to content

Commit b97b3f4

Browse files
committed
add browser integration test
1 parent 6d0c6bd commit b97b3f4

File tree

2 files changed

+132
-0
lines changed
  • dev-packages/browser-integration-tests/suites/public-api/logger/scopeAttributes

2 files changed

+132
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// only log attribute
2+
Sentry.logger.info('log_before_any_scope', { log_attr: 'scope_attr_1' });
3+
4+
Sentry.getGlobalScope().setAttribute('global_scope_attr', true);
5+
6+
// global scope, log attribute
7+
Sentry.logger.info('log_after_global_scope', { log_attr: 'scope_attr_2' });
8+
9+
let isolScope = null;
10+
let isolScope2 = null;
11+
12+
Sentry.withIsolationScope(isolationScope => {
13+
isolScope = isolationScope;
14+
isolationScope.setAttribute('isolation_scope_1_attr', { value: 100, unit: 'ms' });
15+
16+
// global scope, isolation scope, log attribute
17+
Sentry.logger.info('log_with_isolation_scope', { log_attr: 'scope_attr_3' });
18+
19+
Sentry.withScope(scope => {
20+
scope.setAttribute('scope_attr', { value: 200, unit: 'ms' });
21+
22+
// global scope, isolation scope, current scope attribute, log attribute
23+
Sentry.logger.info('log_with_scope', { log_attr: 'scope_attr_4' });
24+
});
25+
26+
Sentry.withScope(scope2 => {
27+
scope2.setAttribute('scope_2_attr', { value: 300, unit: 'ms' });
28+
29+
// global scope, isolation scope, current scope attribute, log attribute
30+
Sentry.logger.info('log_with_scope_2', { log_attr: 'scope_attr_5' });
31+
});
32+
});
33+
34+
Sentry.flush();
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { expect } from '@playwright/test';
2+
import type { LogEnvelope } from '@sentry/core';
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getFirstSentryEnvelopeRequest, properFullEnvelopeRequestParser } from '../../../../utils/helpers';
5+
6+
sentryTest('captures logs with scope attributes', async ({ getLocalTestUrl, page }) => {
7+
const bundle = process.env.PW_BUNDLE || '';
8+
// Only run this for npm package exports
9+
if (bundle.startsWith('bundle') || bundle.startsWith('loader')) {
10+
sentryTest.skip();
11+
}
12+
13+
const url = await getLocalTestUrl({ testDir: __dirname });
14+
15+
const event = await getFirstSentryEnvelopeRequest<LogEnvelope>(page, url, properFullEnvelopeRequestParser);
16+
const envelopeItems = event[1];
17+
18+
expect(envelopeItems[0]).toEqual([
19+
{
20+
type: 'log',
21+
item_count: 5,
22+
content_type: 'application/vnd.sentry.items.log+json',
23+
},
24+
{
25+
items: [
26+
{
27+
timestamp: expect.any(Number),
28+
level: 'info',
29+
body: 'log_before_any_scope',
30+
severity_number: 9,
31+
trace_id: expect.any(String),
32+
attributes: {
33+
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
34+
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
35+
log_attr: { value: 'scope_attr_1', type: 'string' },
36+
},
37+
},
38+
{
39+
timestamp: expect.any(Number),
40+
level: 'info',
41+
body: 'log_after_global_scope',
42+
severity_number: 9,
43+
trace_id: expect.any(String),
44+
attributes: {
45+
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
46+
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
47+
global_scope_attr: { value: true, type: 'boolean' },
48+
log_attr: { value: 'scope_attr_2', type: 'string' },
49+
},
50+
},
51+
{
52+
timestamp: expect.any(Number),
53+
level: 'info',
54+
body: 'log_with_isolation_scope',
55+
severity_number: 9,
56+
trace_id: expect.any(String),
57+
attributes: {
58+
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
59+
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
60+
global_scope_attr: { value: true, type: 'boolean' },
61+
isolation_scope_1_attr: { value: 100, unit: 'ms', type: 'integer' },
62+
log_attr: { value: 'scope_attr_3', type: 'string' },
63+
},
64+
},
65+
{
66+
timestamp: expect.any(Number),
67+
level: 'info',
68+
body: 'log_with_scope',
69+
severity_number: 9,
70+
trace_id: expect.any(String),
71+
attributes: {
72+
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
73+
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
74+
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' },
77+
log_attr: { value: 'scope_attr_4', type: 'string' },
78+
},
79+
},
80+
{
81+
timestamp: expect.any(Number),
82+
level: 'info',
83+
body: 'log_with_scope_2',
84+
severity_number: 9,
85+
trace_id: expect.any(String),
86+
attributes: {
87+
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
88+
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
89+
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' },
92+
log_attr: { value: 'scope_attr_5', type: 'string' },
93+
},
94+
},
95+
],
96+
},
97+
]);
98+
});

0 commit comments

Comments
 (0)