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.
- env
- SENTRY_DSN
- Apireports to DSN →api-errors
Create an application
Section titled “Create an application”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.
Configure the Sentry SDK
Section titled “Configure the Sentry SDK”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:
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.
Bind the DSN
Section titled “Bind the DSN”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:
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.
Group applications
Section titled “Group applications”An ApplicationGroup organises related
applications:
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,});Keep the data when you destroy
Section titled “Keep the data when you destroy”Destroying an application deletes it with all the data it received. Retain it where that data matters:
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”const existing = BetterStack.Errors.Application.lookup({ id: "123456" });An existing application with the same explicit name is adopted with
--adopt.
Where next
Section titled “Where next”- Releases & integrations: versions and where errors are posted.
- Watching your services: error tracking next to logs, a monitor and a heartbeat.
- Reference:
Application,ApplicationGroup, lookups. - Better Stack: Sentry SDK.