Skip to content

Commit b13bc51

Browse files
committed
feat(cloudflare): Add console integration
1 parent 56aac53 commit b13bc51

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {
2+
addBreadcrumb,
3+
addConsoleInstrumentationHandler,
4+
defineIntegration,
5+
getClient,
6+
safeJoin,
7+
severityLevelFromString,
8+
} from '@sentry/core';
9+
10+
const INTEGRATION_NAME = 'Console';
11+
12+
/**
13+
* Capture console logs as breadcrumbs. Enabled by default in the Cloudflare SDK.
14+
*/
15+
export const consoleIntegration = defineIntegration(() => {
16+
return {
17+
name: INTEGRATION_NAME,
18+
setup(client) {
19+
addConsoleInstrumentationHandler(({ args, level }) => {
20+
if (getClient() !== client) {
21+
return;
22+
}
23+
24+
addBreadcrumb(
25+
{
26+
category: 'console',
27+
level: severityLevelFromString(level),
28+
message: safeJoin(args, ' '),
29+
},
30+
{
31+
input: [...args],
32+
level,
33+
},
34+
);
35+
});
36+
},
37+
};
38+
});

packages/cloudflare/src/sdk.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { CloudflareClient } from './client';
1414
import { fetchIntegration } from './integrations/fetch';
1515
import { makeCloudflareTransport } from './transport';
1616
import { defaultStackParser } from './vendor/stacktrace';
17+
import { consoleIntegration } from './integrations/console';
1718

1819
/** Get the default integrations for the Cloudflare SDK. */
1920
export function getDefaultIntegrations(options: CloudflareOptions): Integration[] {
@@ -27,6 +28,7 @@ export function getDefaultIntegrations(options: CloudflareOptions): Integration[
2728
linkedErrorsIntegration(),
2829
fetchIntegration(),
2930
requestDataIntegration(sendDefaultPii ? undefined : { include: { cookies: false } }),
31+
consoleIntegration(),
3032
];
3133
}
3234

0 commit comments

Comments
 (0)