@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
85 lines (84 loc) • 3.32 kB
TypeScript
import { TracingProcessor } from './processor';
import { Span, SpanData, SpanOptions } from './spans';
import { Trace, TraceOptions } from './traces';
import { type TracingIdGenerator } from './utils';
export type CreateSpanOptions<TData extends SpanData> = Omit<SpanOptions<TData>, 'traceId'> & {
traceId?: string;
disabled?: boolean;
};
export type TraceProviderOptions = {
idGenerator?: Partial<TracingIdGenerator>;
};
export declare class TraceProvider {
#private;
constructor(options?: TraceProviderOptions);
/**
* Add a processor to the list of processors. Each processor will receive all traces/spans.
*
* @param processor - The processor to add.
*/
registerProcessor(processor: TracingProcessor): void;
/**
* Set the list of processors. This will replace any existing processors.
*
* @param processors - The list of processors to set.
*/
setProcessors(processors: TracingProcessor[]): void;
/**
* Get the current trace.
*
* @returns The current trace.
*/
getCurrentTrace(): Trace | null;
getCurrentSpan(): Span<any> | null;
setDisabled(disabled: boolean): void;
setIdGenerator(idGenerator?: Partial<TracingIdGenerator>): void;
/**
* Generate a new trace ID.
*
* Override this in custom providers to take precedence over configured ID generators.
*/
generateTraceId(): string;
/**
* Generate a new span ID.
*
* Override this in custom providers to take precedence over configured ID generators.
*/
generateSpanId(): string;
startExportLoop(): void;
/**
* Dispatches a completed trace lifecycle to all registered processors.
*
* This is useful when an integration receives a trace that was started and
* ended outside this process and needs to fan out the lifecycle without
* mutating the trace state.
*/
dispatchTrace(trace: Trace): Promise<void>;
/**
* Dispatches a completed span lifecycle to all registered processors.
*
* This is useful when an integration receives a span that already has
* lifecycle timestamps and needs to fan out the lifecycle without mutating
* those timestamps.
*/
dispatchSpan<TSpanData extends SpanData>(span: Span<TSpanData>): Promise<void>;
/**
* Dispatches a span start event to all registered processors.
*
* This is useful when an integration receives a span start outside this
* process and needs to fan out the start without mutating the span state.
*/
dispatchSpanStart<TSpanData extends SpanData>(span: Span<TSpanData>): Promise<void>;
/**
* Dispatches a span end event to all registered processors.
*
* This is useful when an integration receives a span end outside this process
* and needs to fan out the end without mutating the span state.
*/
dispatchSpanEnd<TSpanData extends SpanData>(span: Span<TSpanData>): Promise<void>;
createTrace(traceOptions: TraceOptions): Trace;
createSpan<TSpanData extends SpanData>(spanOptions: CreateSpanOptions<TSpanData>, parent?: Span<any> | Trace): Span<TSpanData>;
shutdown(timeout?: number): Promise<void>;
forceFlush(): Promise<void>;
}
export declare function getGlobalTraceProvider(): TraceProvider;