Skip to content

Commit 71b3910

Browse files
committed
fixup! feat(cloudflare): Support basic WorkerEntrypoint
1 parent f82649e commit 71b3910

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// Generated by Wrangler on Mon Jul 29 2024 21:44:31 GMT-0400 (Eastern Daylight Time)
22
// by running `wrangler types`
3-
4-
interface Env {
5-
E2E_TEST_DSN: '';
6-
MY_DURABLE_OBJECT: DurableObjectNamespace;
3+
declare namespace Cloudflare {
4+
interface GlobalProps {
5+
mainModule: typeof import("./src/index");
6+
}
7+
interface Env {
8+
E2E_TEST_DSN: '';
9+
MY_DURABLE_OBJECT: DurableObjectNamespace;
10+
}
711
}
12+
interface Env extends Cloudflare.Env {}

packages/cloudflare/src/withSentry.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import {
2525
* @param handler {ExportedHandler} The handler to wrap.
2626
* @returns The wrapped handler.
2727
*/
28+
// TODO(v11): The generic types need to be rewritten to following to improve type safety:
29+
// T extends ExportedHandler<any, any, any> | WorkerEntrypointConstructor<any, any>
2830
export function withSentry<
2931
Env = typeof cloudflareEnv,
3032
QueueHandlerMessage = unknown,
@@ -34,20 +36,26 @@ export function withSentry<
3436
QueueHandlerMessage,
3537
CfHostMetadata
3638
>,
37-
>(optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined, handler: T): T {
39+
>(optionsCallback: (env: Env) => CloudflareOptions | undefined, handler: T): T {
3840
if (isCloudflareClass(handler, 'WorkerEntrypoint')) {
39-
return instrumentWorkerEntrypoint(optionsCallback, handler);
41+
// oxlint-disable-next-line typescript/no-explicit-any
42+
return instrumentWorkerEntrypoint(optionsCallback as any, handler);
4043
}
4144

4245
setAsyncLocalStorageAsyncContextStrategy();
4346

4447
try {
45-
instrumentExportedHandlerFetch(handler, optionsCallback);
48+
// oxlint-disable-next-line typescript/no-explicit-any
49+
instrumentExportedHandlerFetch(handler, optionsCallback as any);
4650
instrumentHonoErrorHandler(handler);
47-
instrumentExportedHandlerScheduled(handler, optionsCallback);
48-
instrumentExportedHandlerEmail(handler, optionsCallback);
49-
instrumentExportedHandlerQueue(handler, optionsCallback);
50-
instrumentExportedHandlerTail(handler, optionsCallback);
51+
// oxlint-disable-next-line typescript/no-explicit-any
52+
instrumentExportedHandlerScheduled(handler, optionsCallback as any);
53+
// oxlint-disable-next-line typescript/no-explicit-any
54+
instrumentExportedHandlerEmail(handler, optionsCallback as any);
55+
// oxlint-disable-next-line typescript/no-explicit-any
56+
instrumentExportedHandlerQueue(handler, optionsCallback as any);
57+
// oxlint-disable-next-line typescript/no-explicit-any
58+
instrumentExportedHandlerTail(handler, optionsCallback as any);
5159
// This is here because Miniflare sometimes cannot get instrumented
5260
} catch {
5361
// Do not console anything here, we don't want to spam the console with errors

0 commit comments

Comments
 (0)