/** * {@link LangSmithPlugin} — the single object a user adds to their Temporal * `Client` and `Worker` to get LangSmith tracing across workflow / activity / * child-workflow / Nexus boundaries with no changes to their existing * `traceable` instrumentation. * * The plugin wires four things: * 1. a **client interceptor** that propagates trace context out of any * `start` / `signal` / `query` / `update` call; * 2. **activity + Nexus inbound interceptors** that reconstruct the trace and * install it as the active run (so body `traceable` calls nest correctly); * 3. the **workflow interceptor module** (loaded into the workflow bundle) plus * a bundle-time global carrying the plugin config; and * 4. the **LangSmith sink** that performs the actual out-of-isolate emission. * * On worker shutdown it flushes the LangSmith client so in-flight traces are * not lost. * * @module */ import { Client, type AgentAddress } from 'langsmith'; import { SimplePlugin } from '@temporalio/plugin'; import type { ClientOptions } from '@temporalio/client'; import type { BundleOptions, ReplayWorkerOptions, Worker, WorkerOptions } from '@temporalio/worker'; /** * Options for {@link LangSmithPlugin}. * * Secrets (the LangSmith API key) are never accepted here as plaintext and * never cross a Temporal boundary — supply a pre-constructed {@link Client} * (which reads `LANGSMITH_API_KEY` from the worker/client process env) or let * the plugin construct a default client from the environment. */ export interface LangSmithPluginOptions { /** * The LangSmith client runs are emitted to. Defaults to `new Client()`, which * reads `LANGSMITH_API_KEY` / `LANGSMITH_ENDPOINT` from the process * environment. Lives only in the worker/client process — never serialized. */ client?: Client; /** Default LangSmith project for new root traces. An inherited destination takes precedence. */ projectName?: string; /** Agent/environment destination, mutually exclusive with projectName. LangSmith beta. */ address?: AgentAddress; /** * When `true`, emit first-class runs for Temporal operations themselves * (`StartWorkflow:`, `RunActivity:`, `HandleSignal:`, …) in addition to the * user's `traceable` runs. When `false` (default), only the user's * `traceable` runs are emitted — trace context still propagates across * boundaries so they nest correctly. */ addTemporalRuns?: boolean; /** Tags attached to every run the plugin emits. */ tags?: string[]; /** Metadata merged into every run the plugin emits (credential keys scrubbed). */ metadata?: Record; } /** * Temporal plugin that adds LangSmith observability to a Client + Worker. * * @example * ```ts * import { traceable } from 'langsmith/traceable'; * import { LangSmithPlugin } from '@temporalio/langsmith'; * * const plugin = new LangSmithPlugin({ addTemporalRuns: true }); * const worker = await Worker.create({ workflowsPath, taskQueue: 'tq', plugins: [plugin] }); * ``` */ export declare class LangSmithPlugin extends SimplePlugin { /** The package version, reported in worker heartbeats. */ readonly version: string; private readonly client; private readonly emitter; private readonly workflowConfig; private readonly drains; private readonly workflowInterceptorModule; private readonly asyncHooksShimModule; constructor(options?: LangSmithPluginOptions); configureClient(options: ClientOptions): ClientOptions; configureWorker(options: WorkerOptions): WorkerOptions; configureReplayWorker(options: ReplayWorkerOptions): ReplayWorkerOptions; private withLangSmithWorker; configureBundler(options: BundleOptions): BundleOptions; /** * Flush the LangSmith client on worker shutdown so traces that were emitted * just before exit are delivered. Wraps the worker run loop and flushes in a * `finally`, swallowing flush errors (shutdown must not fail on telemetry). */ runWorker(worker: Worker, next: (worker: Worker) => Promise): Promise; private flush; }