Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issuesI have reviewed the documentation https://docs.sentry.io/I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/cloudflare
SDK Version
9.11.0
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
import { DurableObject } from "cloudflare:workers";
import * as Sentry from '@sentry/cloudflare';
// Worker with Sentry wrapper
export default Sentry.withSentry(
env => ({
dsn: env.SENTRY_DSN,
}),
{
async fetch(request, env, ctx) {
// Handle WebSocket requests
if (request.url.includes("/websocket")) {
// Get DO stub
const id = env.WEBSOCKET_SERVER.idFromName("user-id");
const stub = env.WEBSOCKET_SERVER.get(id);
// Forward to DO
return await stub.fetch(request);
}
return new Response("Not a WebSocket request");
},
}
);
// Durable Object for WebSocket
export class WebSocketServer extends DurableObject {
constructor(ctx, env) {
super(ctx, env);
}
async fetch(request) {
// Verify WebSocket upgrade
const upgradeHeader = request.headers.get("Upgrade");
if (!upgradeHeader || upgradeHeader.toLowerCase() !== "websocket") {
return new Response("Expected WebSocket", { status: 426 });
}
// Create WebSocket pair
const webSocketPair = new WebSocketPair();
const [client, server] = Object.values(webSocketPair);
// Accept the server side
server.accept();
// Basic message handler
server.addEventListener("message", (event) => {
server.send("Echo: " + event.data);
});
Sentry.captureException(new Error('Testing sentry'));
// Return client WebSocket
return new Response(null, {
status: 101,
webSocket: client
});
}
}
Steps to Reproduce
Just added a test exception, did not show up.
Expected Result
Should have received the error in dashboard.
Actual Result
Did not show.
However, it does work when running the worker locally.
Metadata
Metadata
Assignees
Type
Projects
Status
Waiting for: Community
Activity
Lms24 commentedon Apr 4, 2025
Hey @LawrenceGB I believe your issue is a duplicate to #15342. I'm not fully involved in our CloudFlare SDK (therefore tagging @AbhiPrasad) but as far as I can tell, the SDK is not initialized in your
WebSocketServer
instance.In the issue, someone posted a workaround for durable objects. Would you mind giving this a try?
AbhiPrasad commentedon Apr 4, 2025
Yup, we don't wrap DurableObjects yet, we can backlog this as a feature, but the workaround should work as expected.
18 remaining items