@elastic/opentelemetry-instrumentation-openai
Version:
OpenTelemetry instrumentation for the `openai` OpenAI client library
55 lines • 2.79 kB
TypeScript
import type { Attributes, Context, Span } from '@opentelemetry/api';
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
import { OpenAIInstrumentationConfig } from './types';
export declare class OpenAIInstrumentation extends InstrumentationBase<OpenAIInstrumentationConfig> {
private _genaiClientOperationDuration;
private _genaiClientTokenUsage;
constructor(config?: {});
setConfig(config?: OpenAIInstrumentationConfig): void;
protected init(): InstrumentationNodeModuleDefinition[];
_updateMetricInstruments(): void;
_getPatchedChatCompletionsCreate(): (original: (...args: unknown[]) => any) => (this: any, ...args: unknown[]) => any;
/**
* Start a span for this chat-completion API call. This also emits log events
* as appropriate for the request params.
*
* @param {import('openai').OpenAI.ChatCompletionCreateParams} params
*/
_startChatCompletionsSpan(params: any, // eslint-disable-line @typescript-eslint/no-explicit-any
config: OpenAIInstrumentationConfig, baseURL: string | undefined): {
span: Span;
ctx: Context;
commonAttrs: Attributes;
};
/**
* This wraps an instance of a `openai/streaming.Stream.iterator()`, an
* async iterator. It should yield the chunks unchanged, and gather telemetry
* data from those chunks, then end the span.
*
* @param {OpenAIInstrumentationConfig} config
*/
_onChatCompletionsStreamIterator(streamIter: AsyncIterator<any>, span: Span, startNow: number, config: OpenAIInstrumentationConfig, commonAttrs: Attributes, ctx: Context): AsyncGenerator<any, void, unknown>;
/**
* @param {import('openai').OpenAI.ChatCompletion} result
* @param {OpenAIInstrumentationConfig} config
*/
_onChatCompletionsCreateResult(span: Span, startNow: number, commonAttrs: Attributes, result: any, config: OpenAIInstrumentationConfig, ctx: Context): void;
_createAPIPromiseRejectionHandler(startNow: number, span: Span, commonAttrs: Attributes): (err: Error) => void;
_getPatchedEmbeddingsCreate(): (original: any) => (this: any, ...args: unknown[]) => any;
/**
* Start a span for this chat-completion API call. This also emits log events
* as appropriate for the request params.
*
* @param {OpenAIInstrumentationConfig} config
*/
_startEmbeddingsSpan(params: any, baseURL: string | undefined): {
span: Span;
ctx: Context;
commonAttrs: Attributes;
};
/**
* @param {import('openai').OpenAI.CreateEmbeddingResponse} result
*/
_onEmbeddingsCreateResult(span: Span, startNow: number, commonAttrs: Attributes, result: any): void;
}
//# sourceMappingURL=instrumentation.d.ts.map