Skip to content
betterstack-alchemyUnofficial

Telemetry.Export

Kind LayerSource src/Telemetry/Export.ts

Export a host’s OpenTelemetry (spans, logs, metrics) to a Better Stack source.

A binding layer over alchemy/Telemetry’s layerOtlp: building it in the host’s init binds each signal’s endpoint (https://<ingestingHost>/v1/…) and Authorization: Bearer <source token> (a secret) onto the host; at runtime Alchemy’s built-in exporter ships each signal — flushed per event on Workers/Lambda, batched for the process’s life on a Cloud.Service. Composes with other layerOtlp destinations.

Right after the source is created. A new source’s ingesting host refuses its token for a few seconds (401); Telemetry.Source only reports a create done once the token is accepted, and every host that binds the source is deployed after it, so a host in the same stack never sees that window.

Credential. The host receives the source’s own token: it can only write into that source.

Cost. Spans, logs and metrics count against the team’s telemetry ingestion; sample high-volume traces.

Instrument with Effect itself — named spans (Effect.fn), attributes on the span, structured logs with annotations, Metrics — and provide ONE Export layer: traces, logs and metrics all reach the source.

A handler instrumented with Effect, exported to one source

export const Otel = BetterStack.Telemetry.Source("Otel", { platform: "open_telemetry" });
const ordersPlaced = Metric.counter("orders_placed", { description: "Orders accepted" });
const placeOrder = Effect.fn("orders.place")(function* (orderId: string) {
yield* Effect.annotateCurrentSpan({ "order.id": orderId });
yield* Metric.update(ordersPlaced, 1);
yield* Effect.logInfo("order placed").pipe(Effect.annotateLogs({ orderId }));
});
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* placeOrder("o-1");
return HttpServerResponse.text("ok");
}),
};
}).pipe(Effect.provide(BetterStack.Telemetry.Export({ source: Otel, serviceName: "api" }))),
) {}

The same layer works on any Alchemy host: provide it on a Cloudflare Worker’s or Lambda Function’s init Effect, merged with its other bindings.

logs Source | Effect<Source, never, any>

Source for logs (overrides source).

metrics Source | Effect<Source, never, any>

Source for metrics (overrides source).

serviceName string | Output<string, any> | Config<string> | Effect<string, any, any>

The exported service.name. Default: the host's physical name.

source Source | Effect<Source, never, any>

The source every signal goes to, unless a per-signal source is given. An OpenTelemetry source (platform: "open_telemetry") takes all three.

traces Source | Effect<Source, never, any>

Source for traces (overrides source).