Skip to content

feat(cloudflare): Add support for durable objects #16180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 1, 2025

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented May 1, 2025

This PR introduces a new instrumentDurableObjectWithSentry method to the SDK, which instruments durable objects. We capture both traces and errors automatically.

image

Usage:

class MyDurableObjectBase extends DurableObject<Env> {
 // impl
}

// Export your named class as defined in your wrangler config
export const MyDurableObject = Sentry.instrumentDurableObjectWithSentry(
        // need to define options again because durable objects can be in a separate instance
        // to the cloudflare worker 
	(env) => ({
		dsn: env.SENTRY_DSN,
		tracesSampleRate: 1.0,
	}),
	MyDurableObjectBase,
);

This should work with websockets, and thus https://github.com/getsentry/sentry-mcp as well.

This PR also refactors some types in packages/cloudflare/src/handler.ts with the withSentry method, which should prevent type errors in some situations. This might help with #16099

resolves #15975
resolves https://linear.app/getsentry/issue/JS-285
resolves #16182
resolves https://linear.app/getsentry/issue/JS-398

@AbhiPrasad AbhiPrasad requested a review from a team May 1, 2025 01:31
@AbhiPrasad AbhiPrasad self-assigned this May 1, 2025
@AbhiPrasad AbhiPrasad requested review from lforst and Lms24 and removed request for a team May 1, 2025 01:31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now but since we have stuff like this in multiple sdks, it's probably worth extracting it in the future

@AbhiPrasad AbhiPrasad merged commit 7c50cd4 into develop May 1, 2025
33 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-durable-objects-cloudflare branch May 1, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9.15.0 breaks Cloudflare SDK usage in sentry-mcp Cloudflare Websocket with Durable Objects not working
2 participants