Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

AbhiPrasad
Copy link
Member

resolves #13141

This PR adds a new method to the cloudflare SDK, instrumentD1WithSentry. This method can be used to instrument Cloudflare D1, Cloudflare's serverless SQL database.

// env.DB is the D1 DB binding configured in your `wrangler.toml`
const db = instrumentD1WithSentry(env.DB);
// Now you can use the database as usual
await db.prepare('SELECT * FROM table WHERE id = ?').bind(1).run();

The reason this has to be a standalone wrapper method instead of an integration is because the cloudflare d1 instance can be bound to any arbitrary environmental variable as per user config. This is why the snippet above shows env.DB being passed into instrumentD1WithSentry. env.DB can easily be env.COOL_DB or env.HAPPY_DB.

I am planning to ask the cloudflare team to expose some APIs to make this better, but in the meantime this is the best we can do.

image

image

@AbhiPrasad AbhiPrasad self-assigned this Jul 31, 2024
@AbhiPrasad AbhiPrasad requested review from a team, lforst and s1gr1d and removed request for a team July 31, 2024 18:35
Copy link
Member

@s1gr1d s1gr1d left a comment

Choose a reason for hiding this comment

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

Looks good from my side. Nice JSDocs comments

@AbhiPrasad AbhiPrasad merged commit 0be9894 into develop Aug 1, 2024
@AbhiPrasad AbhiPrasad deleted the abhi-d1-cloudflare branch August 1, 2024 14:40
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.

Add queries module support by instrumenting Cloudflare d1
2 participants