Skip to content
betterstack-alchemyUnofficial

Applications

An Application collects the exceptions, releases and web events of one service. Better Stack error tracking speaks the Sentry protocol, so your service reports to it with the official Sentry SDK for its platform, configured with the application’s DSN, https://<token>@<ingestingHost>/<id>. The DSN can only report events into that one application.

BoxCloud.Server
ApiCloud.Service · Sentry SDK
env
SENTRY_DSN
my-teamBetter Stack team
api-errorsapplication · bun_errors
  • Apireports to DSN →api-errors
The service holds only the application's DSN, which can report events into that application and nothing else.
alchemy.run.ts
const errors = yield* BetterStack.Errors.Application("api-errors", {
name: "API",
platform: "bun_errors",
});

platform, dataRegion, correlateWithSourceId and teamId are set on create only: changing one replaces the application, with a new DSN. Errors.dataRegions() lists the regions your team can store data in.

The application exposes its DSN as dsn, a Redacted secret. Hand it to the service as environment; the same record works for a Cloud.Service, a Cloudflare Worker or any host that sets environment variables:

alchemy.run.ts
const env = {
SENTRY_DSN: errors.dsn,
SENTRY_ENVIRONMENT: "production",
};

In the service, initialise the Sentry SDK for its platform with that DSN, as Better Stack’s Sentry SDK guide shows.

Errors.Dsn binds the DSN into a host as SENTRY_DSN and reads it back as a Redacted at runtime. On a host with a process environment, such as a Cloud.Service, it also puts the plain DSN back into process.env, so a Sentry SDK that reads SENTRY_DSN itself works:

src/api.ts
import * as BetterStack from "betterstack-alchemy";
import * as Effect from "effect/Effect";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
import * as Redacted from "effect/Redacted";
import { Box, Errors } from "./shared.ts";
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* () {
// 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)),
) {}

On a Cloudflare Worker the DSN arrives as a secret_text binding named SENTRY_DSN. The binding is tested against the offline mock only; see Compatibility.

An ApplicationGroup organises related applications:

alchemy.run.ts
const group = yield* BetterStack.Errors.ApplicationGroup("production", {
name: "Production apps",
sortIndex: 1,
});
yield* BetterStack.Errors.Application("web-errors", {
platform: "next_js_errors",
applicationGroupId: group.id,
});

Destroying an application deletes it with all the data it received. Retain it where that data matters:

alchemy.run.ts
yield* BetterStack.Errors.Application("billing-errors", {
platform: "node_errors",
}).pipe(RemovalPolicy.retain());

Reference an application you don’t manage

Section titled “Reference an application you don’t manage”
alchemy.run.ts
const existing = BetterStack.Errors.Application.lookup({ id: "123456" });

An existing application with the same explicit name is adopted with --adopt.