@latitude-data/telemetry 1.0.4 → 1.1.1

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,7 +1,8 @@
1
1
  import * as otel from '@opentelemetry/api';
2
2
  import { TextMapPropagator } from '@opentelemetry/api';
3
- import { SpanProcessor, ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-node';
3
+ import { SpanProcessor, ReadableSpan, SpanExporter, NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
4
4
  import * as latitude from '@latitude-data/sdk';
5
+ import { Latitude } from '@latitude-data/sdk';
5
6
  import { z } from 'zod';
6
7
  import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
7
8
 
@@ -21,8 +22,14 @@ declare class RedactSpanProcessor implements SpanProcessor {
21
22
  }
22
23
  declare const DEFAULT_REDACT_SPAN_PROCESSOR: () => RedactSpanProcessor;
23
24
 
25
+ interface BaseInstrumentation {
26
+ isEnabled(): boolean;
27
+ enable(): void;
28
+ disable(): void;
29
+ }
30
+
24
31
  type LatitudeInstrumentationOptions = {
25
- module: typeof latitude.Latitude;
32
+ module: typeof Latitude;
26
33
  completions?: boolean;
27
34
  };
28
35
 
@@ -39,7 +46,8 @@ declare enum LogSources {
39
46
  SharedPrompt = "shared_prompt",
40
47
  ShadowTest = "shadow_test",
41
48
  ABTestChallenger = "ab_test_challenger",
42
- User = "user"
49
+ User = "user",
50
+ Optimization = "optimization"
43
51
  }
44
52
 
45
53
  declare const traceContextSchema: z.ZodObject<{
@@ -75,21 +83,21 @@ type EndToolSpanOptions = EndSpanOptions & {
75
83
  type StartCompletionSpanOptions = StartSpanOptions & {
76
84
  provider: string;
77
85
  model: string;
78
- configuration: Record<string, unknown>;
79
- input: Record<string, unknown>[];
86
+ configuration?: Record<string, unknown>;
87
+ input?: Record<string, unknown>[];
80
88
  versionUuid?: string;
81
89
  promptUuid?: string;
82
90
  experimentUuid?: string;
83
91
  };
84
92
  type EndCompletionSpanOptions = EndSpanOptions & {
85
- output: Record<string, unknown>[];
86
- tokens: {
87
- prompt: number;
88
- cached: number;
89
- reasoning: number;
90
- completion: number;
91
- };
92
- finishReason: string;
93
+ output?: Record<string, unknown>[];
94
+ tokens?: {
95
+ prompt?: number;
96
+ cached?: number;
97
+ reasoning?: number;
98
+ completion?: number;
99
+ };
100
+ finishReason?: string;
93
101
  };
94
102
  type StartHttpSpanOptions = StartSpanOptions & {
95
103
  request: {
@@ -107,10 +115,10 @@ type EndHttpSpanOptions = EndSpanOptions & {
107
115
  };
108
116
  };
109
117
  type PromptSpanOptions = StartSpanOptions & {
110
- documentLogUuid?: string;
118
+ documentLogUuid: string;
111
119
  versionUuid?: string;
112
120
  promptUuid: string;
113
- projectId?: string;
121
+ projectId?: number;
114
122
  experimentUuid?: string;
115
123
  testDeploymentId?: number;
116
124
  externalId?: string;
@@ -118,9 +126,147 @@ type PromptSpanOptions = StartSpanOptions & {
118
126
  parameters?: Record<string, unknown>;
119
127
  source?: LogSources;
120
128
  };
129
+ type ChatSpanOptions = StartSpanOptions & {
130
+ documentLogUuid: string;
131
+ previousTraceId: string;
132
+ source?: LogSources;
133
+ versionUuid?: string;
134
+ promptUuid?: string;
135
+ };
136
+ type ExternalSpanOptions = StartSpanOptions & {
137
+ promptUuid: string;
138
+ documentLogUuid: string;
139
+ source?: LogSources;
140
+ versionUuid?: string;
141
+ externalId?: string;
142
+ };
143
+ type CaptureOptions = StartSpanOptions & {
144
+ path: string;
145
+ projectId: number;
146
+ versionUuid?: string;
147
+ conversationUuid?: string;
148
+ };
149
+ declare class ManualInstrumentation implements BaseInstrumentation {
150
+ private enabled;
151
+ private readonly tracer;
152
+ constructor(tracer: otel.Tracer);
153
+ isEnabled(): boolean;
154
+ enable(): void;
155
+ disable(): void;
156
+ resume(ctx: TraceContext): otel.Context;
157
+ private capitalize;
158
+ private toCamelCase;
159
+ private toSnakeCase;
160
+ private toKebabCase;
161
+ private error;
162
+ private span;
163
+ tool(ctx: otel.Context, options: StartToolSpanOptions): {
164
+ context: otel.Context;
165
+ end: (options: EndToolSpanOptions) => void;
166
+ fail: (_error: Error, _options?: ErrorOptions) => void;
167
+ };
168
+ private attribifyMessageToolCalls;
169
+ private attribifyMessageContent;
170
+ private attribifyMessages;
171
+ private attribifyConfiguration;
172
+ completion(ctx: otel.Context, options: StartCompletionSpanOptions): {
173
+ context: otel.Context;
174
+ end: (options?: EndCompletionSpanOptions) => void;
175
+ fail: (_error: Error, _options?: ErrorOptions) => void;
176
+ };
177
+ embedding(ctx: otel.Context, options?: StartSpanOptions): {
178
+ context: otel.Context;
179
+ end: (_options?: EndSpanOptions) => void;
180
+ fail: (_error: Error, _options?: ErrorOptions) => void;
181
+ };
182
+ private attribifyHeaders;
183
+ http(ctx: otel.Context, options: StartHttpSpanOptions): {
184
+ context: otel.Context;
185
+ end: (options: EndHttpSpanOptions) => void;
186
+ fail: (_error: Error, _options?: ErrorOptions) => void;
187
+ };
188
+ prompt(ctx: otel.Context, { documentLogUuid, versionUuid, promptUuid, projectId, experimentUuid, testDeploymentId, externalId, template, parameters, name, source, ...rest }: PromptSpanOptions): {
189
+ context: otel.Context;
190
+ end: (_options?: EndSpanOptions) => void;
191
+ fail: (_error: Error, _options?: ErrorOptions) => void;
192
+ };
193
+ chat(ctx: otel.Context, { documentLogUuid, previousTraceId, source, name, versionUuid, promptUuid, ...rest }: ChatSpanOptions): {
194
+ context: otel.Context;
195
+ end: (_options?: EndSpanOptions) => void;
196
+ fail: (_error: Error, _options?: ErrorOptions) => void;
197
+ };
198
+ external(ctx: otel.Context, { promptUuid, documentLogUuid, source, versionUuid, externalId, name, ...rest }: ExternalSpanOptions): {
199
+ context: otel.Context;
200
+ end: (_options?: EndSpanOptions) => void;
201
+ fail: (_error: Error, _options?: ErrorOptions) => void;
202
+ };
203
+ unresolvedExternal(ctx: otel.Context, { path, projectId, versionUuid, conversationUuid, name, ...rest }: CaptureOptions): {
204
+ context: otel.Context;
205
+ end: (_options?: EndSpanOptions) => void;
206
+ fail: (_error: Error, _options?: ErrorOptions) => void;
207
+ };
208
+ }
121
209
 
122
210
  type TelemetryContext = otel.Context;
123
211
  declare const BACKGROUND: () => otel.Context;
212
+ declare class SpanFactory {
213
+ private telemetry;
214
+ constructor(telemetry: ManualInstrumentation);
215
+ tool(options: StartToolSpanOptions, ctx?: TelemetryContext): {
216
+ context: otel.Context;
217
+ end: (options: EndToolSpanOptions) => void;
218
+ fail: (_error: Error, _options?: ErrorOptions) => void;
219
+ };
220
+ completion(options: StartCompletionSpanOptions, ctx?: TelemetryContext): {
221
+ context: otel.Context;
222
+ end: (options?: EndCompletionSpanOptions) => void;
223
+ fail: (_error: Error, _options?: ErrorOptions) => void;
224
+ };
225
+ embedding(options?: StartSpanOptions, ctx?: TelemetryContext): {
226
+ context: otel.Context;
227
+ end: (_options?: EndSpanOptions) => void;
228
+ fail: (_error: Error, _options?: ErrorOptions) => void;
229
+ };
230
+ http(options: StartHttpSpanOptions, ctx?: TelemetryContext): {
231
+ context: otel.Context;
232
+ end: (options: EndHttpSpanOptions) => void;
233
+ fail: (_error: Error, _options?: ErrorOptions) => void;
234
+ };
235
+ prompt(options: PromptSpanOptions, ctx?: TelemetryContext): {
236
+ context: otel.Context;
237
+ end: (_options?: EndSpanOptions) => void;
238
+ fail: (_error: Error, _options?: ErrorOptions) => void;
239
+ };
240
+ chat(options: ChatSpanOptions, ctx?: TelemetryContext): {
241
+ context: otel.Context;
242
+ end: (_options?: EndSpanOptions) => void;
243
+ fail: (_error: Error, _options?: ErrorOptions) => void;
244
+ };
245
+ external(options: ExternalSpanOptions, ctx?: TelemetryContext): {
246
+ context: otel.Context;
247
+ end: (_options?: EndSpanOptions) => void;
248
+ fail: (_error: Error, _options?: ErrorOptions) => void;
249
+ };
250
+ }
251
+ declare class ContextManager {
252
+ private telemetry;
253
+ constructor(telemetry: ManualInstrumentation);
254
+ resume(ctx: TraceContext): otel.Context;
255
+ active(): otel.Context;
256
+ }
257
+ declare class InstrumentationManager {
258
+ private instrumentations;
259
+ constructor(instrumentations: BaseInstrumentation[]);
260
+ enable(): void;
261
+ disable(): void;
262
+ }
263
+ declare class TracerManager {
264
+ private nodeProvider;
265
+ private scopeVersion;
266
+ constructor(nodeProvider: NodeTracerProvider, scopeVersion: string);
267
+ get(scope: Instrumentation): otel.Tracer;
268
+ provider(scope: Instrumentation): ScopedTracerProvider;
269
+ }
124
270
  declare class ScopedTracerProvider implements otel.TracerProvider {
125
271
  private readonly scope;
126
272
  private readonly version;
@@ -163,59 +309,19 @@ type TelemetryOptions = {
163
309
  };
164
310
  declare class LatitudeTelemetry {
165
311
  private options;
166
- private provider;
167
- private telemetry;
168
- private instrumentations;
312
+ private nodeProvider;
313
+ private manualInstrumentation;
314
+ private instrumentationsList;
315
+ readonly span: SpanFactory;
316
+ readonly context: ContextManager;
317
+ readonly instrumentation: InstrumentationManager;
318
+ readonly tracer: TracerManager;
169
319
  constructor(apiKey: string, options?: TelemetryOptions);
170
320
  flush(): Promise<void>;
171
321
  shutdown(): Promise<void>;
172
- tracerProvider(instrumentation: Instrumentation): ScopedTracerProvider;
173
- tracer(instrumentation: Instrumentation): otel.Tracer;
174
322
  private initInstrumentations;
175
- instrument(): void;
176
- uninstrument(): void;
177
- resume(ctx: TraceContext): otel.Context;
178
- tool(ctx: otel.Context, options: StartToolSpanOptions): {
179
- context: otel.Context;
180
- end: (options: EndToolSpanOptions) => void;
181
- fail: (_error: Error, _options?: ErrorOptions) => void;
182
- };
183
- completion(ctx: otel.Context, options: StartCompletionSpanOptions): {
184
- context: otel.Context;
185
- end: (options: EndCompletionSpanOptions) => void;
186
- fail: (_error: Error, _options?: ErrorOptions) => void;
187
- };
188
- embedding(ctx: otel.Context, options?: StartSpanOptions): {
189
- context: otel.Context;
190
- end: (_options?: EndSpanOptions) => void;
191
- fail: (_error: Error, _options?: ErrorOptions) => void;
192
- };
193
- retrieval(ctx: otel.Context, options?: StartSpanOptions): {
194
- context: otel.Context;
195
- end: (_options?: EndSpanOptions) => void;
196
- fail: (_error: Error, _options?: ErrorOptions) => void;
197
- };
198
- reranking(ctx: otel.Context, options?: StartSpanOptions): {
199
- context: otel.Context;
200
- end: (_options?: EndSpanOptions) => void;
201
- fail: (_error: Error, _options?: ErrorOptions) => void;
202
- };
203
- http(ctx: otel.Context, options: StartHttpSpanOptions): {
204
- context: otel.Context;
205
- end: (options: EndHttpSpanOptions) => void;
206
- fail: (_error: Error, _options?: ErrorOptions) => void;
207
- };
208
- prompt(ctx: otel.Context, options: PromptSpanOptions): {
209
- context: otel.Context;
210
- end: (_options?: EndSpanOptions) => void;
211
- fail: (_error: Error, _options?: ErrorOptions) => void;
212
- };
213
- step(ctx: otel.Context, options?: StartSpanOptions): {
214
- context: otel.Context;
215
- end: (_options?: EndSpanOptions) => void;
216
- fail: (_error: Error, _options?: ErrorOptions) => void;
217
- };
323
+ capture<T>(options: CaptureOptions, fn: (ctx: TelemetryContext) => T | Promise<T>): Promise<T>;
218
324
  }
219
325
 
220
326
  export { BACKGROUND, DEFAULT_REDACT_SPAN_PROCESSOR, DEFAULT_SPAN_EXPORTER, Instrumentation, LatitudeTelemetry, RedactSpanProcessor };
221
- export type { EndCompletionSpanOptions, EndHttpSpanOptions, EndSpanOptions, EndToolSpanOptions, ErrorOptions, PromptSpanOptions as PromptSegmentOptions, RedactSpanProcessorOptions, StartCompletionSpanOptions, StartHttpSpanOptions, StartSpanOptions, StartToolSpanOptions, TelemetryContext, TelemetryOptions };
327
+ export type { CaptureOptions, ChatSpanOptions, EndCompletionSpanOptions, EndHttpSpanOptions, EndSpanOptions, EndToolSpanOptions, ErrorOptions, ExternalSpanOptions, PromptSpanOptions as PromptSegmentOptions, RedactSpanProcessorOptions, StartCompletionSpanOptions, StartHttpSpanOptions, StartSpanOptions, StartToolSpanOptions, TelemetryContext, TelemetryOptions };