@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
65 lines (64 loc) • 4.67 kB
TypeScript
import { type Context } from "@opentelemetry/api";
import type { ReadableSpan, Span, SpanProcessor as OtelSpanProcessor } from "@opentelemetry/sdk-trace-base";
import type { ExporterSpanProcessorOptions } from "../types/index.js";
import type { ExporterRegistry } from "./exporterRegistry.js";
/**
* @description OpenTelemetry span processor that turns every observation span into `SpanData` and hands it to an `ExporterRegistry`, so one instrumentation feeds Langfuse, Datadog, Sentry and every other registered exporter. Spans that are not observations (health checks, auth, middleware, NeuroLink's helper spans), wrapper spans marked `langfuse.internal` and spans from other libraries are skipped and their children are re-parented onto the nearest exported ancestor. `shutdown()` shuts the registry's exporters down, as it always did, unless the processor was created to leave them running. Parent ids are read from OpenTelemetry SDK 2.x (`parentSpanContext`) and 1.x (`parentSpanId`) spans alike. At most `MAX_REMEMBERED_SPANS` open and ended spans are remembered for re-parenting; an ancestor of a span that is still open is kept past that limit. Delivery never blocks the span's thread, and a span that cannot be converted is skipped without throwing into the code that ended it.
*/
export declare class ExporterSpanProcessor implements OtelSpanProcessor {
private readonly registry;
private readonly shutsDownExporters;
private readonly open;
private readonly ended;
private readonly pins;
private evictionLogged;
/**
* @description Creates a processor bound to a registry.
* @param registry {ExporterRegistry} - Registry that receives every exported span.
* @param shutsDownExporters {boolean} - Whether `shutdown()` also shuts down the registry's exporters; defaults to `true`. Pass `false` for a host provider that is shut down and rebuilt while the exporters stay shared.
*/
constructor(registry: ExporterRegistry, shutsDownExporters?: boolean);
/**
* @description Copies the propagated Langfuse trace attributes (user, session, trace name, tags, metadata) from the parent context onto the new span, marks it for input and output redaction when a `setLangfuseContext` scope asked for `redactIO`, and remembers it until it ends.
* @param span {Span} - Span that just started.
* @param parentContext {Context} - Context the span was started in.
* @returns {void} Nothing.
*/
onStart(span: Span, parentContext: Context): void;
/**
* @description Exports an ended observation span without waiting for the exporters.
* @param span {ReadableSpan} - Span that just ended.
* @returns {void} Nothing.
*/
onEnd(span: ReadableSpan): void;
/**
* @description Flushes every exporter in the registry.
* @returns {Promise<void>} Resolves when all exporters have flushed.
*/
forceFlush(): Promise<void>;
/**
* @description Shuts down every exporter in the registry, or only flushes them when the processor was created to leave them running.
* @returns {Promise<void>} Resolves when the exporters have shut down or flushed.
*/
shutdown(): Promise<void>;
private contain;
private exportQuietly;
private hold;
private release;
private evictOldestOpen;
private remember;
private trimEnded;
private nearestExportedAncestor;
}
/**
* @description Creates a span processor that feeds NeuroLink's observation spans to an exporter registry. Add it to a host `TracerProvider` to deliver spans through the registered exporters (such as `LangfuseExporter`) instead of `LangfuseSpanProcessor`. Shutting that provider down shuts the registry's exporters down; pass `{ shutdownExporters: false }` to flush them and leave them running, so a provider the host rebuilds keeps exporting.
* @param registry {ExporterRegistry} - Registry to export to; defaults to the process-wide registry.
* @param options {ExporterSpanProcessorOptions} - `shutdownExporters` (default `true`) says whether the processor's `shutdown()` also shuts down the registry's exporters.
* @returns {ExporterSpanProcessor} A processor ready to be added to a TracerProvider.
* @example
* const provider = new NodeTracerProvider({ spanProcessors: [createExporterSpanProcessor()] });
* @example
* // A host provider that is shut down and rebuilt over the same exporters
* const processor = createExporterSpanProcessor(getExporterRegistry(), { shutdownExporters: false });
*/
export declare function createExporterSpanProcessor(registry?: ExporterRegistry, options?: ExporterSpanProcessorOptions): ExporterSpanProcessor;