import { Attributes, Span } from '@opentelemetry/api'; import { O as OtelAttributeFilter } from './types-Db5ZtQHb.js'; /** * Shared utilities for server and client OTel interceptors * * Contains common helper functions used by both createOtelInterceptor() * and createOtelClientInterceptor(). * * @module shared */ /** * Estimates the serialized size of a protobuf message in bytes. * * If the message exposes a `toBinary()` method (standard for protobuf-es messages), * returns the byte length of the serialized form. Otherwise returns 0. * Results are cached per message object using a WeakMap. * * @param message - The message to estimate size for * @returns Size in bytes, or 0 if size cannot be determined */ declare function estimateMessageSize(message: unknown): number; /** * Wraps an AsyncIterable to track streaming messages with OTel span events. * * Captures the span via closure (not AsyncLocalStorage) to avoid * the Node.js ALS context loss in async generators (nodejs/node#42237). * * When `endSpanOnComplete` is true, the span lifecycle is managed by the * generator itself: the span is ended in the `finally` block, which runs * on normal completion, error, or early break (generator.return()). * * @param iterable - The source async iterable (streaming messages) * @param span - The OTel span to record events on * @param direction - 'SENT' for outgoing, 'RECEIVED' for incoming messages * @param recordMessages - Whether to record individual message events * @param endSpanOnComplete - Whether to end the span when the stream completes * @returns A new AsyncGenerator that yields the same messages with span events */ declare function wrapAsyncIterable(iterable: AsyncIterable, span: Span, direction: "SENT" | "RECEIVED", recordMessages: boolean, endSpanOnComplete?: boolean): AsyncGenerator; /** * Builds error-specific attributes for spans and metrics. * * For ConnectError instances, records the Connect error code name and numeric code. * For generic Error instances, records the error constructor name. * For unknown error types, records "UNKNOWN". * * @param error - The caught error * @returns Record of error attributes to attach to spans/metrics */ declare function buildErrorAttributes(error: unknown): Record; /** * Parameters for building base RPC attributes. */ interface BaseAttributeParams { service: string; method: string; serverAddress: string; serverPort?: number | undefined; } /** * Builds standard RPC base attributes per OTel semantic conventions. * * @param params - Service, method, server address/port info * @returns Record of base attributes */ declare function buildBaseAttributes(params: BaseAttributeParams): Record; /** * Connectum transport identifier observed from request headers. * * `@connectum/core`'s `createLocalTransport` sets a synthetic request header * (`connectum-internal-transport: in-process`) on every outgoing call so that * the OTel interceptors can tag spans and metrics with the originating * transport without parsing the synthetic `https://in-memory/...` URL. * * @param headers - The request headers (Connect `req.header`) * @returns `"in-process"` if the marker is present, `"http"` otherwise. */ declare function detectConnectumTransport(headers: Headers): "in-process" | "http"; /** * Applies an attribute filter to the given attributes. * * @param attrs - Base attributes to filter * @param filter - Optional filter function * @returns Filtered attributes */ declare function applyAttributeFilter(attrs: Record, filter?: OtelAttributeFilter): Attributes; export { type BaseAttributeParams, applyAttributeFilter, buildBaseAttributes, buildErrorAttributes, detectConnectumTransport, estimateMessageSize, wrapAsyncIterable };