Closed
Show file tree
Hide file tree
Changes from 1 commit
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Failed to load files.
Next Next commit
fix(cloudflare): Import types explicitly from worker-types
  • Loading branch information
@AbhiPrasad
AbhiPrasad committedJun 20, 2025
commit 89808338aee90e9c0006923d27c5c4bd88198f0f
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import { Hono } from 'hono';
import { DurableObject } from 'cloudflare:workers';
import * as Sentry from '@sentry/cloudflare';

const app = new Hono();
Expand All@@ -25,6 +26,19 @@ app.notFound(ctx => {
return ctx.json({ message: 'Not Found' }, 404);
});

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

// Typecheck that the instrumented durable object is valid
export const MyDurableObject = Sentry.instrumentDurableObjectWithSentry(
(env: Env) => ({
dsn: env?.E2E_TEST_DSN,
tracesSampleRate: 1.0,
}),
MyDurableObjectBase,
);

export default Sentry.withSentry(
(env: Env) => ({
dsn: env?.E2E_TEST_DSN,
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/unbound-method */
import type { DurableObject, DurableObjectState, ExecutionContext, Rpc } from '@cloudflare/workers-types';
import {
captureException,
flush,
Expand All@@ -9,7 +10,6 @@ import {
withIsolationScope,
withScope,
} from '@sentry/core';
import type { DurableObject } from 'cloudflare:workers';
import { setAsyncLocalStorageAsyncContextStrategy } from './async';
import type { CloudflareOptions } from './client';
import { isInstrumented, markAsInstrumented } from './instrument';
Expand DownExpand Up@@ -135,8 +135,8 @@ function wrapMethodWithSentry<T extends (...args: any[]) => any>(
*/
export function instrumentDurableObjectWithSentry<
E,
T extends DurableObject<E>,
C extends new (state: DurableObjectState, env: E) => T,
T extends DurableObject & Rpc.DurableObjectBranded,
C extends new (ctx: DurableObjectState, env: E) => T,
>(optionsCallback: (env: E) => CloudflareOptions, DurableObjectClass: C): C {
return new Proxy(DurableObjectClass, {
construct(target, [context, env]) {
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
import type {
EmailExportedHandler,
ExportedHandler,
ExportedHandlerFetchHandler,
ExportedHandlerQueueHandler,
ExportedHandlerScheduledHandler,
ExportedHandlerTailHandler,
} from '@cloudflare/workers-types';
import {
captureException,
flush,
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
import type { EventPluginContext, PagesPluginFunction } from '@cloudflare/workers-types';
import { setAsyncLocalStorageAsyncContextStrategy } from './async';
import type { CloudflareOptions } from './client';
import { wrapRequestHandler } from './request';
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,6 @@
"include": ["src/**/*"],

"compilerOptions": {
"module": "esnext",
"types": ["node", "@cloudflare/workers-types"]
"module": "esnext"
}
}