@latitude-data/telemetry 0.0.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,152 +1,339 @@
1
- import * as _opentelemetry_api from '@opentelemetry/api';
2
- import { OTLPExporterBase, OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base';
3
- import { SpanExporter, ReadableSpan, SimpleSpanProcessor, SpanProcessor, BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
4
- import { SpanExporter as SpanExporter$1, SimpleSpanProcessor as SimpleSpanProcessor$1, BatchSpanProcessor as BatchSpanProcessor$1 } from '@opentelemetry/sdk-trace-node';
5
- import * as openai from 'openai';
1
+ import * as otel from '@opentelemetry/api';
2
+ import { TextMapPropagator } from '@opentelemetry/api';
3
+ import { SpanProcessor, ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-node';
4
+ import * as latitude from '@latitude-data/sdk';
5
+ import { z } from 'zod';
6
+ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
6
7
  import * as anthropic from '@anthropic-ai/sdk';
7
- import * as azure from '@azure/openai';
8
- import * as cohere from 'cohere-ai';
9
8
  import * as bedrock from '@aws-sdk/client-bedrock-runtime';
9
+ import * as azure from '@azure/openai';
10
10
  import * as aiplatform from '@google-cloud/aiplatform';
11
- import * as vertexAI from '@google-cloud/vertexai';
12
- import * as pinecone from '@pinecone-database/pinecone';
13
- import * as ChainsModule from 'langchain/chains';
14
- import * as AgentsModule from 'langchain/agents';
15
- import * as ToolsModule from 'langchain/tools';
16
- import * as RunnableModule from '@langchain/core/runnables';
17
- import * as VectorStoreModule from '@langchain/core/vectorstores';
11
+ import * as vertexai from '@google-cloud/vertexai';
12
+ import * as langchain_runnables from '@langchain/core/runnables';
13
+ import * as langchain_vectorstores from '@langchain/core/vectorstores';
14
+ import * as cohere from 'cohere-ai';
15
+ import * as langchain_agents from 'langchain/agents';
16
+ import * as langchain_chains from 'langchain/chains';
17
+ import * as langchain_tools from 'langchain/tools';
18
18
  import * as llamaindex from 'llamaindex';
19
- import * as chromadb from 'chromadb';
20
- import * as qdrant from '@qdrant/js-client-rest';
19
+ import * as openai from 'openai';
20
+ import * as togetherai from 'together-ai';
21
21
 
22
- interface OTLPHttpExporterConfig extends OTLPExporterConfigBase {
23
- apiKey: string;
24
- endpoint?: string;
22
+ interface RedactSpanProcessorOptions {
23
+ attributes: (string | RegExp)[];
24
+ mask?: (attribute: string, value: any) => string;
25
25
  }
26
- declare class LatitudeExporter extends OTLPExporterBase<any, any, any> implements SpanExporter {
27
- url: string;
28
- private headers;
29
- constructor(config: OTLPHttpExporterConfig);
30
- export(spans: ReadableSpan[], resultCallback: (result: any) => void): Promise<void>;
26
+ declare class RedactSpanProcessor implements SpanProcessor {
27
+ private options;
28
+ constructor(options: RedactSpanProcessorOptions);
29
+ onStart(_span: ReadableSpan, _context: otel.Context): void;
30
+ onEnd(span: ReadableSpan): void;
31
+ forceFlush(): Promise<void>;
31
32
  shutdown(): Promise<void>;
32
- onShutdown(): Promise<void>;
33
- onInit(): Promise<void>;
34
- send(spans: ReadableSpan[], onSuccess: () => void, onError: (error: Error) => void): Promise<void>;
35
- convert(spans: ReadableSpan[]): {
36
- resourceSpans: {
37
- resource: {
38
- attributes: {
39
- key: string;
40
- value: {
41
- stringValue?: string;
42
- intValue?: number;
43
- boolValue?: boolean;
44
- };
45
- }[];
46
- };
47
- scopeSpans: {
48
- spans: {
49
- traceId: string;
50
- spanId: string;
51
- parentSpanId: string | undefined;
52
- name: string;
53
- kind: _opentelemetry_api.SpanKind;
54
- startTimeUnixNano: string;
55
- endTimeUnixNano: string | undefined;
56
- attributes: {
57
- key: string;
58
- value: {
59
- stringValue?: string;
60
- intValue?: number;
61
- boolValue?: boolean;
62
- };
63
- }[];
64
- status: {
65
- code: _opentelemetry_api.SpanStatusCode;
66
- message: string | undefined;
67
- };
68
- events: {
69
- timeUnixNano: string;
70
- name: string;
71
- attributes: {
72
- key: string;
73
- value: {
74
- stringValue?: string;
75
- intValue?: number;
76
- boolValue?: boolean;
77
- };
78
- }[];
79
- }[];
80
- links: {
81
- traceId: string;
82
- spanId: string;
83
- attributes: {
84
- key: string;
85
- value: {
86
- stringValue?: string;
87
- intValue?: number;
88
- boolValue?: boolean;
89
- };
90
- }[];
91
- }[];
92
- }[];
93
- }[];
94
- }[];
95
- };
96
- getDefaultUrl(config: any): string;
97
- private get __defaultUrl();
98
- private convertAttributes;
99
- private convertAttributeValue;
33
+ private shouldRedact;
34
+ private redactAttributes;
100
35
  }
36
+ declare const DEFAULT_REDACT_SPAN_PROCESSOR: () => RedactSpanProcessor;
101
37
 
102
- declare class VercelSpanProcessor extends SimpleSpanProcessor implements SpanProcessor {
103
- onEnd(span: ReadableSpan): void;
38
+ declare enum SegmentSource {
39
+ API = "api",
40
+ Playground = "playground",
41
+ Evaluation = "evaluation",// Note: from prompts of llm evaluations
42
+ Experiment = "experiment",
43
+ User = "user",
44
+ SharedPrompt = "shared_prompt",
45
+ AgentAsTool = "agent_as_tool",// TODO(tracing): deprecated, use SegmentType.Document with DocumentType.Agent instead
46
+ EmailTrigger = "email_trigger",
47
+ ScheduledTrigger = "scheduled_trigger"
104
48
  }
105
- declare class VercelBatchSpanProcessor extends BatchSpanProcessor implements SpanProcessor {
106
- onEnd(span: ReadableSpan): void;
49
+ declare enum SegmentType {
50
+ Document = "document",
51
+ Step = "step"
107
52
  }
53
+ declare const segmentBaggageSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<z.objectUtil.extendShape<{
54
+ id: z.ZodString;
55
+ parentId: z.ZodOptional<z.ZodString>;
56
+ source: z.ZodNativeEnum<typeof SegmentSource>;
57
+ }, {
58
+ type: z.ZodLiteral<SegmentType.Document>;
59
+ data: z.ZodObject<{
60
+ logUuid: z.ZodOptional<z.ZodString>;
61
+ commitUuid: z.ZodString;
62
+ documentUuid: z.ZodString;
63
+ experimentUuid: z.ZodOptional<z.ZodString>;
64
+ externalId: z.ZodOptional<z.ZodString>;
65
+ }, "strip", z.ZodTypeAny, {
66
+ commitUuid: string;
67
+ documentUuid: string;
68
+ logUuid?: string | undefined;
69
+ experimentUuid?: string | undefined;
70
+ externalId?: string | undefined;
71
+ }, {
72
+ commitUuid: string;
73
+ documentUuid: string;
74
+ logUuid?: string | undefined;
75
+ experimentUuid?: string | undefined;
76
+ externalId?: string | undefined;
77
+ }>;
78
+ }>, "strip", z.ZodTypeAny, {
79
+ id: string;
80
+ type: SegmentType.Document;
81
+ data: {
82
+ commitUuid: string;
83
+ documentUuid: string;
84
+ logUuid?: string | undefined;
85
+ experimentUuid?: string | undefined;
86
+ externalId?: string | undefined;
87
+ };
88
+ source: SegmentSource;
89
+ parentId?: string | undefined;
90
+ }, {
91
+ id: string;
92
+ type: SegmentType.Document;
93
+ data: {
94
+ commitUuid: string;
95
+ documentUuid: string;
96
+ logUuid?: string | undefined;
97
+ experimentUuid?: string | undefined;
98
+ externalId?: string | undefined;
99
+ };
100
+ source: SegmentSource;
101
+ parentId?: string | undefined;
102
+ }>, z.ZodObject<z.objectUtil.extendShape<{
103
+ id: z.ZodString;
104
+ parentId: z.ZodOptional<z.ZodString>;
105
+ source: z.ZodNativeEnum<typeof SegmentSource>;
106
+ }, {
107
+ type: z.ZodLiteral<SegmentType.Step>;
108
+ data: z.ZodOptional<z.ZodUndefined>;
109
+ }>, "strip", z.ZodTypeAny, {
110
+ id: string;
111
+ type: SegmentType.Step;
112
+ source: SegmentSource;
113
+ data?: undefined;
114
+ parentId?: string | undefined;
115
+ }, {
116
+ id: string;
117
+ type: SegmentType.Step;
118
+ source: SegmentSource;
119
+ data?: undefined;
120
+ parentId?: string | undefined;
121
+ }>]>;
122
+ type SegmentBaggage<T extends SegmentType = SegmentType> = Extract<z.infer<typeof segmentBaggageSchema>, {
123
+ type: T;
124
+ }>;
108
125
 
109
- type IModules = {
110
- openAI?: typeof openai.OpenAI;
111
- anthropic?: typeof anthropic;
112
- azureOpenAI?: typeof azure;
113
- cohere?: typeof cohere;
114
- bedrock?: typeof bedrock;
115
- google_vertexai?: typeof vertexAI;
116
- google_aiplatform?: typeof aiplatform;
117
- pinecone?: typeof pinecone;
118
- langchain?: {
119
- chainsModule?: typeof ChainsModule;
120
- agentsModule?: typeof AgentsModule;
121
- toolsModule?: typeof ToolsModule;
122
- runnablesModule?: typeof RunnableModule;
123
- vectorStoreModule?: typeof VectorStoreModule;
124
- };
125
- llamaIndex?: typeof llamaindex;
126
- chromadb?: typeof chromadb;
127
- qdrant?: typeof qdrant;
126
+ declare const traceContextSchema: z.ZodObject<{
127
+ traceparent: z.ZodString;
128
+ tracestate: z.ZodOptional<z.ZodString>;
129
+ baggage: z.ZodOptional<z.ZodString>;
130
+ }, "strip", z.ZodTypeAny, {
131
+ traceparent: string;
132
+ tracestate?: string | undefined;
133
+ baggage?: string | undefined;
134
+ }, {
135
+ traceparent: string;
136
+ tracestate?: string | undefined;
137
+ baggage?: string | undefined;
138
+ }>;
139
+ type TraceContext = z.infer<typeof traceContextSchema>;
140
+ type TraceBaggage = {
141
+ segment: Pick<SegmentBaggage, 'id' | 'parentId'>;
142
+ segments: (SegmentBaggage & Pick<TraceContext, 'traceparent' | 'tracestate'> & {
143
+ paused?: boolean;
144
+ })[];
128
145
  };
129
- type SpanAttributes = {
146
+
147
+ type LatitudeInstrumentationOptions = {
148
+ module: typeof latitude.Latitude;
149
+ completions?: boolean;
150
+ };
151
+
152
+ type StartSpanOptions = {
130
153
  name?: string;
131
- metadata?: Record<string, unknown>;
132
- prompt?: {
133
- uuid: string;
134
- versionUuid?: string;
135
- parameters?: Record<string, unknown>;
154
+ attributes?: otel.Attributes;
155
+ };
156
+ type EndSpanOptions = {
157
+ attributes?: otel.Attributes;
158
+ };
159
+ type ErrorOptions = {
160
+ attributes?: otel.Attributes;
161
+ };
162
+ type StartToolSpanOptions = StartSpanOptions & {
163
+ name: string;
164
+ call: {
165
+ id: string;
166
+ arguments: Record<string, unknown>;
167
+ };
168
+ };
169
+ type EndToolSpanOptions = EndSpanOptions & {
170
+ result: {
171
+ value: unknown;
172
+ isError: boolean;
173
+ };
174
+ };
175
+ type StartCompletionSpanOptions = StartSpanOptions & {
176
+ provider: string;
177
+ model: string;
178
+ configuration: Record<string, unknown>;
179
+ input: Record<string, unknown>[];
180
+ };
181
+ type EndCompletionSpanOptions = EndSpanOptions & {
182
+ output: Record<string, unknown>[];
183
+ tokens: {
184
+ prompt: number;
185
+ cached: number;
186
+ reasoning: number;
187
+ completion: number;
136
188
  };
137
- distinctId?: string;
189
+ finishReason: string;
138
190
  };
139
- type LatitudeTelemetrySDKConfig = {
140
- exporter: SpanExporter$1;
141
- modules?: IModules;
191
+ type StartHttpSpanOptions = StartSpanOptions & {
192
+ request: {
193
+ method: string;
194
+ url: string;
195
+ headers: Record<string, string>;
196
+ body: string | Record<string, unknown>;
197
+ };
198
+ };
199
+ type EndHttpSpanOptions = EndSpanOptions & {
200
+ response: {
201
+ status: number;
202
+ headers: Record<string, string>;
203
+ body: string | Record<string, unknown>;
204
+ };
205
+ };
206
+ type SegmentOptions = {
207
+ attributes?: otel.Attributes;
208
+ baggage?: Record<string, otel.BaggageEntry>;
209
+ _internal?: {
210
+ id?: string;
211
+ source?: SegmentSource;
212
+ };
213
+ };
214
+ type PromptSegmentOptions = SegmentOptions & {
215
+ logUuid?: string;
216
+ versionUuid?: string;
217
+ promptUuid: string;
218
+ experimentUuid?: string;
219
+ externalId?: string;
220
+ template: string;
221
+ parameters?: Record<string, unknown>;
222
+ };
223
+
224
+ type TelemetryContext = otel.Context;
225
+ declare const BACKGROUND: () => otel.Context;
226
+ declare class ScopedTracerProvider implements otel.TracerProvider {
227
+ private readonly scope;
228
+ private readonly version;
229
+ private readonly provider;
230
+ constructor(scope: string, version: string, provider: otel.TracerProvider);
231
+ getTracer(_name: string, _version?: string, options?: otel.TracerOptions): otel.Tracer;
232
+ }
233
+ declare const DEFAULT_SPAN_EXPORTER: (apiKey: string) => OTLPTraceExporter;
234
+ declare enum Instrumentation {
235
+ Latitude = "latitude",
236
+ OpenAI = "openai",
237
+ Anthropic = "anthropic",
238
+ AzureOpenAI = "azure",
239
+ VercelAI = "vercelai",
240
+ VertexAI = "vertexai",
241
+ AIPlatform = "aiplatform",
242
+ Bedrock = "bedrock",
243
+ TogetherAI = "togetherai",
244
+ Cohere = "cohere",
245
+ Langchain = "langchain",
246
+ LlamaIndex = "llamaindex"
247
+ }
248
+ type TelemetryOptions = {
249
+ instrumentations?: {
250
+ [Instrumentation.Latitude]?: typeof latitude.Latitude | LatitudeInstrumentationOptions;
251
+ [Instrumentation.OpenAI]?: typeof openai.OpenAI;
252
+ [Instrumentation.Anthropic]?: typeof anthropic;
253
+ [Instrumentation.AzureOpenAI]?: typeof azure;
254
+ [Instrumentation.VercelAI]?: 'manual';
255
+ [Instrumentation.VertexAI]?: typeof vertexai;
256
+ [Instrumentation.AIPlatform]?: typeof aiplatform;
257
+ [Instrumentation.Bedrock]?: typeof bedrock;
258
+ [Instrumentation.TogetherAI]?: typeof togetherai.Together;
259
+ [Instrumentation.Cohere]?: typeof cohere;
260
+ [Instrumentation.Langchain]?: {
261
+ chainsModule: typeof langchain_chains;
262
+ agentsModule: typeof langchain_agents;
263
+ toolsModule: typeof langchain_tools;
264
+ vectorStoreModule: typeof langchain_vectorstores;
265
+ runnablesModule: typeof langchain_runnables;
266
+ };
267
+ [Instrumentation.LlamaIndex]?: typeof llamaindex;
268
+ };
142
269
  disableBatch?: boolean;
143
- processors?: (typeof SimpleSpanProcessor$1)[] | (typeof BatchSpanProcessor$1)[];
270
+ exporter?: SpanExporter;
271
+ processors?: SpanProcessor[];
272
+ propagators?: TextMapPropagator[];
144
273
  };
145
- declare class LatitudeTelemetrySDK {
146
- private exporter;
147
- constructor({ exporter, modules, disableBatch, processors, }: LatitudeTelemetrySDKConfig);
148
- private _init;
149
- span<T>(s: SpanAttributes, fn: (span: any) => T): Promise<T>;
274
+ declare class LatitudeTelemetry {
275
+ private options;
276
+ private provider;
277
+ private telemetry;
278
+ private instrumentations;
279
+ constructor(apiKey: string, options?: TelemetryOptions);
280
+ flush(): Promise<void>;
281
+ shutdown(): Promise<void>;
282
+ tracerProvider(instrumentation: Instrumentation): ScopedTracerProvider;
283
+ tracer(instrumentation: Instrumentation): otel.Tracer;
284
+ private initInstrumentations;
285
+ instrument(): void;
286
+ uninstrument(): void;
287
+ baggage(ctx: otel.Context | TraceContext): TraceBaggage | undefined;
288
+ pause(ctx: otel.Context): {
289
+ traceparent: string;
290
+ tracestate?: string | undefined;
291
+ baggage?: string | undefined;
292
+ };
293
+ resume(ctx: TraceContext): otel.Context;
294
+ restored(ctx: otel.Context): boolean;
295
+ restore(ctx: otel.Context): otel.Context;
296
+ tool(ctx: otel.Context, options: StartToolSpanOptions): {
297
+ context: otel.Context;
298
+ end: (options: EndToolSpanOptions) => void;
299
+ fail: (_error: Error, _options?: ErrorOptions) => void;
300
+ };
301
+ completion(ctx: otel.Context, options: StartCompletionSpanOptions): {
302
+ context: otel.Context;
303
+ end: (options: EndCompletionSpanOptions) => void;
304
+ fail: (_error: Error, _options?: ErrorOptions) => void;
305
+ };
306
+ embedding(ctx: otel.Context, options?: StartSpanOptions): {
307
+ context: otel.Context;
308
+ end: (_options?: EndSpanOptions) => void;
309
+ fail: (_error: Error, _options?: ErrorOptions) => void;
310
+ };
311
+ retrieval(ctx: otel.Context, options?: StartSpanOptions): {
312
+ context: otel.Context;
313
+ end: (_options?: EndSpanOptions) => void;
314
+ fail: (_error: Error, _options?: ErrorOptions) => void;
315
+ };
316
+ reranking(ctx: otel.Context, options?: StartSpanOptions): {
317
+ context: otel.Context;
318
+ end: (_options?: EndSpanOptions) => void;
319
+ fail: (_error: Error, _options?: ErrorOptions) => void;
320
+ };
321
+ http(ctx: otel.Context, options: StartHttpSpanOptions): {
322
+ context: otel.Context;
323
+ end: (options: EndHttpSpanOptions) => void;
324
+ fail: (_error: Error, _options?: ErrorOptions) => void;
325
+ };
326
+ prompt(ctx: otel.Context, options: PromptSegmentOptions): {
327
+ context: otel.Context;
328
+ end: (_options?: EndSpanOptions) => void;
329
+ fail: (_error: Error, _options?: ErrorOptions) => void;
330
+ };
331
+ step(ctx: otel.Context, options?: SegmentOptions): {
332
+ context: otel.Context;
333
+ end: (_options?: EndSpanOptions) => void;
334
+ fail: (_error: Error, _options?: ErrorOptions) => void;
335
+ };
150
336
  }
151
337
 
152
- export { LatitudeExporter, LatitudeTelemetrySDK, type LatitudeTelemetrySDKConfig, VercelBatchSpanProcessor, VercelSpanProcessor };
338
+ export { BACKGROUND, DEFAULT_REDACT_SPAN_PROCESSOR, DEFAULT_SPAN_EXPORTER, Instrumentation, LatitudeTelemetry, RedactSpanProcessor };
339
+ export type { EndCompletionSpanOptions, EndHttpSpanOptions, EndSpanOptions, EndToolSpanOptions, ErrorOptions, PromptSegmentOptions, RedactSpanProcessorOptions, SegmentOptions, StartCompletionSpanOptions, StartHttpSpanOptions, StartSpanOptions, StartToolSpanOptions, TelemetryContext, TelemetryOptions };