@latitude-data/telemetry 1.0.4 → 1.1.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,6 +1,6 @@
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
5
  import { z } from 'zod';
6
6
  import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
@@ -21,6 +21,12 @@ declare class RedactSpanProcessor implements SpanProcessor {
21
21
  }
22
22
  declare const DEFAULT_REDACT_SPAN_PROCESSOR: () => RedactSpanProcessor;
23
23
 
24
+ interface BaseInstrumentation {
25
+ isEnabled(): boolean;
26
+ enable(): void;
27
+ disable(): void;
28
+ }
29
+
24
30
  type LatitudeInstrumentationOptions = {
25
31
  module: typeof latitude.Latitude;
26
32
  completions?: boolean;
@@ -75,21 +81,21 @@ type EndToolSpanOptions = EndSpanOptions & {
75
81
  type StartCompletionSpanOptions = StartSpanOptions & {
76
82
  provider: string;
77
83
  model: string;
78
- configuration: Record<string, unknown>;
79
- input: Record<string, unknown>[];
84
+ configuration?: Record<string, unknown>;
85
+ input?: Record<string, unknown>[];
80
86
  versionUuid?: string;
81
87
  promptUuid?: string;
82
88
  experimentUuid?: string;
83
89
  };
84
90
  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;
91
+ output?: Record<string, unknown>[];
92
+ tokens?: {
93
+ prompt?: number;
94
+ cached?: number;
95
+ reasoning?: number;
96
+ completion?: number;
97
+ };
98
+ finishReason?: string;
93
99
  };
94
100
  type StartHttpSpanOptions = StartSpanOptions & {
95
101
  request: {
@@ -107,10 +113,10 @@ type EndHttpSpanOptions = EndSpanOptions & {
107
113
  };
108
114
  };
109
115
  type PromptSpanOptions = StartSpanOptions & {
110
- documentLogUuid?: string;
116
+ documentLogUuid: string;
111
117
  versionUuid?: string;
112
118
  promptUuid: string;
113
- projectId?: string;
119
+ projectId?: number;
114
120
  experimentUuid?: string;
115
121
  testDeploymentId?: number;
116
122
  externalId?: string;
@@ -118,9 +124,175 @@ type PromptSpanOptions = StartSpanOptions & {
118
124
  parameters?: Record<string, unknown>;
119
125
  source?: LogSources;
120
126
  };
127
+ type ChatSpanOptions = StartSpanOptions & {
128
+ documentLogUuid: string;
129
+ previousTraceId: string;
130
+ source?: LogSources;
131
+ };
132
+ type ExternalSpanOptions = StartSpanOptions & {
133
+ promptUuid: string;
134
+ documentLogUuid: string;
135
+ source?: LogSources;
136
+ versionUuid?: string;
137
+ externalId?: string;
138
+ };
139
+ type CaptureOptions = StartSpanOptions & {
140
+ path: string;
141
+ projectId: number;
142
+ versionUuid?: string;
143
+ conversationUuid?: string;
144
+ };
145
+ declare class ManualInstrumentation implements BaseInstrumentation {
146
+ private enabled;
147
+ private readonly tracer;
148
+ constructor(tracer: otel.Tracer);
149
+ isEnabled(): boolean;
150
+ enable(): void;
151
+ disable(): void;
152
+ resume(ctx: TraceContext): otel.Context;
153
+ private capitalize;
154
+ private toCamelCase;
155
+ private toSnakeCase;
156
+ private toKebabCase;
157
+ private error;
158
+ private span;
159
+ tool(ctx: otel.Context, options: StartToolSpanOptions): {
160
+ context: otel.Context;
161
+ end: (options: EndToolSpanOptions) => void;
162
+ fail: (_error: Error, _options?: ErrorOptions) => void;
163
+ };
164
+ private attribifyMessageToolCalls;
165
+ private attribifyMessageContent;
166
+ private attribifyMessages;
167
+ private attribifyConfiguration;
168
+ completion(ctx: otel.Context, options: StartCompletionSpanOptions): {
169
+ context: otel.Context;
170
+ end: (options?: EndCompletionSpanOptions) => void;
171
+ fail: (_error: Error, _options?: ErrorOptions) => void;
172
+ };
173
+ embedding(ctx: otel.Context, options?: StartSpanOptions): {
174
+ context: otel.Context;
175
+ end: (_options?: EndSpanOptions) => void;
176
+ fail: (_error: Error, _options?: ErrorOptions) => void;
177
+ };
178
+ retrieval(ctx: otel.Context, options?: StartSpanOptions): {
179
+ context: otel.Context;
180
+ end: (_options?: EndSpanOptions) => void;
181
+ fail: (_error: Error, _options?: ErrorOptions) => void;
182
+ };
183
+ reranking(ctx: otel.Context, options?: StartSpanOptions): {
184
+ context: otel.Context;
185
+ end: (_options?: EndSpanOptions) => void;
186
+ fail: (_error: Error, _options?: ErrorOptions) => void;
187
+ };
188
+ private attribifyHeaders;
189
+ http(ctx: otel.Context, options: StartHttpSpanOptions): {
190
+ context: otel.Context;
191
+ end: (options: EndHttpSpanOptions) => void;
192
+ fail: (_error: Error, _options?: ErrorOptions) => void;
193
+ };
194
+ prompt(ctx: otel.Context, { documentLogUuid, versionUuid, promptUuid, projectId, experimentUuid, testDeploymentId, externalId, template, parameters, name, source, ...rest }: PromptSpanOptions): {
195
+ context: otel.Context;
196
+ end: (_options?: EndSpanOptions) => void;
197
+ fail: (_error: Error, _options?: ErrorOptions) => void;
198
+ };
199
+ step(ctx: otel.Context, options?: StartSpanOptions): {
200
+ context: otel.Context;
201
+ end: (_options?: EndSpanOptions) => void;
202
+ fail: (_error: Error, _options?: ErrorOptions) => void;
203
+ };
204
+ chat(ctx: otel.Context, { documentLogUuid, previousTraceId, source, name, ...rest }: ChatSpanOptions): {
205
+ context: otel.Context;
206
+ end: (_options?: EndSpanOptions) => void;
207
+ fail: (_error: Error, _options?: ErrorOptions) => void;
208
+ };
209
+ external(ctx: otel.Context, { promptUuid, documentLogUuid, source, versionUuid, externalId, name, ...rest }: ExternalSpanOptions): {
210
+ context: otel.Context;
211
+ end: (_options?: EndSpanOptions) => void;
212
+ fail: (_error: Error, _options?: ErrorOptions) => void;
213
+ };
214
+ unresolvedExternal(ctx: otel.Context, { path, projectId, versionUuid, conversationUuid, name, ...rest }: CaptureOptions): {
215
+ context: otel.Context;
216
+ end: (_options?: EndSpanOptions) => void;
217
+ fail: (_error: Error, _options?: ErrorOptions) => void;
218
+ };
219
+ }
121
220
 
122
221
  type TelemetryContext = otel.Context;
123
222
  declare const BACKGROUND: () => otel.Context;
223
+ declare class SpanFactory {
224
+ private telemetry;
225
+ constructor(telemetry: ManualInstrumentation);
226
+ tool(options: StartToolSpanOptions, ctx?: TelemetryContext): {
227
+ context: otel.Context;
228
+ end: (options: EndToolSpanOptions) => void;
229
+ fail: (_error: Error, _options?: ErrorOptions) => void;
230
+ };
231
+ completion(options: StartCompletionSpanOptions, ctx?: TelemetryContext): {
232
+ context: otel.Context;
233
+ end: (options?: EndCompletionSpanOptions) => void;
234
+ fail: (_error: Error, _options?: ErrorOptions) => void;
235
+ };
236
+ embedding(options?: StartSpanOptions, ctx?: TelemetryContext): {
237
+ context: otel.Context;
238
+ end: (_options?: EndSpanOptions) => void;
239
+ fail: (_error: Error, _options?: ErrorOptions) => void;
240
+ };
241
+ retrieval(options?: StartSpanOptions, ctx?: TelemetryContext): {
242
+ context: otel.Context;
243
+ end: (_options?: EndSpanOptions) => void;
244
+ fail: (_error: Error, _options?: ErrorOptions) => void;
245
+ };
246
+ reranking(options?: StartSpanOptions, ctx?: TelemetryContext): {
247
+ context: otel.Context;
248
+ end: (_options?: EndSpanOptions) => void;
249
+ fail: (_error: Error, _options?: ErrorOptions) => void;
250
+ };
251
+ http(options: StartHttpSpanOptions, ctx?: TelemetryContext): {
252
+ context: otel.Context;
253
+ end: (options: EndHttpSpanOptions) => void;
254
+ fail: (_error: Error, _options?: ErrorOptions) => void;
255
+ };
256
+ prompt(options: PromptSpanOptions, ctx?: TelemetryContext): {
257
+ context: otel.Context;
258
+ end: (_options?: EndSpanOptions) => void;
259
+ fail: (_error: Error, _options?: ErrorOptions) => void;
260
+ };
261
+ step(options?: StartSpanOptions, ctx?: TelemetryContext): {
262
+ context: otel.Context;
263
+ end: (_options?: EndSpanOptions) => void;
264
+ fail: (_error: Error, _options?: ErrorOptions) => void;
265
+ };
266
+ chat(options: ChatSpanOptions, ctx?: TelemetryContext): {
267
+ context: otel.Context;
268
+ end: (_options?: EndSpanOptions) => void;
269
+ fail: (_error: Error, _options?: ErrorOptions) => void;
270
+ };
271
+ external(options: ExternalSpanOptions, ctx?: TelemetryContext): {
272
+ context: otel.Context;
273
+ end: (_options?: EndSpanOptions) => void;
274
+ fail: (_error: Error, _options?: ErrorOptions) => void;
275
+ };
276
+ }
277
+ declare class ContextManager {
278
+ private telemetry;
279
+ constructor(telemetry: ManualInstrumentation);
280
+ resume(ctx: TraceContext): otel.Context;
281
+ active(): otel.Context;
282
+ }
283
+ declare class InstrumentationManager {
284
+ private instrumentations;
285
+ constructor(instrumentations: BaseInstrumentation[]);
286
+ enable(): void;
287
+ disable(): void;
288
+ }
289
+ declare class TracerManager {
290
+ private nodeProvider;
291
+ private scopeVersion;
292
+ constructor(nodeProvider: NodeTracerProvider, scopeVersion: string);
293
+ get(scope: Instrumentation): otel.Tracer;
294
+ provider(scope: Instrumentation): ScopedTracerProvider;
295
+ }
124
296
  declare class ScopedTracerProvider implements otel.TracerProvider {
125
297
  private readonly scope;
126
298
  private readonly version;
@@ -163,59 +335,19 @@ type TelemetryOptions = {
163
335
  };
164
336
  declare class LatitudeTelemetry {
165
337
  private options;
166
- private provider;
167
- private telemetry;
168
- private instrumentations;
338
+ private nodeProvider;
339
+ private manualInstrumentation;
340
+ private instrumentationsList;
341
+ readonly span: SpanFactory;
342
+ readonly context: ContextManager;
343
+ readonly instrumentation: InstrumentationManager;
344
+ readonly tracer: TracerManager;
169
345
  constructor(apiKey: string, options?: TelemetryOptions);
170
346
  flush(): Promise<void>;
171
347
  shutdown(): Promise<void>;
172
- tracerProvider(instrumentation: Instrumentation): ScopedTracerProvider;
173
- tracer(instrumentation: Instrumentation): otel.Tracer;
174
348
  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
- };
349
+ capture<T>(options: CaptureOptions, fn: (ctx: TelemetryContext) => T | Promise<T>): Promise<T>;
218
350
  }
219
351
 
220
352
  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 };
353
+ export type { CaptureOptions, ChatSpanOptions, EndCompletionSpanOptions, EndHttpSpanOptions, EndSpanOptions, EndToolSpanOptions, ErrorOptions, ExternalSpanOptions, PromptSpanOptions as PromptSegmentOptions, RedactSpanProcessorOptions, StartCompletionSpanOptions, StartHttpSpanOptions, StartSpanOptions, StartToolSpanOptions, TelemetryContext, TelemetryOptions };