@latitude-data/telemetry 1.1.0 → 2.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.cjs +401 -441
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +57 -71
- package/dist/index.js +401 -441
- package/dist/index.js.map +1 -1
- package/package.json +12 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import * as otel from '@opentelemetry/api';
|
|
2
3
|
import { TextMapPropagator } from '@opentelemetry/api';
|
|
4
|
+
import { Provider } from 'rosetta-ai';
|
|
3
5
|
import { SpanProcessor, ReadableSpan, SpanExporter, NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
|
4
6
|
import * as latitude from '@latitude-data/sdk';
|
|
5
|
-
import {
|
|
7
|
+
import { Latitude } from '@latitude-data/sdk';
|
|
6
8
|
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
7
9
|
|
|
8
|
-
interface RedactSpanProcessorOptions {
|
|
9
|
-
attributes: (string | RegExp)[];
|
|
10
|
-
mask?: (attribute: string, value: any) => string;
|
|
11
|
-
}
|
|
12
|
-
declare class RedactSpanProcessor implements SpanProcessor {
|
|
13
|
-
private options;
|
|
14
|
-
constructor(options: RedactSpanProcessorOptions);
|
|
15
|
-
onStart(_span: ReadableSpan, _context: otel.Context): void;
|
|
16
|
-
onEnd(span: ReadableSpan): void;
|
|
17
|
-
forceFlush(): Promise<void>;
|
|
18
|
-
shutdown(): Promise<void>;
|
|
19
|
-
private shouldRedact;
|
|
20
|
-
private redactAttributes;
|
|
21
|
-
}
|
|
22
|
-
declare const DEFAULT_REDACT_SPAN_PROCESSOR: () => RedactSpanProcessor;
|
|
23
|
-
|
|
24
10
|
interface BaseInstrumentation {
|
|
25
11
|
isEnabled(): boolean;
|
|
26
12
|
enable(): void;
|
|
@@ -28,7 +14,7 @@ interface BaseInstrumentation {
|
|
|
28
14
|
}
|
|
29
15
|
|
|
30
16
|
type LatitudeInstrumentationOptions = {
|
|
31
|
-
module: typeof
|
|
17
|
+
module: typeof Latitude;
|
|
32
18
|
completions?: boolean;
|
|
33
19
|
};
|
|
34
20
|
|
|
@@ -45,7 +31,8 @@ declare enum LogSources {
|
|
|
45
31
|
SharedPrompt = "shared_prompt",
|
|
46
32
|
ShadowTest = "shadow_test",
|
|
47
33
|
ABTestChallenger = "ab_test_challenger",
|
|
48
|
-
User = "user"
|
|
34
|
+
User = "user",
|
|
35
|
+
Optimization = "optimization"
|
|
49
36
|
}
|
|
50
37
|
|
|
51
38
|
declare const traceContextSchema: z.ZodObject<{
|
|
@@ -82,13 +69,13 @@ type StartCompletionSpanOptions = StartSpanOptions & {
|
|
|
82
69
|
provider: string;
|
|
83
70
|
model: string;
|
|
84
71
|
configuration?: Record<string, unknown>;
|
|
85
|
-
input?: Record<string, unknown>[];
|
|
72
|
+
input?: string | Record<string, unknown>[];
|
|
86
73
|
versionUuid?: string;
|
|
87
74
|
promptUuid?: string;
|
|
88
75
|
experimentUuid?: string;
|
|
89
76
|
};
|
|
90
77
|
type EndCompletionSpanOptions = EndSpanOptions & {
|
|
91
|
-
output?: Record<string, unknown>[];
|
|
78
|
+
output?: string | Record<string, unknown>[];
|
|
92
79
|
tokens?: {
|
|
93
80
|
prompt?: number;
|
|
94
81
|
cached?: number;
|
|
@@ -128,6 +115,8 @@ type ChatSpanOptions = StartSpanOptions & {
|
|
|
128
115
|
documentLogUuid: string;
|
|
129
116
|
previousTraceId: string;
|
|
130
117
|
source?: LogSources;
|
|
118
|
+
versionUuid?: string;
|
|
119
|
+
promptUuid?: string;
|
|
131
120
|
};
|
|
132
121
|
type ExternalSpanOptions = StartSpanOptions & {
|
|
133
122
|
promptUuid: string;
|
|
@@ -142,66 +131,53 @@ type CaptureOptions = StartSpanOptions & {
|
|
|
142
131
|
versionUuid?: string;
|
|
143
132
|
conversationUuid?: string;
|
|
144
133
|
};
|
|
134
|
+
type ManualInstrumentationOptions = {
|
|
135
|
+
provider?: Provider;
|
|
136
|
+
};
|
|
145
137
|
declare class ManualInstrumentation implements BaseInstrumentation {
|
|
146
138
|
private enabled;
|
|
147
139
|
private readonly tracer;
|
|
148
|
-
|
|
140
|
+
private readonly options;
|
|
141
|
+
constructor(tracer: otel.Tracer, options?: ManualInstrumentationOptions);
|
|
149
142
|
isEnabled(): boolean;
|
|
150
143
|
enable(): void;
|
|
151
144
|
disable(): void;
|
|
152
145
|
resume(ctx: TraceContext): otel.Context;
|
|
153
|
-
private capitalize;
|
|
154
|
-
private toCamelCase;
|
|
155
|
-
private toSnakeCase;
|
|
156
|
-
private toKebabCase;
|
|
157
146
|
private error;
|
|
158
147
|
private span;
|
|
159
|
-
|
|
148
|
+
unknown(ctx: otel.Context, options?: StartSpanOptions): {
|
|
160
149
|
context: otel.Context;
|
|
150
|
+
end: (_options?: EndSpanOptions) => void;
|
|
151
|
+
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
152
|
+
};
|
|
153
|
+
tool(ctx: otel.Context, options: StartToolSpanOptions): {
|
|
161
154
|
end: (options: EndToolSpanOptions) => void;
|
|
155
|
+
context: otel.Context;
|
|
162
156
|
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
163
157
|
};
|
|
164
|
-
private attribifyMessageToolCalls;
|
|
165
|
-
private attribifyMessageContent;
|
|
166
|
-
private attribifyMessages;
|
|
167
158
|
private attribifyConfiguration;
|
|
168
159
|
completion(ctx: otel.Context, options: StartCompletionSpanOptions): {
|
|
169
|
-
context: otel.Context;
|
|
170
160
|
end: (options?: EndCompletionSpanOptions) => void;
|
|
171
|
-
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
172
|
-
};
|
|
173
|
-
embedding(ctx: otel.Context, options?: StartSpanOptions): {
|
|
174
161
|
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
162
|
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
182
163
|
};
|
|
183
|
-
|
|
164
|
+
embedding(ctx: otel.Context, options?: StartSpanOptions): {
|
|
184
165
|
context: otel.Context;
|
|
185
166
|
end: (_options?: EndSpanOptions) => void;
|
|
186
167
|
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
187
168
|
};
|
|
188
169
|
private attribifyHeaders;
|
|
189
170
|
http(ctx: otel.Context, options: StartHttpSpanOptions): {
|
|
190
|
-
context: otel.Context;
|
|
191
171
|
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
172
|
context: otel.Context;
|
|
196
|
-
end: (_options?: EndSpanOptions) => void;
|
|
197
173
|
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
198
174
|
};
|
|
199
|
-
|
|
175
|
+
prompt(ctx: otel.Context, { documentLogUuid, versionUuid, promptUuid, projectId, experimentUuid, testDeploymentId, externalId, template, parameters, name, source, ...rest }: PromptSpanOptions): {
|
|
200
176
|
context: otel.Context;
|
|
201
177
|
end: (_options?: EndSpanOptions) => void;
|
|
202
178
|
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
203
179
|
};
|
|
204
|
-
chat(ctx: otel.Context, { documentLogUuid, previousTraceId, source, name, ...rest }: ChatSpanOptions): {
|
|
180
|
+
chat(ctx: otel.Context, { documentLogUuid, previousTraceId, source, name, versionUuid, promptUuid, ...rest }: ChatSpanOptions): {
|
|
205
181
|
context: otel.Context;
|
|
206
182
|
end: (_options?: EndSpanOptions) => void;
|
|
207
183
|
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
@@ -218,47 +194,53 @@ declare class ManualInstrumentation implements BaseInstrumentation {
|
|
|
218
194
|
};
|
|
219
195
|
}
|
|
220
196
|
|
|
197
|
+
interface RedactSpanProcessorOptions {
|
|
198
|
+
attributes: (string | RegExp)[];
|
|
199
|
+
mask?: (attribute: string, value: any) => string;
|
|
200
|
+
}
|
|
201
|
+
declare class RedactSpanProcessor implements SpanProcessor {
|
|
202
|
+
private options;
|
|
203
|
+
constructor(options: RedactSpanProcessorOptions);
|
|
204
|
+
onStart(_span: ReadableSpan, _context: otel.Context): void;
|
|
205
|
+
onEnd(span: ReadableSpan): void;
|
|
206
|
+
forceFlush(): Promise<void>;
|
|
207
|
+
shutdown(): Promise<void>;
|
|
208
|
+
private shouldRedact;
|
|
209
|
+
private redactAttributes;
|
|
210
|
+
}
|
|
211
|
+
declare const DEFAULT_REDACT_SPAN_PROCESSOR: () => RedactSpanProcessor;
|
|
212
|
+
|
|
221
213
|
type TelemetryContext = otel.Context;
|
|
222
214
|
declare const BACKGROUND: () => otel.Context;
|
|
223
215
|
declare class SpanFactory {
|
|
224
|
-
private telemetry;
|
|
216
|
+
private readonly telemetry;
|
|
225
217
|
constructor(telemetry: ManualInstrumentation);
|
|
226
|
-
|
|
218
|
+
span(options?: StartSpanOptions, ctx?: TelemetryContext): {
|
|
227
219
|
context: otel.Context;
|
|
228
|
-
end: (
|
|
229
|
-
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
230
|
-
};
|
|
231
|
-
completion(options: StartCompletionSpanOptions, ctx?: TelemetryContext): {
|
|
232
|
-
context: otel.Context;
|
|
233
|
-
end: (options?: EndCompletionSpanOptions) => void;
|
|
220
|
+
end: (_options?: EndSpanOptions) => void;
|
|
234
221
|
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
235
222
|
};
|
|
236
|
-
|
|
223
|
+
tool(options: StartToolSpanOptions, ctx?: TelemetryContext): {
|
|
224
|
+
end: (options: EndToolSpanOptions) => void;
|
|
237
225
|
context: otel.Context;
|
|
238
|
-
end: (_options?: EndSpanOptions) => void;
|
|
239
226
|
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
240
227
|
};
|
|
241
|
-
|
|
228
|
+
completion(options: StartCompletionSpanOptions, ctx?: TelemetryContext): {
|
|
229
|
+
end: (options?: EndCompletionSpanOptions) => void;
|
|
242
230
|
context: otel.Context;
|
|
243
|
-
end: (_options?: EndSpanOptions) => void;
|
|
244
231
|
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
245
232
|
};
|
|
246
|
-
|
|
233
|
+
embedding(options?: StartSpanOptions, ctx?: TelemetryContext): {
|
|
247
234
|
context: otel.Context;
|
|
248
235
|
end: (_options?: EndSpanOptions) => void;
|
|
249
236
|
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
250
237
|
};
|
|
251
238
|
http(options: StartHttpSpanOptions, ctx?: TelemetryContext): {
|
|
252
|
-
context: otel.Context;
|
|
253
239
|
end: (options: EndHttpSpanOptions) => void;
|
|
254
|
-
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
255
|
-
};
|
|
256
|
-
prompt(options: PromptSpanOptions, ctx?: TelemetryContext): {
|
|
257
240
|
context: otel.Context;
|
|
258
|
-
end: (_options?: EndSpanOptions) => void;
|
|
259
241
|
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
260
242
|
};
|
|
261
|
-
|
|
243
|
+
prompt(options: PromptSpanOptions, ctx?: TelemetryContext): {
|
|
262
244
|
context: otel.Context;
|
|
263
245
|
end: (_options?: EndSpanOptions) => void;
|
|
264
246
|
fail: (_error: Error, _options?: ErrorOptions) => void;
|
|
@@ -275,20 +257,21 @@ declare class SpanFactory {
|
|
|
275
257
|
};
|
|
276
258
|
}
|
|
277
259
|
declare class ContextManager {
|
|
278
|
-
private telemetry;
|
|
260
|
+
private readonly telemetry;
|
|
279
261
|
constructor(telemetry: ManualInstrumentation);
|
|
280
262
|
resume(ctx: TraceContext): otel.Context;
|
|
281
263
|
active(): otel.Context;
|
|
264
|
+
with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(ctx: TelemetryContext, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
|
|
282
265
|
}
|
|
283
266
|
declare class InstrumentationManager {
|
|
284
|
-
private instrumentations;
|
|
267
|
+
private readonly instrumentations;
|
|
285
268
|
constructor(instrumentations: BaseInstrumentation[]);
|
|
286
269
|
enable(): void;
|
|
287
270
|
disable(): void;
|
|
288
271
|
}
|
|
289
272
|
declare class TracerManager {
|
|
290
|
-
private nodeProvider;
|
|
291
|
-
private scopeVersion;
|
|
273
|
+
private readonly nodeProvider;
|
|
274
|
+
private readonly scopeVersion;
|
|
292
275
|
constructor(nodeProvider: NodeTracerProvider, scopeVersion: string);
|
|
293
276
|
get(scope: Instrumentation): otel.Tracer;
|
|
294
277
|
provider(scope: Instrumentation): ScopedTracerProvider;
|
|
@@ -309,6 +292,7 @@ declare enum Instrumentation {
|
|
|
309
292
|
Langchain = "langchain",
|
|
310
293
|
Latitude = "latitude",
|
|
311
294
|
LlamaIndex = "llamaindex",
|
|
295
|
+
Manual = "manual",
|
|
312
296
|
OpenAI = "openai",
|
|
313
297
|
TogetherAI = "togetherai",
|
|
314
298
|
VertexAI = "vertexai"
|
|
@@ -331,6 +315,7 @@ type TelemetryOptions = {
|
|
|
331
315
|
[Instrumentation.Langchain]?: {
|
|
332
316
|
callbackManagerModule?: any;
|
|
333
317
|
};
|
|
318
|
+
[Instrumentation.Manual]?: ManualInstrumentationOptions;
|
|
334
319
|
};
|
|
335
320
|
};
|
|
336
321
|
declare class LatitudeTelemetry {
|
|
@@ -342,6 +327,7 @@ declare class LatitudeTelemetry {
|
|
|
342
327
|
readonly context: ContextManager;
|
|
343
328
|
readonly instrumentation: InstrumentationManager;
|
|
344
329
|
readonly tracer: TracerManager;
|
|
330
|
+
private readonly lifecycle;
|
|
345
331
|
constructor(apiKey: string, options?: TelemetryOptions);
|
|
346
332
|
flush(): Promise<void>;
|
|
347
333
|
shutdown(): Promise<void>;
|