
Research
/Security News
TensorLake npm SDK Compromised in ChainDrop Shai-Hulud Credential-Stealing Attack
Tensorlake npm SDK version 0.5.144 was compromised in a ChainDrop / Shai-Hulud attack, delivering credential-stealing malware.
@sentry/cloudflare
Advanced tools
To get started, first install the @sentry/cloudflare package:
npm install @sentry/cloudflare
Then set the nodejs_compat compatibility flag in your wrangler.jsonc/wrangler.toml config. This is because the SDK needs access to Node.js compatibility APIs to work correctly.
{
"compatibility_flags": ["nodejs_compat"],
}
compatibility_flags = ["nodejs_compat"]
To use this SDK, add the sentryPagesPlugin as
middleware to your Cloudflare Pages application.
We recommend adding a functions/_middleware.js for the middleware setup so that Sentry is initialized for your entire
app.
// functions/_middleware.js
import * as Sentry from '@sentry/cloudflare';
export const onRequest = Sentry.sentryPagesPlugin({
dsn: process.env.SENTRY_DSN,
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
tracesSampleRate: 1.0,
});
If you need to to chain multiple middlewares, you can do so by exporting an array of middlewares. Make sure the Sentry middleware is the first one in the array.
import * as Sentry from '@sentry/cloudflare';
export const onRequest = [
// Make sure Sentry is the first middleware
Sentry.sentryPagesPlugin({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
}),
// Add more middlewares here
];
If you need to access the context object (for example to grab environmental variables), you can pass a function to
sentryPagesPlugin that takes the context object as an argument and returns init options:
export const onRequest = Sentry.sentryPagesPlugin(context => ({
dsn: context.env.SENTRY_DSN,
tracesSampleRate: 1.0,
}));
If you do not have access to the onRequest middleware API, you can use the wrapRequestHandler API instead.
Here is an example with SvelteKit:
// hooks.server.js
import * as Sentry from '@sentry/cloudflare';
export const handle = ({ event, resolve }) => {
const requestHandlerOptions = {
options: {
dsn: event.platform.env.SENTRY_DSN,
tracesSampleRate: 1.0,
},
request: event.request,
context: event.platform.ctx,
};
return Sentry.wrapRequestHandler(requestHandlerOptions, () => resolve(event));
};
To use this SDK, wrap your handler with the withSentry function. This will initialize the SDK and hook into the
environment. Note that you can turn off almost all side effects using the respective options.
Currently only ESM handlers are supported.
import * as Sentry from '@sentry/cloudflare';
export default withSentry(
env => ({
dsn: env.SENTRY_DSN,
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
tracesSampleRate: 1.0,
}),
{
async fetch(request, env, ctx) {
return new Response('Hello World!');
},
} satisfies ExportedHandler<Env>,
);
Configure uploading sourcemaps via the Sentry Wizard:
npx @sentry/wizard@latest -i sourcemaps
See more details in our docs.
To set context information or send manual events, use the exported functions of @sentry/cloudflare. Note that these
functions will require the usage of the Sentry helpers, either withSentry function for Cloudflare Workers or the
sentryPagesPlugin middleware for Cloudflare Pages.
import * as Sentry from '@sentry/cloudflare';
// Set user information, as well as tags and further extras
Sentry.setExtra('battery', 0.7);
Sentry.setTag('user_mode', 'admin');
Sentry.setUser({ id: '4711' });
// Add a breadcrumb for future events
Sentry.addBreadcrumb({
message: 'My Breadcrumb',
// ...
});
// Capture exceptions, messages or manual events
Sentry.captureMessage('Hello, world!');
Sentry.captureException(new Error('Good bye'));
Sentry.captureEvent({
message: 'Manual',
stacktrace: [
// ...
],
});
withSentry() automatically instruments all Cloudflare D1 bindings on env,
Cloudflare's serverless SQL database. Just use the binding as usual:
// env.DB is the D1 DB binding configured in your `wrangler.toml`
await env.DB.prepare('SELECT * FROM table WHERE id = ?').bind(1).run();
Sentry Crons allows you to monitor the uptime and performance of any scheduled, recurring job in your application.
To instrument your cron triggers, use the Sentry.withMonitor API in your
Scheduled handler.
export default {
async scheduled(event, env, ctx) {
ctx.waitUntil(
Sentry.withMonitor('your-cron-name', () => {
return doSomeTaskOnASchedule();
}),
);
},
};
You can also use supply a monitor config to upsert cron monitors with additional metadata:
const monitorConfig = {
schedule: {
type: 'crontab',
value: '* * * * *',
},
checkinMargin: 2, // In minutes. Optional.
maxRuntime: 10, // In minutes. Optional.
timezone: 'America/Los_Angeles', // Optional.
};
export default {
async scheduled(event, env, ctx) {
Sentry.withMonitor('your-cron-name', () => doSomeTaskOnASchedule(), monitorConfig);
},
};
FAQs
Official Sentry SDK for Cloudflare Workers and Pages
The npm package @sentry/cloudflare receives a total of 1,193,177 weekly downloads. As such, @sentry/cloudflare popularity was classified as popular.
We found that @sentry/cloudflare demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Research
/Security News
Tensorlake npm SDK version 0.5.144 was compromised in a ChainDrop / Shai-Hulud attack, delivering credential-stealing malware.

Research
/Security News
Socket found 16 malicious Firefox extensions designed to steal crypto wallet recovery phrases and private keys using cloned Rabby and OKX interfaces.

Product
Socket now scans VS Code extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.