(optionsCallback: (env: Env) => CloudflareOptions | undefined, handler: T)
| 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> |
| 30 | export function withSentry< |
| 31 | Env = typeof cloudflareEnv, |
| 32 | QueueHandlerMessage = unknown, |
| 33 | CfHostMetadata = unknown, |
| 34 | T extends ExportedHandler<Env, QueueHandlerMessage, CfHostMetadata> | WorkerEntrypointConstructor = ExportedHandler< |
| 35 | Env, |
| 36 | QueueHandlerMessage, |
| 37 | CfHostMetadata |
| 38 | >, |
| 39 | >(optionsCallback: (env: Env) => CloudflareOptions | undefined, handler: T): T { |
| 40 | if (isCloudflareClass(handler, 'WorkerEntrypoint')) { |
| 41 | // oxlint-disable-next-line typescript/no-explicit-any |
| 42 | return instrumentWorkerEntrypoint(optionsCallback as any, handler); |
| 43 | } |
| 44 | |
| 45 | setAsyncLocalStorageAsyncContextStrategy(); |
| 46 | |
| 47 | try { |
| 48 | // oxlint-disable-next-line typescript/no-explicit-any |
| 49 | instrumentExportedHandlerFetch(handler, optionsCallback as any); |
| 50 | instrumentHonoErrorHandler(handler); |
| 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); |
| 59 | // This is here because Miniflare sometimes cannot get instrumented |
| 60 | } catch { |
| 61 | // Do not console anything here, we don't want to spam the console with errors |
| 62 | } |
| 63 | |
| 64 | return handler; |
| 65 | } |
| 66 | |
| 67 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 68 | function instrumentHonoErrorHandler<T extends ExportedHandler<any, any, any>>(handler: T): void { |
no test coverage detected