Skip to content
betterstack-alchemyUnofficial

Telemetry.ShipLogs

Kind LayerSource src/Telemetry/ShipLogs.ts

Ship the host’s own Effect logs (Effect.log, Effect.logError, …) into a Source, in bounded batches, next to the console output.

Built on IngestLogs (provided internally): the host receives only the source’s own token and ingesting host. Registered through alchemy/Telemetry’s layer, so the runtime installs the logger the way it installs exporters: once for a long-running process (a Cloud.Service, flushed at shutdown), per event on Workers and Lambda (flushed when the event ends).

Events are { dt, level, message, ...annotations }; at most maxBuffer are held, sent batchSize at a time every window.

For application telemetry, prefer Effect’s OpenTelemetry exported with Telemetry.Export: logs then travel with their trace. ShipLogs is the plain-JSON alternative for a host without the export layer, or when you want log lines as plain source events.

Pick one per host: with alchemy@2.0.0-beta.87, ShipLogs and Export’s OTLP logs on the same host do not combine. Both reach the runtime as telemetry layers that each provide the host’s logger set, and the runtime merges them with Layer.mergeAll (buildEventTelemetry / provideProcessTelemetry in alchemy/TelemetryRuntime), where the later Logger.layer replaces the earlier one’s set instead of adding to it.

Cost. Every shipped line counts against log ingestion: raise minimumLevel for chatty services.

Effect’s logs go to the source

export default class Api extends BetterStack.Cloud.Service<Api>()(
"Api",
{ server: Box, main: import.meta.url, port: 3000 },
Effect.gen(function* () {
return {
fetch: Effect.gen(function* () {
yield* Effect.logInfo("order placed").pipe(Effect.annotateLogs({ orderId: "o-1" }));
return HttpServerResponse.text("ok");
}),
};
}).pipe(Effect.provide(BetterStack.Telemetry.ShipLogs(AppLogs))),
) {}

Works on any Alchemy host: provide it on a Worker’s or Lambda Function’s init Effect.