Skip to content

Commit bfa9caf

Browse files
committed
fix(core): Add log level only to 4xx/5xx codes
Modify `getBreadcrumbLogLevel` to account only for 4xx or 5xx status. Tests updated to reflect the changes to `getBreadcrumbLogLevel` function. Signed-off-by: Kaung Zin Hein <[email protected]>
1 parent a71e07e commit bfa9caf

File tree

17 files changed

+176
-85
lines changed

17 files changed

+176
-85
lines changed

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/fetch/get/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ sentryTest('captures Breadcrumb for basic GET request', async ({ getLocalTestUrl
3333
status_code: 200,
3434
url: 'http://sentry-test.io/foo',
3535
},
36-
level: 'info',
3736
});
3837
});

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/fetch/getWithRequestObj/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ sentryTest('captures Breadcrumb for basic GET request that uses request object',
3333
status_code: 200,
3434
url: 'http://sentry-test.io/foo',
3535
},
36-
level: 'info',
3736
});
3837
});

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/fetch/post/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ sentryTest('captures Breadcrumb for POST request', async ({ getLocalTestUrl, pag
3333
status_code: 200,
3434
url: 'http://sentry-test.io/foo',
3535
},
36-
level: 'info',
3736
});
3837
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fetch('http://sentry-test.io/foo').then(() => {
2+
Sentry.captureException('test error');
3+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
7+
sentryTest('captures Breadcrumb with log level for 4xx response code', async ({ getLocalTestUrl, page }) => {
8+
const url = await getLocalTestUrl({ testDir: __dirname });
9+
10+
await page.route('**/foo', async route => {
11+
await route.fulfill({
12+
status: 404,
13+
contentType: 'text/plain',
14+
body: 'Not Found!',
15+
});
16+
});
17+
18+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
19+
20+
expect(eventData.exception?.values).toHaveLength(1);
21+
22+
expect(eventData?.breadcrumbs?.length).toBe(1);
23+
expect(eventData!.breadcrumbs![0]).toEqual({
24+
timestamp: expect.any(Number),
25+
category: 'fetch',
26+
type: 'http',
27+
data: {
28+
method: 'GET',
29+
status_code: 404,
30+
url: 'http://sentry-test.io/foo',
31+
},
32+
level: 'warning',
33+
});
34+
35+
await page.route('**/foo', async route => {
36+
await route.fulfill({
37+
status: 500,
38+
contentType: 'text/plain',
39+
body: 'Internal Server Error',
40+
});
41+
});
42+
});
43+
44+
sentryTest('captures Breadcrumb with log level for 5xx response code', async ({ getLocalTestUrl, page }) => {
45+
const url = await getLocalTestUrl({ testDir: __dirname });
46+
47+
await page.route('**/foo', async route => {
48+
await route.fulfill({
49+
status: 500,
50+
contentType: 'text/plain',
51+
body: 'Internal Server Error',
52+
});
53+
});
54+
55+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
56+
57+
expect(eventData.exception?.values).toHaveLength(1);
58+
59+
expect(eventData?.breadcrumbs?.length).toBe(1);
60+
expect(eventData!.breadcrumbs![0]).toEqual({
61+
timestamp: expect.any(Number),
62+
category: 'fetch',
63+
type: 'http',
64+
data: {
65+
method: 'GET',
66+
status_code: 500,
67+
url: 'http://sentry-test.io/foo',
68+
},
69+
level: 'error',
70+
});
71+
});

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/xhr/get/test.ts

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -34,64 +34,5 @@ sentryTest('captures Breadcrumb for basic GET request', async ({ getLocalTestUrl
3434
status_code: 200,
3535
url: 'http://sentry-test.io/foo',
3636
},
37-
level: 'info',
38-
});
39-
});
40-
41-
sentryTest('captures Breadcrumb for GET request with 4xx response code', async ({ getLocalTestUrl, page }) => {
42-
const url = await getLocalTestUrl({ testDir: __dirname });
43-
44-
await page.route('**/foo', async route => {
45-
await route.fulfill({
46-
status: 404,
47-
contentType: 'text/plain',
48-
body: 'Not Found!',
49-
});
50-
});
51-
52-
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
53-
54-
expect(eventData.exception?.values).toHaveLength(1);
55-
56-
expect(eventData?.breadcrumbs?.length).toBe(1);
57-
expect(eventData!.breadcrumbs![0]).toEqual({
58-
timestamp: expect.any(Number),
59-
category: 'xhr',
60-
type: 'http',
61-
data: {
62-
method: 'GET',
63-
status_code: 404,
64-
url: 'http://sentry-test.io/foo',
65-
},
66-
level: 'warning',
67-
});
68-
});
69-
70-
sentryTest('captures Breadcrumb for GET request with 5xx response code', async ({ getLocalTestUrl, page }) => {
71-
const url = await getLocalTestUrl({ testDir: __dirname });
72-
73-
await page.route('**/foo', async route => {
74-
await route.fulfill({
75-
status: 500,
76-
contentType: 'text/plain',
77-
body: 'Internal Server Error',
78-
});
79-
});
80-
81-
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
82-
83-
expect(eventData.exception?.values).toHaveLength(1);
84-
85-
expect(eventData?.breadcrumbs?.length).toBe(1);
86-
expect(eventData!.breadcrumbs![0]).toEqual({
87-
timestamp: expect.any(Number),
88-
category: 'xhr',
89-
type: 'http',
90-
data: {
91-
method: 'GET',
92-
status_code: 500,
93-
url: 'http://sentry-test.io/foo',
94-
},
95-
level: 'error',
9637
});
9738
});

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/xhr/post/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ sentryTest('captures Breadcrumb for POST request', async ({ getLocalTestUrl, pag
3333
status_code: 200,
3434
url: 'http://sentry-test.io/foo',
3535
},
36-
level: 'info',
3736
});
3837
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const xhr = new XMLHttpRequest();
2+
3+
xhr.open('GET', 'http://sentry-test.io/foo');
4+
xhr.send();
5+
6+
xhr.addEventListener('readystatechange', function () {
7+
if (xhr.readyState === 4) {
8+
Sentry.captureException('test error');
9+
}
10+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
7+
sentryTest('captures Breadcrumb with log level for 4xx response code', async ({ getLocalTestUrl, page }) => {
8+
const url = await getLocalTestUrl({ testDir: __dirname });
9+
10+
await page.route('**/foo', async route => {
11+
await route.fulfill({
12+
status: 404,
13+
contentType: 'text/plain',
14+
body: 'Not Found!',
15+
});
16+
});
17+
18+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
19+
20+
expect(eventData.exception?.values).toHaveLength(1);
21+
22+
expect(eventData?.breadcrumbs?.length).toBe(1);
23+
expect(eventData!.breadcrumbs![0]).toEqual({
24+
timestamp: expect.any(Number),
25+
category: 'xhr',
26+
type: 'http',
27+
data: {
28+
method: 'GET',
29+
status_code: 404,
30+
url: 'http://sentry-test.io/foo',
31+
},
32+
level: 'warning',
33+
});
34+
35+
await page.route('**/foo', async route => {
36+
await route.fulfill({
37+
status: 500,
38+
contentType: 'text/plain',
39+
body: 'Internal Server Error',
40+
});
41+
});
42+
});
43+
44+
sentryTest('captures Breadcrumb with log level for 5xx response code', async ({ getLocalTestUrl, page }) => {
45+
const url = await getLocalTestUrl({ testDir: __dirname });
46+
47+
await page.route('**/foo', async route => {
48+
await route.fulfill({
49+
status: 500,
50+
contentType: 'text/plain',
51+
body: 'Internal Server Error',
52+
});
53+
});
54+
55+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
56+
57+
expect(eventData.exception?.values).toHaveLength(1);
58+
59+
expect(eventData?.breadcrumbs?.length).toBe(1);
60+
expect(eventData!.breadcrumbs![0]).toEqual({
61+
timestamp: expect.any(Number),
62+
category: 'xhr',
63+
type: 'http',
64+
data: {
65+
method: 'GET',
66+
status_code: 500,
67+
url: 'http://sentry-test.io/foo',
68+
},
69+
level: 'error',
70+
});
71+
});

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function _getXhrBreadcrumbHandler(client: Client): (handlerData: HandlerDataXhr)
254254
category: 'xhr',
255255
data,
256256
type: 'http',
257-
level,
257+
...level,
258258
},
259259
hint,
260260
);
@@ -319,7 +319,7 @@ function _getFetchBreadcrumbHandler(client: Client): (handlerData: HandlerDataFe
319319
category: 'fetch',
320320
data,
321321
type: 'http',
322-
level,
322+
...level,
323323
},
324324
hint,
325325
);

0 commit comments

Comments
 (0)