Skip to content

Cloudflare D1 instrumentation prevents deployment to workers #16801

Open
@depsimon

Description

@depsimon

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/cloudflare - hono

SDK Version

9.34.0

Framework Version

Hono 4.8.3

Link to Sentry event

No response

Reproduction Example/SDK Setup

// lib/db.ts 
import { env } from "cloudflare:workers";

export const db = Sentry.instrumentD1WithSentry(env.DB);
// index.ts
import { Hono } from "hono";
import { db } from "~/lib/db";

type Env = {
	Bindings: CloudflareEnv;
};

const app = new Hono<Env>();

app.get("/", async (c) => {
	const result = await db.exec("SELECT 1");
	
	return c.json({
		message: "Hello Hono!",
		result,
	});
});

export default Sentry.withSentry((env: CloudflareEnv) => {
	return {
		dsn: env.SENTRY_DSN,

		// Adds request headers & IP for users
		sendDefaultPii: true,

		// Enable logs to be sent to Sentry
		_experiments: { enableLogs: true },

		tracesSampleRate: 1.0,
	};
}, app);

Steps to Reproduce

  1. Setup D1 instrumentation as per the docs
  2. Use that db somewhere in your app
  3. Deploy the worker

Expected Result

Without the instrumentation, it works fine both locally & in production.

With the instrumentation, it works locally, but the deployment fails due to env.DB being undefined.

I would expect the behavior to be consistent with the non-instrumented version.

Actual Result

CloudflareApiError: Error 400 uploading worker script worker 'backend': Uncaught TypeError: Cannot read properties of undefined (reading 'prepare')
  at worker.js:59795:31 in instrumentD1WithSentry

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions