import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Redacted from "effect/Redacted"; import type * as Scope from "effect/Scope"; import type { Input } from "./Input.ts"; /** * The shape of the {@link Telemetry} reference: a Layer of telemetry * exporters (tracer, loggers, metrics) built once per event into the * event's request scope. Requirements are satisfied from the runtime's * isolate context (`HttpClient`, `ConfigProvider`, …). */ export type TelemetryLayer = Layer.Layer; /** * The per-event telemetry exporters, as a `Context.Reference` holding the * Layer the runtime bridges build into every event's request scope. * Provide it via {@link layerOtlp} / {@link layer} rather than directly — * see the module documentation. */ export declare const Telemetry: Context.Reference; /** * Install a custom telemetry Layer (any Layer providing a `Tracer`, * loggers, and/or metric exporters). It is built once per event into the * event's request scope, so scoped exporters flush when the request scope * finalizes. * * Custom layers COMPOSE with the built-in OTLP destinations and with each * other: loggers and metric exporters merge; a custom `Tracer` (a single * Effect service) replaces the built-in one. * * Provide it on the Function/Worker's init Effect (merged into the single * `Effect.provide`): building the returned Layer registers the exporter * Layer on the current runtime context, where the runtime bridges pick it * up per event. Handlers' request-time context is assembled by the bridge, * so a plain `Layer.succeed` of the reference on the init Effect would * never reach them — the registration is what makes it visible at request * time. */ export declare const layer: (exporter: TelemetryLayer) => Layer.Layer; /** * A header value: a plain string, a `Redacted` secret, or an Output of * either (e.g. an ApiToken's `token` attribute). */ export type OtlpHeaderValue = Input>; /** * OTLP configuration for one signal. `url` and header values accept plain * values or resource Outputs — they are *bound* onto the host at deploy * time like any other binding. */ export interface OtlpSignalOptions { /** The OTLP/HTTP URL exports for this signal are POSTed to. */ url: Input; /** * Headers sent with each export request (e.g. auth tokens). `Redacted` * values bind as secrets. */ headers?: Record | undefined; } /** * Options for {@link layerOtlp}. Configure a base `url` (with * `/v1/{signal}` appended per signal), per-signal urls, or a mix — a * per-signal entry takes precedence over the base. */ export interface OtlpOptions { /** Base OTLP/HTTP URL; `/v1/{traces,logs,metrics}` is appended per signal. */ url?: Input | undefined; /** Headers for every signal; per-signal `headers` take precedence. */ headers?: Record | undefined; traces?: OtlpSignalOptions | undefined; logs?: OtlpSignalOptions | undefined; metrics?: OtlpSignalOptions | undefined; /** * The exported `service.name`. * @default the deployed Function/Worker's physical name */ serviceName?: Input | undefined; } /** * The built-in OTLP exporter as a *binding* layer. * * At deploy time, building this layer binds the configured urls and * headers onto the host Function/Worker (Redacted values as secret * bindings) — url and header values accept resource Outputs, so exporter * config is wired from resources like any other binding. At runtime the * exporter reads the bound values back and ships traces, logs, and metrics * over OTLP/HTTP JSON, flushed as each event's scope closes. * * Exporters COMPOSE: merge several `otlp` layers (or vendor sugar like * `Axiom.Telemetry`) and every destination receives the telemetry — spans * are serialized once, so trace/span ids agree across destinations: * * ```ts * Effect.provide( * Layer.mergeAll( * Cloudflare.R2.ReadWriteBucketBinding, * Axiom.Telemetry({ token: Ingest, traces: Traces, logs: Logs }), * Alchemy.Telemetry.layerOtlp({ * url: "https://api.honeycomb.io", * headers: { "x-honeycomb-team": apiKey }, * }), * ), * ) * ``` */ export declare const layerOtlp: (options: OtlpOptions) => Layer.Layer; /** * Build the configured {@link Telemetry} Layer into an event's request * scope, returning the Context of telemetry services to provide to the * event's handler effect. * * Called by the runtime bridges (Worker, Durable Object, Workflow, Lambda) * once per event. Building into the *request* scope — not the * never-finalized isolate scope — is what makes export work on workerd: * the batching fiber lives inside the event's I/O context and the final * flush runs from the scope's finalizer, which the bridges register with * `ctx.waitUntil`. * * A failed build (bad user Layer, config error) degrades to an empty * Context with a warning instead of failing the event. * * `override` is the (possibly merged) custom Layer registered on the * runtime context by {@link layer} during init. It composes with * — rather than replaces — the bound OTLP destinations: loggers and metric * exporters merge, and a custom `Tracer` (a single Effect service) wins * over the built-in one. * * Declared `R = never`: the Layer's actual requirements (`HttpClient`, * `ConfigProvider`, …) are satisfied at runtime by the bridge's surrounding * `Effect.provide` of the built runtime context. */ export declare const buildEventTelemetry: (context: Context.Context, scope: Scope.Scope, override?: TelemetryLayer | undefined, base?: TelemetryLayer | undefined) => Effect.Effect>; /** * Provide telemetry to a long-running server process (Cloudflare Container, * ECS Task, EC2 host, Lambda microVM). * * Unlike the per-event runtime bridges, server processes have no I/O-context * pinning and a real shutdown: the configured {@link Telemetry} Layer is * built ONCE into the ambient root scope, exporters batch on their intervals * for the life of the process, and the final flush runs when the root scope * closes on graceful exit. * * `runtimeContext` is the entrypoint's runtime context; its `telemetry` * field carries the custom Layer(s) registered by {@link layer} * during init, composed with the bound OTLP destinations (read with the * standard periodic export intervals). */ export declare const provideProcessTelemetry: (runtimeContext?: { telemetry?: TelemetryLayer | undefined; }) => (effect: Effect.Effect) => Effect.Effect; //# sourceMappingURL=Telemetry.d.ts.map