Skip to content
betterstack-alchemyUnofficial

Errors.Dsn

Kind BindingType id BetterStack.Errors.DsnSource src/Errors/Dsn.ts

Hand a host the Sentry DSN of an Application, so a Sentry SDK in that host reports its exceptions to Better Stack error tracking.

At deploy it binds the application’s dsn (Redacted) into the host’s environment as SENTRY_DSN (or options.env); at runtime it returns an Effect that reads the DSN back as a Redacted.

Alchemy carries secrets through a host’s environment in a marked form ({"_tag":"Redacted",…}) that only Alchemy reads. On a host with a process environment (a Cloud.Service, a container, Lambda) the binding puts the plain DSN back into process.env when the host starts, so a Sentry SDK that reads SENTRY_DSN itself works: Sentry.init({ tracesSampleRate: 1 }) after the binding. Elsewhere (a Cloudflare Worker’s env) pass it explicitly: dsn: Redacted.value(yield* dsn).

Credential. The host receives the DSN only: an ingestion token that can only report events (errors, releases seen in events, web events) into that one application. It reads nothing and manages nothing. No API token reaches the host. That is the least Better Stack offers for reporting.

Cost. Every reported exception counts against the team’s error tracking volume; sample with the Sentry SDK’s options when it is high.

Provide DsnLive on the host’s implementation.

Bind the DSN; Sentry reads SENTRY_DSN

export const Errors = BetterStack.Errors.Application("Errors", { platform: "node_errors" });
export default class Api extends BetterStack.Cloud.Service<Api>()(
"Api",
{ server: Box, main: import.meta.url, port: 3000 },
Effect.gen(function* () {
const dsn = yield* BetterStack.Errors.Dsn(Errors);
return {
fetch: Effect.gen(function* () {
// e.g. Sentry.init({ dsn: Redacted.value(yield* dsn) }) once, at startup
const value = yield* dsn;
return HttpServerResponse.text(Redacted.value(value).length > 0 ? "ok" : "no dsn");
}),
};
}).pipe(Effect.provide(BetterStack.Errors.DsnLive)),
) {}

The DSN is bound through RuntimeContext, so a Cloudflare Worker gets it as a secret_text binding named SENTRY_DSN (what @sentry/cloudflare reads from env) and a Lambda Function as an environment variable.