tldraw/packages/worker-shared/src/sentry.ts
alex cbac3ad3d0
introduce images.tldraw.xyz image optimisation worker (#4069)
Fixes asset loading/processing on staging/previews by introducing a new
image processing worker. This worker acts as a proxy for our various
image hosts and resizes/optimizes/caches images on the fly. Like the old
bookmark worker, this one is deployed in an ad-hoc fashion as it works
across environments and we're not likely to change it often.

### Change type

- [x] `other`
2024-07-08 16:25:53 +00:00

40 lines
1 KiB
TypeScript

import { WorkerVersionMetadata } from '@cloudflare/workers-types'
import { Toucan } from 'toucan-js'
import { requiredEnv } from './env'
interface Context {
waitUntil: ExecutionContext['waitUntil']
request?: Request
}
export interface SentryEnvironment {
readonly SENTRY_DSN?: string | undefined
readonly TLDRAW_ENV?: string | undefined
readonly WORKER_NAME?: string | undefined
readonly CF_VERSION_METADATA?: WorkerVersionMetadata
}
export function createSentry(ctx: Context, env: SentryEnvironment, request?: Request) {
// TLDRAW_ENV is undefined in dev
if (!env.SENTRY_DSN && !env.TLDRAW_ENV) {
return null
}
const { SENTRY_DSN, WORKER_NAME, CF_VERSION_METADATA } = requiredEnv(env, {
SENTRY_DSN: true,
WORKER_NAME: true,
CF_VERSION_METADATA: true,
})
return new Toucan({
dsn: SENTRY_DSN,
release: `${WORKER_NAME}.${CF_VERSION_METADATA.id}`,
environment: WORKER_NAME,
context: ctx,
request,
requestDataOptions: {
allowedHeaders: ['user-agent'],
allowedSearchParams: /(.*)/,
},
})
}