Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/cloudflare/src/integrations/console.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
addBreadcrumb,
addConsoleInstrumentationHandler,
defineIntegration,
getClient,
safeJoin,
severityLevelFromString,
} from '@sentry/core';

const INTEGRATION_NAME = 'Console';

/**
* Capture console logs as breadcrumbs. Enabled by default in the Cloudflare SDK.
*/
export const consoleIntegration = defineIntegration(() => {
return {
name: INTEGRATION_NAME,
setup(client) {
addConsoleInstrumentationHandler(({ args, level }) => {
if (getClient() !== client) {
return;
}

addBreadcrumb(
{
category: 'console',
level: severityLevelFromString(level),
message: safeJoin(args, ' '),
},
{
input: [...args],
level,
},
);
});
},
};
});
2 changes: 2 additions & 0 deletions packages/cloudflare/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { CloudflareClient } from './client';
import { fetchIntegration } from './integrations/fetch';
import { makeCloudflareTransport } from './transport';
import { defaultStackParser } from './vendor/stacktrace';
import { consoleIntegration } from './integrations/console';

/** Get the default integrations for the Cloudflare SDK. */
export function getDefaultIntegrations(options: CloudflareOptions): Integration[] {
Expand All @@ -27,6 +28,7 @@ export function getDefaultIntegrations(options: CloudflareOptions): Integration[
linkedErrorsIntegration(),
fetchIntegration(),
requestDataIntegration(sendDefaultPii ? undefined : { include: { cookies: false } }),
consoleIntegration(),
];
}

Expand Down
Loading