@libo11y/effect 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,28 +3,27 @@
3
3
  The libo11y bridge for [Effect](https://effect.website) 4. It reports an
4
4
  Effect program to a libo11y telemetry from any platform package:
5
5
  [`@libo11y/server`](https://github.com/libo11y/libo11y/tree/main/ts/packages/server) on Bun and Node,
6
- [`@libo11y/workers`](https://github.com/libo11y/libo11y/tree/main/ts/packages/workers) on Cloudflare Workers, or
7
- [`@libo11y/web`](https://github.com/libo11y/libo11y/tree/main/ts/packages/web) in browsers. Effect spans, logs and metrics are
8
- then exported, correlated and redacted with everything else the telemetry
9
- exports.
6
+ [`@libo11y/workers`](https://github.com/libo11y/libo11y/tree/main/ts/packages/workers) on Cloudflare Workers,
7
+ [`@libo11y/web`](https://github.com/libo11y/libo11y/tree/main/ts/packages/web) / [`@libo11y/rum`](https://github.com/libo11y/libo11y/tree/main/ts/packages/rum) in browsers, or
8
+ [`@libo11y/react-native`](https://github.com/libo11y/libo11y/tree/main/ts/packages/react-native) in React Native.
9
+ Effect spans, logs and metrics are exported, correlated and redacted with
10
+ everything else the telemetry exports.
10
11
 
11
12
  ```sh
12
13
  npm install @libo11y/effect effect @effect/opentelemetry
13
14
  ```
14
15
 
15
- The package first ships in `ts/v0.8.0`. Until its first npm publish,
16
- install it from the tarball on the
17
- [`ts/v0.8.0` GitHub Release](https://github.com/libo11y/libo11y/releases/tag/ts/v0.8.0):
18
- `npm install https://github.com/libo11y/libo11y/releases/download/ts/v0.8.0/libo11y-effect-0.8.0.tgz`.
16
+ The package first ships in `ts/v0.8.0` and is published on npm at `0.9.0`
17
+ (and attached as a tarball to the
18
+ [`ts/v0.9.0` GitHub Release](https://github.com/libo11y/libo11y/releases/tag/ts/v0.9.0)).
19
19
 
20
20
  `effect` and `@effect/opentelemetry` (both `^4.2.0`) and
21
21
  `@opentelemetry/api` (`>=1.10.0 <1.11.0`) are peer dependencies.
22
22
  `@effect/opentelemetry` 4.2.0 is the first release built on OpenTelemetry
23
23
  JS 3.x, which libo11y uses. Only its `OtelTracer` module is loaded.
24
24
 
25
- libo11y wraps setup, not instrumentation, so the package is layers and two
26
- small helpers, and no span or metric wrapper types. Write Effect as usual:
27
- `Effect.withSpan`, `Effect.log`, `Effect.annotateLogs`, `Metric.counter`.
25
+ Write Effect as usual: `Effect.withSpan`, `Effect.log`,
26
+ `Effect.annotateLogs`, `Metric.counter`.
28
27
 
29
28
  ## Quick start
30
29
 
@@ -49,7 +48,7 @@ await telemetry.shutdown();
49
48
  `layer(telemetry, options?)` merges three layers, each also exported on
50
49
  its own:
51
50
 
52
- - `tracerLayer(telemetry)`: the Effect `Tracer` over
51
+ - `tracerLayer(telemetry, options?)`: the Effect `Tracer` over
53
52
  `telemetry.tracerProvider`, from `@effect/opentelemetry`'s `OtelTracer`.
54
53
  Effect spans, including those of Effect's `HttpServer`, `HttpClient`, RPC
55
54
  and SQL modules, become OpenTelemetry spans of that provider, so they pass
@@ -59,21 +58,28 @@ its own:
59
58
  an active OpenTelemetry span is its child. While a traced effect runs, its
60
59
  span is the active OpenTelemetry span, so `instrumentFetch` and other
61
60
  OpenTelemetry code see it. The instrumentation scope is `effect`.
61
+ Pass `sql: { parentConnectSpans: true }` (on `layer` or `tracerLayer`) to
62
+ re-parent `@effect/sql-pg`'s detached `sql.connect` root spans onto the
63
+ active propagated Effect span and enable `Statement.SpanPropagationEnabled`.
62
64
  - `loggerLayer(telemetry)`: an Effect `Logger` (`makeLogger(telemetry)`)
63
65
  that writes each record through `telemetry.logger`, to the console sink
64
66
  and the OTLP leg. Records carry the trace and span IDs of the fiber's
65
- Effect span. Log annotations become attributes, plain objects staying
66
- groups; log spans become `effect.log_span.<label>` in milliseconds; a
67
- failure or defect in the cause becomes `exception.type`,
68
- `exception.message` and `exception.stacktrace`. The sensitivity policy
69
- drops secret and PII attributes by key, as for every libo11y record.
70
- Effect's `MinimumLogLevel` filters first, then libo11y's `logLevel`.
67
+ propagated Effect span (walking past `Tracer.DisablePropagation` spans).
68
+ Log annotations become attributes, plain objects staying groups; log spans
69
+ become `effect.log_span.<label>` in milliseconds; a failure or defect in
70
+ the cause becomes `exception.type`, `exception.message` and
71
+ `exception.stacktrace`. The sensitivity policy drops secret and PII
72
+ attributes by key, as for every libo11y record. Effect's
73
+ `MinimumLogLevel` filters first, then libo11y's `logLevel`.
71
74
  - `metricsLayer(telemetry)`: Effect metrics on `telemetry.meterProvider`.
72
75
  Counters and frequencies add to OpenTelemetry counters (a counter that is
73
76
  not incremental becomes an up-down counter, and a frequency's word is the
74
77
  attribute `key`), histograms record with their own boundaries, summaries
75
- record into a histogram, and gauges are observed at each collection. A
76
- measurement inside a sampled Effect span carries an exemplar of it.
78
+ record into a histogram, and gauges are observed at each collection.
79
+ Pull-only `Counter`, `Frequency` and `Gauge` series registered through
80
+ `Metric.registerUnsafe` are bridged via `ObservableCounter`,
81
+ `ObservableUpDownCounter` and `ObservableGauge`. A measurement inside a
82
+ sampled Effect span carries an exemplar of it.
77
83
 
78
84
  By default the libo11y logger replaces Effect's loggers. It has a console
79
85
  sink of its own, so Effect's default console logger would print every record
@@ -94,7 +100,7 @@ whose cause is the `O11yError`:
94
100
  ```ts
95
101
  import { flush, layerScoped } from "@libo11y/effect";
96
102
  import { setup } from "@libo11y/server";
97
- import { Effect, Layer } from "effect";
103
+ import { Effect } from "effect";
98
104
 
99
105
  const Observability = layerScoped(() => setup({ serviceName: "worker", environment: "production" }));
100
106
 
@@ -110,11 +116,74 @@ await Effect.runPromise(
110
116
  context and succeeds with its `SignalReport`; `flushWith(options)` takes a
111
117
  deadline. Neither fails.
112
118
 
113
- ## Cloudflare Workers
119
+ ## Client tracing and single-carrier RPC propagation
120
+
121
+ Browser and React Native clients often load telemetry lazily after first
122
+ paint and gate trace propagation on consent, kill switches and allowed
123
+ origins. `@libo11y/effect` provides late-bound client layers that enforce
124
+ one gated carrier per hop:
125
+
126
+ - `createTelemetryRef(initial?)`: mutable reference to a `Telemetry` handle.
127
+ While unset, spans, logs, metrics and outbound trace propagation stay dark;
128
+ calling `ref.set(telemetry)` activates them seamlessly.
129
+ - `clientLayer(telemetryOrRef, options?)`: installs Effect's Tracer (via
130
+ `OtelTracer.layerWithoutOtelTracer`, creating no duplicate SDK), Logger
131
+ and Metrics over a concrete `Telemetry` or live `TelemetryRef`.
132
+ - `httpClientLayer(telemetryOrRef, options?)`: wraps `FetchHttpClient.layer`
133
+ with `HttpClient.TracerPropagationEnabled = false` (suppressing Effect's
134
+ `b3` and ungated `traceparent` while keeping Effect's `CLIENT` HTTP span),
135
+ uses the platform's untraced `fetch` (`pristineFetch` on web, depth-guarded
136
+ `untracedFetch` on bare React Native so XHR instrumentation emits no
137
+ duplicate span), strips all configured `propagator.fields()` (plus
138
+ `options.propagatorFields` / W3C defaults) before injection and on blocked
139
+ requests, and applies runtime-explicit redirect handling:
140
+ - Server (`"server"`, Node, Bun, Workers): hop-by-hop validation using
141
+ `redirect: "manual"`, stripping propagation headers (and cross-origin
142
+ `authorization`/`cookie`) on unapproved or ignored hops.
143
+ - Browser (`"browser"`): keeps `redirect: "follow"` by default on generic
144
+ `httpClientLayer` (overridable to `"error"`), and defaults to
145
+ `redirect: "error"` on `rpcProtocolHttpLayer` (overridable to
146
+ `"follow"`).
147
+ - React Native (`"react-native"`): runs over `untracedFetch` (`whatwg-fetch`
148
+ over XHR ignores `redirect` mode in JS; list only trusted non-redirecting
149
+ API origins in `propagateTo`).
150
+ - `stripHttpRpcSerialization(serializationLayer)` and
151
+ `rpcProtocolHttpLayer(telemetryOrRef, options)`: strip `{ traceId, spanId, sampled }`
152
+ from HTTP RPC `Request` bodies at the `RpcSerialization` encode boundary
153
+ so HTTP headers are the sole carrier while preserving direct parent
154
+ ancestry on unbatched HTTP RPC and `RpcClient.batch` span links on batched
155
+ HTTP RPC.
156
+ - `webSocketConstructorLayer(telemetryOrRef, options?)`,
157
+ `gateWebSocketConstructor(ctor, telemetryOrRef, options?)` and
158
+ `gateSocketRpcProtocol(protocolLayer, telemetryOrRef, options)`: evaluate
159
+ recording and destination gates synchronously right before wire `ws.send()`
160
+ (after Effect's `Socket.fromWebSocket` `latch.whenOpen` resumes) so frames
161
+ queued while opening or reconnecting have `{ traceId, spanId, sampled }`
162
+ scrubbed if consent is revoked or the `ws:`/`wss:` origin is disallowed.
163
+ Use `gateSocketRpcProtocol` for custom transports or binary serializations.
164
+
165
+ ```ts
166
+ import {
167
+ clientLayer,
168
+ createTelemetryRef,
169
+ rpcProtocolHttpLayer,
170
+ webSocketConstructorLayer,
171
+ } from "@libo11y/effect";
172
+ import { Layer } from "effect";
173
+
174
+ export const telemetryRef = createTelemetryRef();
175
+ export const ClientTelemetry = clientLayer(telemetryRef);
176
+ export const ApiRpcProtocol = rpcProtocolHttpLayer(telemetryRef, {
177
+ url: "https://api.example.com/rpc",
178
+ });
179
+ export const ChannelWebSocket = webSocketConstructorLayer(telemetryRef);
180
+ ```
181
+
182
+ ## Cloudflare Workers and detached context
114
183
 
115
184
  Build the app once per isolate and flush after every request through
116
185
  `waitUntil`. Effect's `HttpServer` makes the server span, so call `setup`
117
- and `scheduleFlush` from `@libo11y/workers` rather than `instrument`:
186
+ and `scheduleFlush` from `@libo11y/workers` (or `instrument(handler, { serve: false })`):
118
187
 
119
188
  ```ts
120
189
  import { layer } from "@libo11y/effect";
@@ -161,34 +230,29 @@ export default {
161
230
  } satisfies ExportedHandler<Env>;
162
231
  ```
163
232
 
164
- A queue consumer or a Durable Object runs its effects with a runtime built
165
- once per isolate:
166
-
167
- ```ts
168
- import { type Libo11yServices, layer } from "@libo11y/effect";
169
- import { ManagedRuntime } from "effect";
170
-
171
- let runtime: ManagedRuntime.ManagedRuntime<Libo11yServices, never> | undefined;
172
-
173
- export default {
174
- async queue(batch: MessageBatch, env: Env, ctx: ExecutionContext): Promise<void> {
175
- const telemetry = await setup(options(env));
176
- runtime ??= ManagedRuntime.make(layer(telemetry));
177
- try {
178
- await runtime.runPromise(
179
- Effect.forEach(batch.messages, (m) => handle(m)).pipe(
180
- Effect.withSpan(`process ${batch.queue}`, { kind: "consumer" }),
181
- ),
182
- );
183
- } finally {
184
- scheduleFlush(ctx, telemetry);
185
- }
186
- },
187
- } satisfies ExportedHandler<Env>;
188
- ```
189
-
190
- In a Durable Object, flush through the object's own state:
191
- `scheduleFlush(this.ctx, telemetry)`.
233
+ For Durable Objects, alarms, cron triggers, queues and outbox handoffs,
234
+ `@libo11y/effect` provides thin Effect combinators over `@libo11y/core`'s
235
+ detached `Carrier` and `@libo11y/core/edge`'s semconv 1.41.0 span builders:
236
+
237
+ - `captureContext`: captures the active fiber's propagated span context and
238
+ egress-filtered baggage into a detached `Carrier`.
239
+ - `withLinkedContext(carrier, name, options?)` and `linkCarriers(carriers)`:
240
+ start a linked root span with merged carrier baggage, or attach deduplicated
241
+ carrier links onto the active span.
242
+ - `traceDurableObjectMethods(className, methods)`,
243
+ `traceDurableObjectCall(className, method)`,
244
+ `traceDurableObjectStub(className, stub)` (preserving dual Effect/Stream
245
+ return values) and `enrichDurableObjectRpc(className, handlers)`: emit or
246
+ enrich semconv 1.41.0 Durable Object spans (`<Class>/<method>`,
247
+ `rpc.system.name: "cloudflare_durable_object"`, `o11y.durable_object.class`).
248
+ - `withAlarmSpan(className, callback, links?)`: root `SERVER` alarm span
249
+ with `faas.trigger: "timer"` and optional carrier links.
250
+ - `withCronSpan(cron, jobOrOptions?)`: root `SERVER` scheduled span with
251
+ `faas.trigger: "timer"`, `faas.cron` and optional ISO `faas.time`.
252
+ - `withQueueBatchSpan(queue, options?)`: wraps a streaming queue consumer in
253
+ a root `CONSUMER` span (`process <queue>`), extracting deduplicated `_o11y`
254
+ carriers as span links, recording `messaging.batch.message_count`, and
255
+ invoking `options.onBatchCount(count)`.
192
256
 
193
257
  ## Testing
194
258
 
@@ -207,10 +271,10 @@ await rec.shutdown();
207
271
 
208
272
  ## Known limitations
209
273
 
210
- - The metrics bridge provides Effect's `MetricRegistry` with a registry that
211
- wraps each series' update hook as Effect registers it. A series registered
212
- with `Metric.registerUnsafe` reports through its read hook only, so only
213
- gauges registered that way are exported.
274
+ - Pull-only `Histogram` and `Summary` series registered via
275
+ `Metric.registerUnsafe` are not bridged because OpenTelemetry JS has no
276
+ observable histogram or summary instrument (`Counter`, `Frequency` and
277
+ `Gauge` registrations are bridged via `Observable*` instruments).
214
278
  - Effect metrics have no unit, so the instruments have none.
215
279
  - Without a global OpenTelemetry context manager, as with a telemetry from
216
280
  `createTelemetry` and no recorder, log records are not correlated. The
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Effect 4 client telemetry and single-carrier gated propagation layers:
3
+ *
4
+ * - createTelemetryRef / clientLayer: late-bound Effect Tracer, Logger, and Metrics layers built on
5
+ * @effect/opentelemetry's OtelTracer.layerWithoutOtelTracer (never creating a duplicate SDK) so
6
+ * module-level runtimes activate seamlessly once lazy browser RUM or native setup finishes.
7
+ * - httpClientLayer / stripHttpRpcSerialization / rpcProtocolHttpLayer: enforces one gated carrier
8
+ * per HTTP hop. Injects configured propagator headers inside FetchHttpClient.Fetch with
9
+ * HttpClient.TracerPropagationEnabled = false, uses PropagationConfig.fetch (pristineFetch on
10
+ * web, depth-guarded untracedFetch on bare React Native), strips all propagator fields before
11
+ * injection and on blocked requests, applies runtime-explicit redirect handling, and strips
12
+ * { traceId, spanId, sampled } from HTTP RPC request bodies at the RpcSerialization boundary.
13
+ * - gateWebSocketConstructor / webSocketConstructorLayer / gateSocketRpcProtocol: enforces
14
+ * write-time consent and destination gating on WebSocket RPC envelopes right before wire send
15
+ * (after Socket.fromWebSocket's latch.whenOpen resumes), plus protocol-level gating for custom
16
+ * or binary socket serializations.
17
+ */
18
+ import * as OtelTracer from "@effect/opentelemetry/OtelTracer";
19
+ import type { Telemetry } from "@libo11y/core";
20
+ import type * as Duration from "effect/Duration";
21
+ import * as HttpClient from "effect/http/HttpClient";
22
+ import * as Layer from "effect/Layer";
23
+ import * as RpcClient from "effect/rpc/RpcClient";
24
+ import * as RpcSerialization from "effect/rpc/RpcSerialization";
25
+ import * as Socket from "effect/socket/Socket";
26
+ /** Runtime category controlling HTTP redirect handling when trace headers are injected. */
27
+ export type ClientRuntime = "browser" | "react-native" | "server";
28
+ /** Fetch redirect handling mode. */
29
+ export type RedirectMode = "error" | "follow" | "manual";
30
+ /**
31
+ * Mutable reference to a libo11y Telemetry handle for late-bound client setups (such as
32
+ * after-first-paint dynamic RUM loading in browsers). While unset (undefined), telemetry stays dark
33
+ * and outbound trace propagation is suppressed.
34
+ */
35
+ export interface TelemetryRef {
36
+ get(): Telemetry | undefined;
37
+ set(telemetry: Telemetry | undefined): void;
38
+ }
39
+ /** Either a concrete Telemetry handle or a live TelemetryRef. */
40
+ export type TelemetrySource = Telemetry | TelemetryRef;
41
+ /** Creates a live TelemetryRef, optionally seeded with an already-initialized Telemetry handle. */
42
+ export declare function createTelemetryRef(initial?: Telemetry): TelemetryRef;
43
+ /** Options for {@link clientLayer}. */
44
+ export interface ClientLayerOptions {
45
+ /**
46
+ * How the libo11y logger joins Effect's loggers. "replace" (default) replaces Effect's loggers,
47
+ * "merge" keeps existing loggers beside it, and "none" installs no logger.
48
+ */
49
+ readonly logger?: "replace" | "merge" | "none";
50
+ /** Bridge Effect metrics to the telemetry's meter provider once loaded. Default true. */
51
+ readonly metrics?: boolean;
52
+ }
53
+ /**
54
+ * Installs an Effect Tracer, Logger, and Metrics bridge over a concrete Telemetry or live
55
+ * TelemetryRef using `@effect/opentelemetry`'s `OtelTracer.layerWithoutOtelTracer` (never creating
56
+ * a duplicate SDK or touching globals). When backed by a TelemetryRef that starts undefined, spans
57
+ * and logs stay silent until `ref.set(telemetry)` runs and activate seamlessly thereafter.
58
+ */
59
+ export declare function clientLayer(telemetryOrRef: TelemetrySource, options?: ClientLayerOptions): Layer.Layer<OtelTracer.OtelTracer>;
60
+ /** Options for {@link httpClientLayer}. */
61
+ export interface HttpClientLayerOptions {
62
+ /**
63
+ * Additional propagation header names to strip before injection and on blocked requests, even
64
+ * before a lazy TelemetryRef finishes loading. Always unioned with `telemetry.propagator.fields()`
65
+ * (or `["traceparent", "tracestate", "baggage"]` while dark/unloaded).
66
+ */
67
+ readonly propagatorFields?: readonly string[];
68
+ /**
69
+ * Fetch redirect mode override. On server runtimes (`"server"`), `"follow"` (default) validates
70
+ * redirects hop-by-hop with `redirect: "manual"` so disallowed hops never receive trace headers.
71
+ * On browsers (`"browser"`), generic `httpClientLayer` defaults to `"follow"` (overridable to
72
+ * `"error"`), while `rpcProtocolHttpLayer` defaults to `"error"` (overridable to `"follow"`).
73
+ */
74
+ readonly redirect?: RedirectMode;
75
+ /** Maximum redirect hops followed in server hop-by-hop mode. Default 20. */
76
+ readonly maxRedirects?: number;
77
+ /** Explicit runtime override when the Telemetry handle carries no PropagationConfig metadata. */
78
+ readonly runtime?: ClientRuntime;
79
+ /** Optional additional destination gate predicate (ANDed with Telemetry's PropagationConfig). */
80
+ readonly shouldPropagate?: (url: URL) => boolean;
81
+ /** Optional additional ignore predicate (ORed with Telemetry's PropagationConfig). */
82
+ readonly isIgnored?: (url: URL) => boolean;
83
+ /** Optional fetch implementation override (takes precedence over PropagationConfig.fetch). */
84
+ readonly fetch?: typeof fetch;
85
+ }
86
+ /**
87
+ * Provides an Effect `HttpClient` over `FetchHttpClient` with gated single-carrier propagation:
88
+ *
89
+ * - Disables Effect's built-in `b3` + ungated `traceparent` injection
90
+ * (`HttpClient.TracerPropagationEnabled = false`) while keeping Effect's `CLIENT` HTTP span.
91
+ * - Uses `PropagationConfig.fetch` (`pristineFetch` on web, `depth`-guarded `untracedFetch` on
92
+ * bare React Native) so global RUM fetch/XHR patches never emit duplicate spans or headers.
93
+ * - Strips all configured `propagator.fields()` (plus `options.propagatorFields` / W3C defaults)
94
+ * before injection and on blocked requests.
95
+ * - Applies runtime-explicit redirect handling (`"server"`: hop-by-hop manual validation;
96
+ * `"browser"`: preserves `"follow"` by default, overridable via `redirect: "error"`;
97
+ * `"react-native"`: runs over `untracedFetch`).
98
+ */
99
+ export declare function httpClientLayer(telemetryOrRef: TelemetrySource, options?: HttpClientLayerOptions): Layer.Layer<HttpClient.HttpClient>;
100
+ /**
101
+ * Wraps an Effect `RpcSerialization` layer so HTTP RPC requests omit `{ traceId, spanId, sampled }`
102
+ * from encoded `Request` envelopes (single or batched arrays) right before wire serialization.
103
+ *
104
+ * Preserves Effect's `HttpClient` spans and batched `RpcClient.batch` `withBatchSpan` links
105
+ * (unlike `Tracer.DisablePropagation`, which turns spans into no-ops).
106
+ */
107
+ export declare function stripHttpRpcSerialization<E, R>(serializationLayer: Layer.Layer<RpcSerialization.RpcSerialization, E, R>): Layer.Layer<RpcSerialization.RpcSerialization, E, R>;
108
+ /** Options for {@link rpcProtocolHttpLayer}. */
109
+ export interface RpcProtocolHttpLayerOptions<E = never, R = never> extends HttpClientLayerOptions {
110
+ /** Target HTTP RPC endpoint URL. */
111
+ readonly url: string;
112
+ /** Optional HttpClient transformer (for example, attaching auth headers). */
113
+ readonly transformClient?: <CE, CR>(client: HttpClient.HttpClient.With<CE, CR>) => HttpClient.HttpClient.With<CE, CR>;
114
+ /** Optional HTTP RPC batching configuration. */
115
+ readonly batch?: {
116
+ readonly window: Duration.Input;
117
+ readonly maxSize?: number | undefined;
118
+ };
119
+ /**
120
+ * RPC serialization layer wrapped with {@link stripHttpRpcSerialization}.
121
+ * Defaults to `RpcSerialization.layerNdjson`.
122
+ */
123
+ readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization, E, R>;
124
+ }
125
+ /**
126
+ * Convenience layer for Effect HTTP RPC clients enforcing the single-carrier invariant:
127
+ *
128
+ * - Combines {@link httpClientLayer} (with `redirect: "error"` by default on `"browser"` so Effect
129
+ * HTTP RPC POSTs never carry trace headers across redirects, overridable via `redirect: "follow"`,
130
+ * and hop-by-hop manual redirect validation on `"server"`)
131
+ * - With {@link stripHttpRpcSerialization} (defaulting to `RpcSerialization.layerNdjson`) so HTTP
132
+ * RPC request bodies carry no `{ traceId, spanId, sampled }` fields.
133
+ */
134
+ export declare function rpcProtocolHttpLayer<E = never, R = never>(telemetryOrRef: TelemetrySource, options: RpcProtocolHttpLayerOptions<E, R>): Layer.Layer<RpcClient.Protocol, E, R>;
135
+ /** Options for WebSocket write-time trace gating. */
136
+ export interface WebSocketGateOptions {
137
+ /** Optional additional destination gate predicate (ANDed with Telemetry's PropagationConfig). */
138
+ readonly shouldPropagate?: (url: URL) => boolean;
139
+ /** Optional additional ignore predicate (ORed with Telemetry's PropagationConfig). */
140
+ readonly isIgnored?: (url: URL) => boolean;
141
+ }
142
+ /** Function signature of Effect's `Socket.WebSocketConstructor` service. */
143
+ export type WebSocketConstructorFn = Socket.WebSocketConstructor["Service"];
144
+ /**
145
+ * Wraps a `Socket.WebSocketConstructor` function so every opened `WebSocketLike` evaluates the
146
+ * telemetry recording and destination gate synchronously at `ws.send()` time (after Effect's
147
+ * `Socket.fromWebSocket` `latch.whenOpen` resumes).
148
+ *
149
+ * When the gate is closed (before setup, pending consent, revoked while opening/reconnecting,
150
+ * killed/safe mode, or disallowed/ignored `ws:`/`wss:` origin), strips `{ traceId, spanId, sampled }`
151
+ * from outbound JSON and NDJSON RPC Request frames right before wire transmission. For binary
152
+ * serializations, pair with {@link gateSocketRpcProtocol}.
153
+ */
154
+ export declare function gateWebSocketConstructor(ctor: WebSocketConstructorFn, telemetryOrRef: TelemetrySource, options?: WebSocketGateOptions): WebSocketConstructorFn;
155
+ /** Options for {@link webSocketConstructorLayer}. */
156
+ export interface WebSocketConstructorLayerOptions extends WebSocketGateOptions {
157
+ /** Custom underlying WebSocket constructor. Defaults to `globalThis.WebSocket`. */
158
+ readonly webSocketConstructor?: WebSocketConstructorFn;
159
+ }
160
+ /**
161
+ * Drop-in replacement for `Socket.layerWebSocketConstructorGlobal` that enforces write-time
162
+ * propagation gating on every WebSocket RPC frame right before `ws.send()`.
163
+ */
164
+ export declare function webSocketConstructorLayer(telemetryOrRef: TelemetrySource, options?: WebSocketConstructorLayerOptions): Layer.Layer<Socket.WebSocketConstructor>;
165
+ /** Options for {@link gateSocketRpcProtocol}. */
166
+ export interface SocketRpcProtocolGateOptions extends WebSocketGateOptions {
167
+ /** Target WebSocket endpoint URL (or lazy getter) evaluated against the destination gate. */
168
+ readonly url: string | URL | (() => string | URL);
169
+ }
170
+ /**
171
+ * Wraps an Effect `RpcClient.Protocol` layer to gate `{ traceId, spanId, sampled }` at
172
+ * `Protocol.send` before serialization. Use for custom socket protocols or binary RPC
173
+ * serializations (where wire-level JSON/NDJSON scrubbing in `webSocketConstructorLayer` does not
174
+ * inspect binary frames).
175
+ */
176
+ export declare function gateSocketRpcProtocol<E, R>(protocolLayer: Layer.Layer<RpcClient.Protocol, E, R>, telemetryOrRef: TelemetrySource, options: SocketRpcProtocolGateOptions): Layer.Layer<RpcClient.Protocol, E, R>;