@latitude-data/telemetry 1.0.3 → 1.0.4
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 +470 -585
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +41 -161
- package/dist/index.js +471 -586
- package/dist/index.js.map +1 -1
- package/package.json +30 -41
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,6 @@ var zod = require('zod');
|
|
|
4
4
|
var otel = require('@opentelemetry/api');
|
|
5
5
|
var semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
6
6
|
var incubating = require('@opentelemetry/semantic-conventions/incubating');
|
|
7
|
-
var uuid = require('uuid');
|
|
8
7
|
var baggageSpanProcessor = require('@opentelemetry/baggage-span-processor');
|
|
9
8
|
var contextAsyncHooks = require('@opentelemetry/context-async-hooks');
|
|
10
9
|
var core = require('@opentelemetry/core');
|
|
@@ -13,7 +12,6 @@ var instrumentation = require('@opentelemetry/instrumentation');
|
|
|
13
12
|
var resources = require('@opentelemetry/resources');
|
|
14
13
|
var sdkTraceNode = require('@opentelemetry/sdk-trace-node');
|
|
15
14
|
var instrumentationAnthropic = require('@traceloop/instrumentation-anthropic');
|
|
16
|
-
var instrumentationAzure = require('@traceloop/instrumentation-azure');
|
|
17
15
|
var instrumentationBedrock = require('@traceloop/instrumentation-bedrock');
|
|
18
16
|
var instrumentationCohere = require('@traceloop/instrumentation-cohere');
|
|
19
17
|
var instrumentationLangchain = require('@traceloop/instrumentation-langchain');
|
|
@@ -96,6 +94,7 @@ const DEFAULT_REDACT_SPAN_PROCESSOR = () => new RedactSpanProcessor({
|
|
|
96
94
|
attributes: [
|
|
97
95
|
/^.*auth.*$/i,
|
|
98
96
|
/^.*authorization.*$/i,
|
|
97
|
+
/^(?!ai\.).*usage.*$/i,
|
|
99
98
|
/^(?!gen_ai\.).*token.*$/i,
|
|
100
99
|
/^.*secret.*$/i,
|
|
101
100
|
/^.*key.*$/i,
|
|
@@ -138,289 +137,6 @@ function GET_GATEWAY_BASE_URL() {
|
|
|
138
137
|
}
|
|
139
138
|
const env = { GATEWAY_BASE_URL: GET_GATEWAY_BASE_URL() };
|
|
140
139
|
|
|
141
|
-
var SegmentSource;
|
|
142
|
-
(function (SegmentSource) {
|
|
143
|
-
SegmentSource["API"] = "api";
|
|
144
|
-
SegmentSource["AgentAsTool"] = "agent_as_tool";
|
|
145
|
-
SegmentSource["Copilot"] = "copilot";
|
|
146
|
-
SegmentSource["EmailTrigger"] = "email_trigger";
|
|
147
|
-
SegmentSource["Evaluation"] = "evaluation";
|
|
148
|
-
SegmentSource["Experiment"] = "experiment";
|
|
149
|
-
SegmentSource["Playground"] = "playground";
|
|
150
|
-
SegmentSource["ScheduledTrigger"] = "scheduled_trigger";
|
|
151
|
-
SegmentSource["IntegrationTrigger"] = "integration_trigger";
|
|
152
|
-
SegmentSource["SharedPrompt"] = "shared_prompt";
|
|
153
|
-
SegmentSource["User"] = "user";
|
|
154
|
-
})(SegmentSource || (SegmentSource = {}));
|
|
155
|
-
var SegmentType;
|
|
156
|
-
(function (SegmentType) {
|
|
157
|
-
SegmentType["Document"] = "document";
|
|
158
|
-
SegmentType["Step"] = "step";
|
|
159
|
-
})(SegmentType || (SegmentType = {}));
|
|
160
|
-
const SEGMENT_SPECIFICATIONS = {
|
|
161
|
-
[SegmentType.Document]: {
|
|
162
|
-
name: 'Prompt',
|
|
163
|
-
description: 'A prompt',
|
|
164
|
-
},
|
|
165
|
-
[SegmentType.Step]: {
|
|
166
|
-
name: 'Step',
|
|
167
|
-
description: 'A step in a prompt',
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
const baseSegmentBaggageSchema = zod.z.object({
|
|
171
|
-
id: zod.z.string(),
|
|
172
|
-
parentId: zod.z.string().optional(),
|
|
173
|
-
source: zod.z.nativeEnum(SegmentSource),
|
|
174
|
-
});
|
|
175
|
-
zod.z.discriminatedUnion('type', [
|
|
176
|
-
baseSegmentBaggageSchema.extend({
|
|
177
|
-
type: zod.z.literal(SegmentType.Document),
|
|
178
|
-
data: zod.z.object({
|
|
179
|
-
logUuid: zod.z.string().optional(), // TODO(tracing): temporal related log, remove when observability is ready
|
|
180
|
-
commitUuid: zod.z.string(),
|
|
181
|
-
documentUuid: zod.z.string(),
|
|
182
|
-
experimentUuid: zod.z.string().optional(),
|
|
183
|
-
externalId: zod.z.string().optional(),
|
|
184
|
-
}),
|
|
185
|
-
}),
|
|
186
|
-
baseSegmentBaggageSchema.extend({
|
|
187
|
-
type: zod.z.literal(SegmentType.Step),
|
|
188
|
-
data: zod.z.undefined().optional(),
|
|
189
|
-
}),
|
|
190
|
-
]);
|
|
191
|
-
|
|
192
|
-
var SpanKind;
|
|
193
|
-
(function (SpanKind) {
|
|
194
|
-
SpanKind["Internal"] = "internal";
|
|
195
|
-
SpanKind["Server"] = "server";
|
|
196
|
-
SpanKind["Client"] = "client";
|
|
197
|
-
SpanKind["Producer"] = "producer";
|
|
198
|
-
SpanKind["Consumer"] = "consumer";
|
|
199
|
-
})(SpanKind || (SpanKind = {}));
|
|
200
|
-
// Note: loosely based on OpenTelemetry GenAI semantic conventions
|
|
201
|
-
var SpanType;
|
|
202
|
-
(function (SpanType) {
|
|
203
|
-
SpanType["Tool"] = "tool";
|
|
204
|
-
SpanType["Completion"] = "completion";
|
|
205
|
-
SpanType["Embedding"] = "embedding";
|
|
206
|
-
SpanType["Retrieval"] = "retrieval";
|
|
207
|
-
SpanType["Reranking"] = "reranking";
|
|
208
|
-
SpanType["Http"] = "http";
|
|
209
|
-
SpanType["Segment"] = "segment";
|
|
210
|
-
SpanType["Unknown"] = "unknown";
|
|
211
|
-
})(SpanType || (SpanType = {}));
|
|
212
|
-
const SPAN_SPECIFICATIONS = {
|
|
213
|
-
[SpanType.Tool]: {
|
|
214
|
-
name: 'Tool',
|
|
215
|
-
description: 'A tool call',
|
|
216
|
-
isGenAI: true,
|
|
217
|
-
isHidden: false,
|
|
218
|
-
},
|
|
219
|
-
[SpanType.Completion]: {
|
|
220
|
-
name: 'Completion',
|
|
221
|
-
description: 'A completion call',
|
|
222
|
-
isGenAI: true,
|
|
223
|
-
isHidden: false,
|
|
224
|
-
},
|
|
225
|
-
[SpanType.Embedding]: {
|
|
226
|
-
name: 'Embedding',
|
|
227
|
-
description: 'An embedding call',
|
|
228
|
-
isGenAI: true,
|
|
229
|
-
isHidden: false,
|
|
230
|
-
},
|
|
231
|
-
[SpanType.Retrieval]: {
|
|
232
|
-
name: 'Retrieval',
|
|
233
|
-
description: 'A retrieval call',
|
|
234
|
-
isGenAI: true,
|
|
235
|
-
isHidden: false,
|
|
236
|
-
},
|
|
237
|
-
[SpanType.Reranking]: {
|
|
238
|
-
name: 'Reranking',
|
|
239
|
-
description: 'A reranking call',
|
|
240
|
-
isGenAI: true,
|
|
241
|
-
isHidden: false,
|
|
242
|
-
},
|
|
243
|
-
[SpanType.Http]: {
|
|
244
|
-
name: 'HTTP',
|
|
245
|
-
description: 'An HTTP request',
|
|
246
|
-
isGenAI: false,
|
|
247
|
-
isHidden: true,
|
|
248
|
-
},
|
|
249
|
-
[SpanType.Segment]: {
|
|
250
|
-
name: 'Segment',
|
|
251
|
-
description: 'A (partial) segment of a trace',
|
|
252
|
-
isGenAI: false,
|
|
253
|
-
isHidden: false,
|
|
254
|
-
},
|
|
255
|
-
[SpanType.Unknown]: {
|
|
256
|
-
name: 'Unknown',
|
|
257
|
-
description: 'An unknown span',
|
|
258
|
-
isGenAI: false,
|
|
259
|
-
isHidden: true,
|
|
260
|
-
},
|
|
261
|
-
};
|
|
262
|
-
var SpanStatus;
|
|
263
|
-
(function (SpanStatus) {
|
|
264
|
-
SpanStatus["Unset"] = "unset";
|
|
265
|
-
SpanStatus["Ok"] = "ok";
|
|
266
|
-
SpanStatus["Error"] = "error";
|
|
267
|
-
})(SpanStatus || (SpanStatus = {}));
|
|
268
|
-
|
|
269
|
-
// Note: Traces are unmaterialized but this context is used to propagate the trace
|
|
270
|
-
// See www.w3.org/TR/trace-context and w3c.github.io/baggage
|
|
271
|
-
zod.z.object({
|
|
272
|
-
traceparent: zod.z.string(), // <version>-<trace-id>-<span-id>-<trace-flags>
|
|
273
|
-
tracestate: zod.z.string().optional(), // <key>=urlencoded(<value>)[,<key>=urlencoded(<value>)]*
|
|
274
|
-
baggage: zod.z.string().optional(), // <key>=urlencoded(<value>)[,<key>=urlencoded(<value>)]*
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
/* Note: Instrumentation scopes from all language SDKs */
|
|
278
|
-
const SCOPE_LATITUDE = 'so.latitude.instrumentation';
|
|
279
|
-
var InstrumentationScope;
|
|
280
|
-
(function (InstrumentationScope) {
|
|
281
|
-
InstrumentationScope["Manual"] = "manual";
|
|
282
|
-
InstrumentationScope["Latitude"] = "latitude";
|
|
283
|
-
InstrumentationScope["OpenAI"] = "openai";
|
|
284
|
-
InstrumentationScope["Anthropic"] = "anthropic";
|
|
285
|
-
InstrumentationScope["AzureOpenAI"] = "azure";
|
|
286
|
-
InstrumentationScope["VercelAI"] = "vercelai";
|
|
287
|
-
InstrumentationScope["VertexAI"] = "vertexai";
|
|
288
|
-
InstrumentationScope["AIPlatform"] = "aiplatform";
|
|
289
|
-
InstrumentationScope["MistralAI"] = "mistralai";
|
|
290
|
-
InstrumentationScope["Bedrock"] = "bedrock";
|
|
291
|
-
InstrumentationScope["Sagemaker"] = "sagemaker";
|
|
292
|
-
InstrumentationScope["TogetherAI"] = "togetherai";
|
|
293
|
-
InstrumentationScope["Replicate"] = "replicate";
|
|
294
|
-
InstrumentationScope["Groq"] = "groq";
|
|
295
|
-
InstrumentationScope["Cohere"] = "cohere";
|
|
296
|
-
InstrumentationScope["LiteLLM"] = "litellm";
|
|
297
|
-
InstrumentationScope["Langchain"] = "langchain";
|
|
298
|
-
InstrumentationScope["LlamaIndex"] = "llamaindex";
|
|
299
|
-
InstrumentationScope["DSPy"] = "dspy";
|
|
300
|
-
InstrumentationScope["Haystack"] = "haystack";
|
|
301
|
-
InstrumentationScope["Ollama"] = "ollama";
|
|
302
|
-
InstrumentationScope["Transformers"] = "transformers";
|
|
303
|
-
InstrumentationScope["AlephAlpha"] = "alephalpha";
|
|
304
|
-
})(InstrumentationScope || (InstrumentationScope = {}));
|
|
305
|
-
/* Note: non-standard OpenTelemetry semantic conventions used in Latitude */
|
|
306
|
-
const ATTR_LATITUDE = 'latitude';
|
|
307
|
-
const ATTR_LATITUDE_TYPE = `${ATTR_LATITUDE}.type`;
|
|
308
|
-
const ATTR_LATITUDE_SEGMENT_ID = `${ATTR_LATITUDE}.segment.id`;
|
|
309
|
-
const ATTR_LATITUDE_SEGMENT_PARENT_ID = `${ATTR_LATITUDE}.segment.parent_id`;
|
|
310
|
-
const ATTR_LATITUDE_SEGMENTS = `${ATTR_LATITUDE}.segments`;
|
|
311
|
-
const GEN_AI_TOOL_TYPE_VALUE_FUNCTION = 'function';
|
|
312
|
-
const ATTR_GEN_AI_TOOL_CALL_ARGUMENTS = 'gen_ai.tool.call.arguments';
|
|
313
|
-
const ATTR_GEN_AI_TOOL_RESULT_VALUE = 'gen_ai.tool.result.value';
|
|
314
|
-
const ATTR_GEN_AI_TOOL_RESULT_IS_ERROR = 'gen_ai.tool.result.is_error';
|
|
315
|
-
const ATTR_GEN_AI_REQUEST = 'gen_ai.request';
|
|
316
|
-
const ATTR_GEN_AI_REQUEST_CONFIGURATION = 'gen_ai.request.configuration';
|
|
317
|
-
const ATTR_GEN_AI_REQUEST_TEMPLATE = 'gen_ai.request.template';
|
|
318
|
-
const ATTR_GEN_AI_REQUEST_PARAMETERS = 'gen_ai.request.parameters';
|
|
319
|
-
const ATTR_GEN_AI_REQUEST_MESSAGES = 'gen_ai.request.messages';
|
|
320
|
-
const ATTR_GEN_AI_RESPONSE = 'gen_ai.response';
|
|
321
|
-
const ATTR_GEN_AI_RESPONSE_MESSAGES = 'gen_ai.response.messages';
|
|
322
|
-
const ATTR_GEN_AI_USAGE_PROMPT_TOKENS = 'gen_ai.usage.prompt_tokens';
|
|
323
|
-
const ATTR_GEN_AI_USAGE_CACHED_TOKENS = 'gen_ai.usage.cached_tokens';
|
|
324
|
-
const ATTR_GEN_AI_USAGE_REASONING_TOKENS = 'gen_ai.usage.reasoning_tokens'; // prettier-ignore
|
|
325
|
-
const ATTR_GEN_AI_USAGE_COMPLETION_TOKENS = 'gen_ai.usage.completion_tokens'; // prettier-ignore
|
|
326
|
-
const ATTR_GEN_AI_PROMPTS = 'gen_ai.prompt'; // gen_ai.prompt.{index}.{role/content/...}
|
|
327
|
-
const ATTR_GEN_AI_COMPLETIONS = 'gen_ai.completion'; // gen_ai.completion.{index}.{role/content/...}
|
|
328
|
-
const ATTR_GEN_AI_MESSAGE_ROLE = 'role';
|
|
329
|
-
const ATTR_GEN_AI_MESSAGE_CONTENT = 'content'; // string or object
|
|
330
|
-
const ATTR_GEN_AI_MESSAGE_TOOL_NAME = 'tool_name';
|
|
331
|
-
const ATTR_GEN_AI_MESSAGE_TOOL_CALL_ID = 'tool_call_id';
|
|
332
|
-
const ATTR_GEN_AI_MESSAGE_TOOL_RESULT_IS_ERROR = 'is_error';
|
|
333
|
-
const ATTR_GEN_AI_MESSAGE_TOOL_CALLS = 'tool_calls'; // gen_ai.completion.{index}.tool_calls.{index}.{id/name/arguments}
|
|
334
|
-
const ATTR_GEN_AI_MESSAGE_TOOL_CALLS_ID = 'id';
|
|
335
|
-
const ATTR_GEN_AI_MESSAGE_TOOL_CALLS_NAME = 'name';
|
|
336
|
-
const ATTR_GEN_AI_MESSAGE_TOOL_CALLS_ARGUMENTS = 'arguments';
|
|
337
|
-
const GEN_AI_RESPONSE_FINISH_REASON_VALUE_STOP = 'stop';
|
|
338
|
-
const GEN_AI_RESPONSE_FINISH_REASON_VALUE_TOOL_CALLS = 'tool_calls';
|
|
339
|
-
const ATTR_HTTP_REQUEST_URL = 'http.request.url';
|
|
340
|
-
const ATTR_HTTP_REQUEST_BODY = 'http.request.body';
|
|
341
|
-
const ATTR_HTTP_REQUEST_HEADER = 'http.request.header';
|
|
342
|
-
const ATTR_HTTP_RESPONSE_BODY = 'http.response.body';
|
|
343
|
-
const ATTR_HTTP_RESPONSE_HEADER = 'http.response.header';
|
|
344
|
-
/* Note: Schemas for span ingestion following OpenTelemetry service request specification */
|
|
345
|
-
var Otlp;
|
|
346
|
-
(function (Otlp) {
|
|
347
|
-
Otlp.attributeValueSchema = zod.z.object({
|
|
348
|
-
stringValue: zod.z.string().optional(),
|
|
349
|
-
intValue: zod.z.number().optional(),
|
|
350
|
-
boolValue: zod.z.boolean().optional(),
|
|
351
|
-
arrayValue: zod.z
|
|
352
|
-
.object({
|
|
353
|
-
values: zod.z.array(zod.z.object({
|
|
354
|
-
stringValue: zod.z.string().optional(),
|
|
355
|
-
intValue: zod.z.number().optional(),
|
|
356
|
-
boolValue: zod.z.boolean().optional(),
|
|
357
|
-
})),
|
|
358
|
-
})
|
|
359
|
-
.optional(),
|
|
360
|
-
});
|
|
361
|
-
Otlp.attributeSchema = zod.z.object({
|
|
362
|
-
key: zod.z.string(),
|
|
363
|
-
value: Otlp.attributeValueSchema,
|
|
364
|
-
});
|
|
365
|
-
Otlp.eventSchema = zod.z.object({
|
|
366
|
-
name: zod.z.string(),
|
|
367
|
-
timeUnixNano: zod.z.string(),
|
|
368
|
-
attributes: zod.z.array(Otlp.attributeSchema).optional(),
|
|
369
|
-
});
|
|
370
|
-
Otlp.linkSchema = zod.z.object({
|
|
371
|
-
traceId: zod.z.string(),
|
|
372
|
-
spanId: zod.z.string(),
|
|
373
|
-
attributes: zod.z.array(Otlp.attributeSchema).optional(),
|
|
374
|
-
});
|
|
375
|
-
(function (StatusCode) {
|
|
376
|
-
StatusCode[StatusCode["Unset"] = 0] = "Unset";
|
|
377
|
-
StatusCode[StatusCode["Ok"] = 1] = "Ok";
|
|
378
|
-
StatusCode[StatusCode["Error"] = 2] = "Error";
|
|
379
|
-
})(Otlp.StatusCode || (Otlp.StatusCode = {}));
|
|
380
|
-
Otlp.statusSchema = zod.z.object({
|
|
381
|
-
code: zod.z.number(),
|
|
382
|
-
message: zod.z.string().optional(),
|
|
383
|
-
});
|
|
384
|
-
(function (SpanKind) {
|
|
385
|
-
SpanKind[SpanKind["Internal"] = 0] = "Internal";
|
|
386
|
-
SpanKind[SpanKind["Server"] = 1] = "Server";
|
|
387
|
-
SpanKind[SpanKind["Client"] = 2] = "Client";
|
|
388
|
-
SpanKind[SpanKind["Producer"] = 3] = "Producer";
|
|
389
|
-
SpanKind[SpanKind["Consumer"] = 4] = "Consumer";
|
|
390
|
-
})(Otlp.SpanKind || (Otlp.SpanKind = {}));
|
|
391
|
-
Otlp.spanSchema = zod.z.object({
|
|
392
|
-
traceId: zod.z.string(),
|
|
393
|
-
spanId: zod.z.string(),
|
|
394
|
-
parentSpanId: zod.z.string().optional(),
|
|
395
|
-
name: zod.z.string(),
|
|
396
|
-
kind: zod.z.number(),
|
|
397
|
-
startTimeUnixNano: zod.z.string(),
|
|
398
|
-
endTimeUnixNano: zod.z.string(),
|
|
399
|
-
status: Otlp.statusSchema.optional(),
|
|
400
|
-
events: zod.z.array(Otlp.eventSchema).optional(),
|
|
401
|
-
links: zod.z.array(Otlp.linkSchema).optional(),
|
|
402
|
-
attributes: zod.z.array(Otlp.attributeSchema).optional(),
|
|
403
|
-
});
|
|
404
|
-
Otlp.scopeSchema = zod.z.object({
|
|
405
|
-
name: zod.z.string(),
|
|
406
|
-
version: zod.z.string().optional(),
|
|
407
|
-
});
|
|
408
|
-
Otlp.scopeSpanSchema = zod.z.object({
|
|
409
|
-
scope: Otlp.scopeSchema,
|
|
410
|
-
spans: zod.z.array(Otlp.spanSchema),
|
|
411
|
-
});
|
|
412
|
-
Otlp.resourceSchema = zod.z.object({
|
|
413
|
-
attributes: zod.z.array(Otlp.attributeSchema),
|
|
414
|
-
});
|
|
415
|
-
Otlp.resourceSpanSchema = zod.z.object({
|
|
416
|
-
resource: Otlp.resourceSchema,
|
|
417
|
-
scopeSpans: zod.z.array(Otlp.scopeSpanSchema),
|
|
418
|
-
});
|
|
419
|
-
Otlp.serviceRequestSchema = zod.z.object({
|
|
420
|
-
resourceSpans: zod.z.array(Otlp.resourceSpanSchema),
|
|
421
|
-
});
|
|
422
|
-
})(Otlp || (Otlp = {}));
|
|
423
|
-
|
|
424
140
|
var StreamEventTypes;
|
|
425
141
|
(function (StreamEventTypes) {
|
|
426
142
|
StreamEventTypes["Latitude"] = "latitude-event";
|
|
@@ -445,17 +161,27 @@ var LatitudeTool;
|
|
|
445
161
|
LatitudeTool["RunCode"] = "code";
|
|
446
162
|
LatitudeTool["WebSearch"] = "search";
|
|
447
163
|
LatitudeTool["WebExtract"] = "extract";
|
|
164
|
+
LatitudeTool["Think"] = "think";
|
|
165
|
+
LatitudeTool["TODO"] = "todo";
|
|
448
166
|
})(LatitudeTool || (LatitudeTool = {}));
|
|
449
167
|
var LatitudeToolInternalName;
|
|
450
168
|
(function (LatitudeToolInternalName) {
|
|
451
169
|
LatitudeToolInternalName["RunCode"] = "lat_tool_run_code";
|
|
452
170
|
LatitudeToolInternalName["WebSearch"] = "lat_tool_web_search";
|
|
453
171
|
LatitudeToolInternalName["WebExtract"] = "lat_tool_web_extract";
|
|
172
|
+
LatitudeToolInternalName["Think"] = "think";
|
|
173
|
+
LatitudeToolInternalName["TODO"] = "todo_write";
|
|
454
174
|
})(LatitudeToolInternalName || (LatitudeToolInternalName = {}));
|
|
175
|
+
[
|
|
176
|
+
LatitudeTool.Think,
|
|
177
|
+
LatitudeTool.TODO,
|
|
178
|
+
];
|
|
455
179
|
|
|
456
180
|
const actualOutputConfiguration = zod.z.object({
|
|
457
181
|
messageSelection: zod.z.enum(['last', 'all']), // Which assistant messages to select
|
|
458
|
-
contentFilter: zod.z
|
|
182
|
+
contentFilter: zod.z
|
|
183
|
+
.enum(['text', 'reasoning', 'image', 'file', 'tool_call'])
|
|
184
|
+
.optional(),
|
|
459
185
|
parsingFormat: zod.z.enum(['string', 'json']),
|
|
460
186
|
fieldAccessor: zod.z.string().optional(), // Field accessor to get the output from if it's a key-value format
|
|
461
187
|
});
|
|
@@ -465,11 +191,11 @@ const expectedOutputConfiguration = zod.z.object({
|
|
|
465
191
|
});
|
|
466
192
|
const baseEvaluationConfiguration = zod.z.object({
|
|
467
193
|
reverseScale: zod.z.boolean(), // If true, lower is better, otherwise, higher is better
|
|
468
|
-
actualOutput: actualOutputConfiguration
|
|
469
|
-
expectedOutput: expectedOutputConfiguration.optional(),
|
|
194
|
+
actualOutput: actualOutputConfiguration,
|
|
195
|
+
expectedOutput: expectedOutputConfiguration.optional(),
|
|
470
196
|
});
|
|
471
197
|
const baseEvaluationResultMetadata = zod.z.object({
|
|
472
|
-
// Configuration snapshot is defined in every metric specification
|
|
198
|
+
// configuration: Configuration snapshot is defined in every metric specification
|
|
473
199
|
actualOutput: zod.z.string(),
|
|
474
200
|
expectedOutput: zod.z.string().optional(),
|
|
475
201
|
datasetLabel: zod.z.string().optional(),
|
|
@@ -478,7 +204,78 @@ const baseEvaluationResultError = zod.z.object({
|
|
|
478
204
|
message: zod.z.string(),
|
|
479
205
|
});
|
|
480
206
|
|
|
207
|
+
const compositeEvaluationConfiguration = baseEvaluationConfiguration.extend({
|
|
208
|
+
evaluationUuids: zod.z.array(zod.z.string()),
|
|
209
|
+
minThreshold: zod.z.number().optional(), // Threshold percentage
|
|
210
|
+
maxThreshold: zod.z.number().optional(), // Threshold percentage
|
|
211
|
+
});
|
|
212
|
+
const compositeEvaluationResultMetadata = baseEvaluationResultMetadata.extend({
|
|
213
|
+
results: zod.z.record(zod.z.string(), // Evaluation uuid
|
|
214
|
+
zod.z.object({
|
|
215
|
+
uuid: zod.z.string(), // Result uuid (for side effects)
|
|
216
|
+
name: zod.z.string(), // Evaluation name
|
|
217
|
+
score: zod.z.number(), // Normalized score
|
|
218
|
+
reason: zod.z.string(),
|
|
219
|
+
passed: zod.z.boolean(),
|
|
220
|
+
})),
|
|
221
|
+
});
|
|
222
|
+
const compositeEvaluationResultError = baseEvaluationResultError.extend({
|
|
223
|
+
errors: zod.z
|
|
224
|
+
.record(zod.z.string(), // Evaluation uuid
|
|
225
|
+
zod.z.object({
|
|
226
|
+
uuid: zod.z.string(), // Result uuid (for side effects)
|
|
227
|
+
name: zod.z.string(), // Evaluation name
|
|
228
|
+
message: zod.z.string(),
|
|
229
|
+
}))
|
|
230
|
+
.optional(),
|
|
231
|
+
});
|
|
232
|
+
// AVERAGE
|
|
233
|
+
const compositeEvaluationAverageConfiguration = compositeEvaluationConfiguration.extend({});
|
|
234
|
+
compositeEvaluationResultMetadata.extend({
|
|
235
|
+
configuration: compositeEvaluationAverageConfiguration,
|
|
236
|
+
});
|
|
237
|
+
compositeEvaluationResultError.extend({});
|
|
238
|
+
const CompositeEvaluationAverageSpecification = {
|
|
239
|
+
};
|
|
240
|
+
// WEIGHTED
|
|
241
|
+
const compositeEvaluationWeightedConfiguration = compositeEvaluationConfiguration.extend({
|
|
242
|
+
weights: zod.z.record(zod.z.string(), // Evaluation uuid
|
|
243
|
+
zod.z.number()),
|
|
244
|
+
});
|
|
245
|
+
compositeEvaluationResultMetadata.extend({
|
|
246
|
+
configuration: compositeEvaluationWeightedConfiguration,
|
|
247
|
+
});
|
|
248
|
+
compositeEvaluationResultError.extend({});
|
|
249
|
+
const CompositeEvaluationWeightedSpecification = {
|
|
250
|
+
};
|
|
251
|
+
// CUSTOM
|
|
252
|
+
const compositeEvaluationCustomConfiguration = compositeEvaluationConfiguration.extend({
|
|
253
|
+
formula: zod.z.string(),
|
|
254
|
+
});
|
|
255
|
+
compositeEvaluationResultMetadata.extend({
|
|
256
|
+
configuration: compositeEvaluationCustomConfiguration,
|
|
257
|
+
});
|
|
258
|
+
compositeEvaluationResultError.extend({});
|
|
259
|
+
const CompositeEvaluationCustomSpecification = {
|
|
260
|
+
};
|
|
261
|
+
/* ------------------------------------------------------------------------- */
|
|
262
|
+
var CompositeEvaluationMetric;
|
|
263
|
+
(function (CompositeEvaluationMetric) {
|
|
264
|
+
CompositeEvaluationMetric["Average"] = "average";
|
|
265
|
+
CompositeEvaluationMetric["Weighted"] = "weighted";
|
|
266
|
+
CompositeEvaluationMetric["Custom"] = "custom";
|
|
267
|
+
})(CompositeEvaluationMetric || (CompositeEvaluationMetric = {}));
|
|
268
|
+
const CompositeEvaluationSpecification = {
|
|
269
|
+
// prettier-ignore
|
|
270
|
+
metrics: {
|
|
271
|
+
[CompositeEvaluationMetric.Average]: CompositeEvaluationAverageSpecification,
|
|
272
|
+
[CompositeEvaluationMetric.Weighted]: CompositeEvaluationWeightedSpecification,
|
|
273
|
+
[CompositeEvaluationMetric.Custom]: CompositeEvaluationCustomSpecification,
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
|
|
481
277
|
const humanEvaluationConfiguration = baseEvaluationConfiguration.extend({
|
|
278
|
+
enableControls: zod.z.boolean().optional(),
|
|
482
279
|
criteria: zod.z.string().optional(),
|
|
483
280
|
});
|
|
484
281
|
const humanEvaluationResultMetadata = baseEvaluationResultMetadata.extend({
|
|
@@ -619,7 +416,9 @@ const LlmEvaluationSpecification = {
|
|
|
619
416
|
};
|
|
620
417
|
|
|
621
418
|
const ruleEvaluationConfiguration = baseEvaluationConfiguration.extend({});
|
|
622
|
-
const ruleEvaluationResultMetadata = baseEvaluationResultMetadata.extend({
|
|
419
|
+
const ruleEvaluationResultMetadata = baseEvaluationResultMetadata.extend({
|
|
420
|
+
reason: zod.z.string().optional(),
|
|
421
|
+
});
|
|
623
422
|
const ruleEvaluationResultError = baseEvaluationResultError.extend({});
|
|
624
423
|
// EXACT MATCH
|
|
625
424
|
const ruleEvaluationExactMatchConfiguration = ruleEvaluationConfiguration.extend({
|
|
@@ -729,12 +528,14 @@ var EvaluationType;
|
|
|
729
528
|
EvaluationType["Rule"] = "rule";
|
|
730
529
|
EvaluationType["Llm"] = "llm";
|
|
731
530
|
EvaluationType["Human"] = "human";
|
|
531
|
+
EvaluationType["Composite"] = "composite";
|
|
732
532
|
})(EvaluationType || (EvaluationType = {}));
|
|
733
|
-
const EvaluationTypeSchema = zod.z.
|
|
533
|
+
const EvaluationTypeSchema = zod.z.enum(EvaluationType);
|
|
734
534
|
const EvaluationMetricSchema = zod.z.union([
|
|
735
|
-
zod.z.
|
|
736
|
-
zod.z.
|
|
737
|
-
zod.z.
|
|
535
|
+
zod.z.enum(RuleEvaluationMetric),
|
|
536
|
+
zod.z.enum(LlmEvaluationMetric),
|
|
537
|
+
zod.z.enum(HumanEvaluationMetric),
|
|
538
|
+
zod.z.enum(CompositeEvaluationMetric),
|
|
738
539
|
]);
|
|
739
540
|
const EvaluationConfigurationSchema = zod.z.custom();
|
|
740
541
|
// prettier-ignore
|
|
@@ -745,6 +546,7 @@ zod.z.custom();
|
|
|
745
546
|
[EvaluationType.Rule]: RuleEvaluationSpecification,
|
|
746
547
|
[EvaluationType.Llm]: LlmEvaluationSpecification,
|
|
747
548
|
[EvaluationType.Human]: HumanEvaluationSpecification,
|
|
549
|
+
[EvaluationType.Composite]: CompositeEvaluationSpecification,
|
|
748
550
|
});
|
|
749
551
|
zod.z.object({
|
|
750
552
|
name: zod.z.string(),
|
|
@@ -758,7 +560,6 @@ zod.z.object({
|
|
|
758
560
|
enableSuggestions: zod.z.boolean().nullable().optional(),
|
|
759
561
|
autoApplySuggestions: zod.z.boolean().nullable().optional(),
|
|
760
562
|
});
|
|
761
|
-
Object.values(SegmentSource).filter((source) => source !== SegmentSource.Evaluation && source !== SegmentSource.Experiment);
|
|
762
563
|
|
|
763
564
|
var LegacyChainEventTypes;
|
|
764
565
|
(function (LegacyChainEventTypes) {
|
|
@@ -779,17 +580,71 @@ var ChainEventTypes;
|
|
|
779
580
|
ChainEventTypes["StepCompleted"] = "step-completed";
|
|
780
581
|
ChainEventTypes["StepStarted"] = "step-started";
|
|
781
582
|
ChainEventTypes["ToolCompleted"] = "tool-completed";
|
|
782
|
-
ChainEventTypes["ToolsRequested"] = "tools-requested";
|
|
783
583
|
ChainEventTypes["ToolResult"] = "tool-result";
|
|
784
584
|
ChainEventTypes["ToolsStarted"] = "tools-started";
|
|
785
585
|
})(ChainEventTypes || (ChainEventTypes = {}));
|
|
786
586
|
|
|
587
|
+
zod.z.object({
|
|
588
|
+
name: zod.z.string(),
|
|
589
|
+
provider: zod.z.string(),
|
|
590
|
+
model: zod.z.string(),
|
|
591
|
+
temperature: zod.z.number(),
|
|
592
|
+
});
|
|
593
|
+
// Experiment ran from a dataset
|
|
594
|
+
const experimentDatasetSourceSchema = zod.z.object({
|
|
595
|
+
source: zod.z.literal('dataset'),
|
|
596
|
+
datasetId: zod.z.number(),
|
|
597
|
+
fromRow: zod.z.number(),
|
|
598
|
+
toRow: zod.z.number(),
|
|
599
|
+
datasetLabels: zod.z.record(zod.z.string(), zod.z.string()),
|
|
600
|
+
parametersMap: zod.z.record(zod.z.string(), zod.z.number()),
|
|
601
|
+
});
|
|
602
|
+
// Experiment ran from last logs (from commit and creation time of experiment)
|
|
603
|
+
const experimentLogsSourceSchema = zod.z.object({
|
|
604
|
+
source: zod.z.literal('logs'),
|
|
605
|
+
count: zod.z.number(),
|
|
606
|
+
});
|
|
607
|
+
// Experiment ran with manual parameters (currently only used for prompts with no parameters)
|
|
608
|
+
const experimentManualSourceSchema = zod.z.object({
|
|
609
|
+
source: zod.z.literal('manual'),
|
|
610
|
+
count: zod.z.number(),
|
|
611
|
+
parametersMap: zod.z.record(zod.z.string(), zod.z.number()),
|
|
612
|
+
});
|
|
613
|
+
zod.z.discriminatedUnion('source', [
|
|
614
|
+
experimentDatasetSourceSchema,
|
|
615
|
+
experimentLogsSourceSchema,
|
|
616
|
+
experimentManualSourceSchema,
|
|
617
|
+
]);
|
|
618
|
+
|
|
619
|
+
var QuotaType;
|
|
620
|
+
(function (QuotaType) {
|
|
621
|
+
QuotaType["Seats"] = "seats";
|
|
622
|
+
QuotaType["Runs"] = "runs";
|
|
623
|
+
QuotaType["Credits"] = "credits";
|
|
624
|
+
})(QuotaType || (QuotaType = {}));
|
|
625
|
+
var GrantSource;
|
|
626
|
+
(function (GrantSource) {
|
|
627
|
+
GrantSource["System"] = "system";
|
|
628
|
+
GrantSource["Subscription"] = "subscription";
|
|
629
|
+
GrantSource["Purchase"] = "purchase";
|
|
630
|
+
GrantSource["Reward"] = "reward";
|
|
631
|
+
GrantSource["Promocode"] = "promocode";
|
|
632
|
+
})(GrantSource || (GrantSource = {}));
|
|
633
|
+
|
|
634
|
+
var ModifiedDocumentType;
|
|
635
|
+
(function (ModifiedDocumentType) {
|
|
636
|
+
ModifiedDocumentType["Created"] = "created";
|
|
637
|
+
ModifiedDocumentType["Updated"] = "updated";
|
|
638
|
+
ModifiedDocumentType["UpdatedPath"] = "updated_path";
|
|
639
|
+
ModifiedDocumentType["Deleted"] = "deleted";
|
|
640
|
+
})(ModifiedDocumentType || (ModifiedDocumentType = {}));
|
|
641
|
+
|
|
787
642
|
var IntegrationType;
|
|
788
643
|
(function (IntegrationType) {
|
|
789
644
|
IntegrationType["Latitude"] = "latitude";
|
|
790
645
|
IntegrationType["ExternalMCP"] = "custom_mcp";
|
|
791
|
-
IntegrationType["HostedMCP"] = "mcp_server";
|
|
792
646
|
IntegrationType["Pipedream"] = "pipedream";
|
|
647
|
+
IntegrationType["HostedMCP"] = "mcp_server";
|
|
793
648
|
})(IntegrationType || (IntegrationType = {}));
|
|
794
649
|
var HostedIntegrationType;
|
|
795
650
|
(function (HostedIntegrationType) {
|
|
@@ -886,13 +741,40 @@ var HostedIntegrationType;
|
|
|
886
741
|
// Loops = 'loops', // Does not exist
|
|
887
742
|
})(HostedIntegrationType || (HostedIntegrationType = {}));
|
|
888
743
|
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
744
|
+
var LogSources;
|
|
745
|
+
(function (LogSources) {
|
|
746
|
+
LogSources["API"] = "api";
|
|
747
|
+
LogSources["AgentAsTool"] = "agent_as_tool";
|
|
748
|
+
LogSources["Copilot"] = "copilot";
|
|
749
|
+
LogSources["EmailTrigger"] = "email_trigger";
|
|
750
|
+
LogSources["Evaluation"] = "evaluation";
|
|
751
|
+
LogSources["Experiment"] = "experiment";
|
|
752
|
+
LogSources["IntegrationTrigger"] = "integration_trigger";
|
|
753
|
+
LogSources["Playground"] = "playground";
|
|
754
|
+
LogSources["ScheduledTrigger"] = "scheduled_trigger";
|
|
755
|
+
LogSources["SharedPrompt"] = "shared_prompt";
|
|
756
|
+
LogSources["ShadowTest"] = "shadow_test";
|
|
757
|
+
LogSources["ABTestChallenger"] = "ab_test_challenger";
|
|
758
|
+
LogSources["User"] = "user";
|
|
759
|
+
})(LogSources || (LogSources = {}));
|
|
760
|
+
|
|
761
|
+
var RunSourceGroup;
|
|
762
|
+
(function (RunSourceGroup) {
|
|
763
|
+
RunSourceGroup["Production"] = "production";
|
|
764
|
+
RunSourceGroup["Playground"] = "playground";
|
|
765
|
+
})(RunSourceGroup || (RunSourceGroup = {}));
|
|
766
|
+
({
|
|
767
|
+
[RunSourceGroup.Production]: [
|
|
768
|
+
LogSources.API,
|
|
769
|
+
LogSources.Copilot,
|
|
770
|
+
LogSources.EmailTrigger,
|
|
771
|
+
LogSources.IntegrationTrigger,
|
|
772
|
+
LogSources.ScheduledTrigger,
|
|
773
|
+
LogSources.SharedPrompt,
|
|
774
|
+
LogSources.User,
|
|
775
|
+
],
|
|
776
|
+
[RunSourceGroup.Playground]: [LogSources.Playground, LogSources.Experiment],
|
|
777
|
+
});
|
|
896
778
|
|
|
897
779
|
var MessageRole;
|
|
898
780
|
(function (MessageRole) {
|
|
@@ -902,13 +784,242 @@ var MessageRole;
|
|
|
902
784
|
MessageRole["tool"] = "tool";
|
|
903
785
|
})(MessageRole || (MessageRole = {}));
|
|
904
786
|
|
|
905
|
-
var
|
|
906
|
-
(function (
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
787
|
+
var SpanKind;
|
|
788
|
+
(function (SpanKind) {
|
|
789
|
+
SpanKind["Internal"] = "internal";
|
|
790
|
+
SpanKind["Server"] = "server";
|
|
791
|
+
SpanKind["Client"] = "client";
|
|
792
|
+
SpanKind["Producer"] = "producer";
|
|
793
|
+
SpanKind["Consumer"] = "consumer";
|
|
794
|
+
})(SpanKind || (SpanKind = {}));
|
|
795
|
+
// Note: loosely based on OpenTelemetry GenAI semantic conventions
|
|
796
|
+
var SpanType;
|
|
797
|
+
(function (SpanType) {
|
|
798
|
+
SpanType["Tool"] = "tool";
|
|
799
|
+
SpanType["Completion"] = "completion";
|
|
800
|
+
SpanType["Embedding"] = "embedding";
|
|
801
|
+
SpanType["Retrieval"] = "retrieval";
|
|
802
|
+
SpanType["Reranking"] = "reranking";
|
|
803
|
+
SpanType["Http"] = "http";
|
|
804
|
+
SpanType["Unknown"] = "unknown";
|
|
805
|
+
SpanType["Prompt"] = "prompt";
|
|
806
|
+
SpanType["Step"] = "step";
|
|
807
|
+
})(SpanType || (SpanType = {}));
|
|
808
|
+
const SPAN_SPECIFICATIONS = {
|
|
809
|
+
[SpanType.Tool]: {
|
|
810
|
+
name: 'Tool',
|
|
811
|
+
description: 'A tool call',
|
|
812
|
+
isGenAI: true,
|
|
813
|
+
isHidden: false,
|
|
814
|
+
},
|
|
815
|
+
[SpanType.Completion]: {
|
|
816
|
+
name: 'Completion',
|
|
817
|
+
description: 'A completion call',
|
|
818
|
+
isGenAI: true,
|
|
819
|
+
isHidden: false,
|
|
820
|
+
},
|
|
821
|
+
[SpanType.Embedding]: {
|
|
822
|
+
name: 'Embedding',
|
|
823
|
+
description: 'An embedding call',
|
|
824
|
+
isGenAI: true,
|
|
825
|
+
isHidden: false,
|
|
826
|
+
},
|
|
827
|
+
[SpanType.Retrieval]: {
|
|
828
|
+
name: 'Retrieval',
|
|
829
|
+
description: 'A retrieval call',
|
|
830
|
+
isGenAI: true,
|
|
831
|
+
isHidden: false,
|
|
832
|
+
},
|
|
833
|
+
[SpanType.Reranking]: {
|
|
834
|
+
name: 'Reranking',
|
|
835
|
+
description: 'A reranking call',
|
|
836
|
+
isGenAI: true,
|
|
837
|
+
isHidden: false,
|
|
838
|
+
},
|
|
839
|
+
[SpanType.Http]: {
|
|
840
|
+
name: 'HTTP',
|
|
841
|
+
description: 'An HTTP request',
|
|
842
|
+
isGenAI: false,
|
|
843
|
+
isHidden: true,
|
|
844
|
+
},
|
|
845
|
+
[SpanType.Unknown]: {
|
|
846
|
+
name: 'Unknown',
|
|
847
|
+
description: 'An unknown span',
|
|
848
|
+
isGenAI: false,
|
|
849
|
+
isHidden: true,
|
|
850
|
+
},
|
|
851
|
+
[SpanType.Prompt]: {
|
|
852
|
+
name: 'Prompt',
|
|
853
|
+
description: 'A prompt span',
|
|
854
|
+
isGenAI: false,
|
|
855
|
+
isHidden: false,
|
|
856
|
+
},
|
|
857
|
+
[SpanType.Step]: {
|
|
858
|
+
name: 'Step',
|
|
859
|
+
description: 'A step span',
|
|
860
|
+
isGenAI: false,
|
|
861
|
+
isHidden: false,
|
|
862
|
+
},
|
|
863
|
+
};
|
|
864
|
+
var SpanStatus;
|
|
865
|
+
(function (SpanStatus) {
|
|
866
|
+
SpanStatus["Unset"] = "unset";
|
|
867
|
+
SpanStatus["Ok"] = "ok";
|
|
868
|
+
SpanStatus["Error"] = "error";
|
|
869
|
+
})(SpanStatus || (SpanStatus = {}));
|
|
870
|
+
|
|
871
|
+
// Note: Traces are unmaterialized but this context is used to propagate the trace
|
|
872
|
+
// See www.w3.org/TR/trace-context and w3c.github.io/baggage
|
|
873
|
+
zod.z.object({
|
|
874
|
+
traceparent: zod.z.string(), // <version>-<trace-id>-<span-id>-<trace-flags>
|
|
875
|
+
tracestate: zod.z.string().optional(), // <key>=urlencoded(<value>)[,<key>=urlencoded(<value>)]*
|
|
876
|
+
baggage: zod.z.string().optional(), // <key>=urlencoded(<value>)[,<key>=urlencoded(<value>)]*
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
/* Note: Instrumentation scopes from all language SDKs */
|
|
880
|
+
const SCOPE_LATITUDE = 'so.latitude.instrumentation';
|
|
881
|
+
var InstrumentationScope;
|
|
882
|
+
(function (InstrumentationScope) {
|
|
883
|
+
InstrumentationScope["Manual"] = "manual";
|
|
884
|
+
InstrumentationScope["Latitude"] = "latitude";
|
|
885
|
+
InstrumentationScope["OpenAI"] = "openai";
|
|
886
|
+
InstrumentationScope["Anthropic"] = "anthropic";
|
|
887
|
+
InstrumentationScope["AzureOpenAI"] = "azure";
|
|
888
|
+
InstrumentationScope["VercelAI"] = "vercelai";
|
|
889
|
+
InstrumentationScope["VertexAI"] = "vertexai";
|
|
890
|
+
InstrumentationScope["AIPlatform"] = "aiplatform";
|
|
891
|
+
InstrumentationScope["MistralAI"] = "mistralai";
|
|
892
|
+
InstrumentationScope["Bedrock"] = "bedrock";
|
|
893
|
+
InstrumentationScope["Sagemaker"] = "sagemaker";
|
|
894
|
+
InstrumentationScope["TogetherAI"] = "togetherai";
|
|
895
|
+
InstrumentationScope["Replicate"] = "replicate";
|
|
896
|
+
InstrumentationScope["Groq"] = "groq";
|
|
897
|
+
InstrumentationScope["Cohere"] = "cohere";
|
|
898
|
+
InstrumentationScope["LiteLLM"] = "litellm";
|
|
899
|
+
InstrumentationScope["Langchain"] = "langchain";
|
|
900
|
+
InstrumentationScope["LlamaIndex"] = "llamaindex";
|
|
901
|
+
InstrumentationScope["DSPy"] = "dspy";
|
|
902
|
+
InstrumentationScope["Haystack"] = "haystack";
|
|
903
|
+
InstrumentationScope["Ollama"] = "ollama";
|
|
904
|
+
InstrumentationScope["Transformers"] = "transformers";
|
|
905
|
+
InstrumentationScope["AlephAlpha"] = "alephalpha";
|
|
906
|
+
})(InstrumentationScope || (InstrumentationScope = {}));
|
|
907
|
+
/* Note: non-standard OpenTelemetry semantic conventions used in Latitude */
|
|
908
|
+
const ATTR_LATITUDE = 'latitude';
|
|
909
|
+
const ATTR_LATITUDE_TYPE = `${ATTR_LATITUDE}.type`;
|
|
910
|
+
const ATTR_LATITUDE_TEST_DEPLOYMENT_ID = `${ATTR_LATITUDE}.test_deployment_id`;
|
|
911
|
+
const GEN_AI_TOOL_TYPE_VALUE_FUNCTION = 'function';
|
|
912
|
+
const ATTR_GEN_AI_TOOL_CALL_ARGUMENTS = 'gen_ai.tool.call.arguments';
|
|
913
|
+
const ATTR_GEN_AI_TOOL_RESULT_VALUE = 'gen_ai.tool.result.value';
|
|
914
|
+
const ATTR_GEN_AI_TOOL_RESULT_IS_ERROR = 'gen_ai.tool.result.is_error';
|
|
915
|
+
const ATTR_GEN_AI_REQUEST = 'gen_ai.request';
|
|
916
|
+
const ATTR_GEN_AI_REQUEST_CONFIGURATION = 'gen_ai.request.configuration';
|
|
917
|
+
const ATTR_GEN_AI_REQUEST_TEMPLATE = 'gen_ai.request.template';
|
|
918
|
+
const ATTR_GEN_AI_REQUEST_PARAMETERS = 'gen_ai.request.parameters';
|
|
919
|
+
const ATTR_GEN_AI_REQUEST_MESSAGES = 'gen_ai.request.messages';
|
|
920
|
+
const ATTR_GEN_AI_RESPONSE = 'gen_ai.response';
|
|
921
|
+
const ATTR_GEN_AI_RESPONSE_MESSAGES = 'gen_ai.response.messages';
|
|
922
|
+
const ATTR_GEN_AI_USAGE_PROMPT_TOKENS = 'gen_ai.usage.prompt_tokens';
|
|
923
|
+
const ATTR_GEN_AI_USAGE_CACHED_TOKENS = 'gen_ai.usage.cached_tokens';
|
|
924
|
+
const ATTR_GEN_AI_USAGE_REASONING_TOKENS = 'gen_ai.usage.reasoning_tokens'; // prettier-ignore
|
|
925
|
+
const ATTR_GEN_AI_USAGE_COMPLETION_TOKENS = 'gen_ai.usage.completion_tokens'; // prettier-ignore
|
|
926
|
+
const ATTR_GEN_AI_PROMPTS = 'gen_ai.prompt'; // gen_ai.prompt.{index}.{role/content/...}
|
|
927
|
+
const ATTR_GEN_AI_COMPLETIONS = 'gen_ai.completion'; // gen_ai.completion.{index}.{role/content/...}
|
|
928
|
+
const ATTR_GEN_AI_MESSAGE_ROLE = 'role';
|
|
929
|
+
const ATTR_GEN_AI_MESSAGE_CONTENT = 'content'; // string or object
|
|
930
|
+
const ATTR_GEN_AI_MESSAGE_TOOL_NAME = 'tool_name';
|
|
931
|
+
const ATTR_GEN_AI_MESSAGE_TOOL_CALL_ID = 'tool_call_id';
|
|
932
|
+
const ATTR_GEN_AI_MESSAGE_TOOL_RESULT_IS_ERROR = 'is_error';
|
|
933
|
+
const ATTR_GEN_AI_MESSAGE_TOOL_CALLS = 'tool_calls'; // gen_ai.completion.{index}.tool_calls.{index}.{id/name/arguments}
|
|
934
|
+
const ATTR_GEN_AI_MESSAGE_TOOL_CALLS_ID = 'id';
|
|
935
|
+
const ATTR_GEN_AI_MESSAGE_TOOL_CALLS_NAME = 'name';
|
|
936
|
+
const ATTR_GEN_AI_MESSAGE_TOOL_CALLS_ARGUMENTS = 'arguments';
|
|
937
|
+
const GEN_AI_RESPONSE_FINISH_REASON_VALUE_STOP = 'stop';
|
|
938
|
+
const GEN_AI_RESPONSE_FINISH_REASON_VALUE_TOOL_CALLS = 'tool_calls';
|
|
939
|
+
const ATTR_HTTP_REQUEST_URL = 'http.request.url';
|
|
940
|
+
const ATTR_HTTP_REQUEST_BODY = 'http.request.body';
|
|
941
|
+
const ATTR_HTTP_REQUEST_HEADER = 'http.request.header';
|
|
942
|
+
const ATTR_HTTP_RESPONSE_BODY = 'http.response.body';
|
|
943
|
+
const ATTR_HTTP_RESPONSE_HEADER = 'http.response.header';
|
|
944
|
+
/* Note: Schemas for span ingestion following OpenTelemetry service request specification */
|
|
945
|
+
var Otlp;
|
|
946
|
+
(function (Otlp) {
|
|
947
|
+
Otlp.attributeValueSchema = zod.z.object({
|
|
948
|
+
stringValue: zod.z.string().optional(),
|
|
949
|
+
intValue: zod.z.number().optional(),
|
|
950
|
+
boolValue: zod.z.boolean().optional(),
|
|
951
|
+
arrayValue: zod.z
|
|
952
|
+
.object({
|
|
953
|
+
values: zod.z.array(zod.z.object({
|
|
954
|
+
stringValue: zod.z.string().optional(),
|
|
955
|
+
intValue: zod.z.number().optional(),
|
|
956
|
+
boolValue: zod.z.boolean().optional(),
|
|
957
|
+
})),
|
|
958
|
+
})
|
|
959
|
+
.optional(),
|
|
960
|
+
});
|
|
961
|
+
Otlp.attributeSchema = zod.z.object({
|
|
962
|
+
key: zod.z.string(),
|
|
963
|
+
value: Otlp.attributeValueSchema,
|
|
964
|
+
});
|
|
965
|
+
Otlp.eventSchema = zod.z.object({
|
|
966
|
+
name: zod.z.string(),
|
|
967
|
+
timeUnixNano: zod.z.string(),
|
|
968
|
+
attributes: zod.z.array(Otlp.attributeSchema).optional(),
|
|
969
|
+
});
|
|
970
|
+
Otlp.linkSchema = zod.z.object({
|
|
971
|
+
traceId: zod.z.string(),
|
|
972
|
+
spanId: zod.z.string(),
|
|
973
|
+
attributes: zod.z.array(Otlp.attributeSchema).optional(),
|
|
974
|
+
});
|
|
975
|
+
(function (StatusCode) {
|
|
976
|
+
StatusCode[StatusCode["Unset"] = 0] = "Unset";
|
|
977
|
+
StatusCode[StatusCode["Ok"] = 1] = "Ok";
|
|
978
|
+
StatusCode[StatusCode["Error"] = 2] = "Error";
|
|
979
|
+
})(Otlp.StatusCode || (Otlp.StatusCode = {}));
|
|
980
|
+
Otlp.statusSchema = zod.z.object({
|
|
981
|
+
code: zod.z.number(),
|
|
982
|
+
message: zod.z.string().optional(),
|
|
983
|
+
});
|
|
984
|
+
(function (SpanKind) {
|
|
985
|
+
SpanKind[SpanKind["Internal"] = 0] = "Internal";
|
|
986
|
+
SpanKind[SpanKind["Server"] = 1] = "Server";
|
|
987
|
+
SpanKind[SpanKind["Client"] = 2] = "Client";
|
|
988
|
+
SpanKind[SpanKind["Producer"] = 3] = "Producer";
|
|
989
|
+
SpanKind[SpanKind["Consumer"] = 4] = "Consumer";
|
|
990
|
+
})(Otlp.SpanKind || (Otlp.SpanKind = {}));
|
|
991
|
+
Otlp.spanSchema = zod.z.object({
|
|
992
|
+
traceId: zod.z.string(),
|
|
993
|
+
spanId: zod.z.string(),
|
|
994
|
+
parentSpanId: zod.z.string().optional(),
|
|
995
|
+
name: zod.z.string(),
|
|
996
|
+
kind: zod.z.number(),
|
|
997
|
+
startTimeUnixNano: zod.z.string(),
|
|
998
|
+
endTimeUnixNano: zod.z.string(),
|
|
999
|
+
status: Otlp.statusSchema.optional(),
|
|
1000
|
+
events: zod.z.array(Otlp.eventSchema).optional(),
|
|
1001
|
+
links: zod.z.array(Otlp.linkSchema).optional(),
|
|
1002
|
+
attributes: zod.z.array(Otlp.attributeSchema).optional(),
|
|
1003
|
+
});
|
|
1004
|
+
Otlp.scopeSchema = zod.z.object({
|
|
1005
|
+
name: zod.z.string(),
|
|
1006
|
+
version: zod.z.string().optional(),
|
|
1007
|
+
});
|
|
1008
|
+
Otlp.scopeSpanSchema = zod.z.object({
|
|
1009
|
+
scope: Otlp.scopeSchema,
|
|
1010
|
+
spans: zod.z.array(Otlp.spanSchema),
|
|
1011
|
+
});
|
|
1012
|
+
Otlp.resourceSchema = zod.z.object({
|
|
1013
|
+
attributes: zod.z.array(Otlp.attributeSchema),
|
|
1014
|
+
});
|
|
1015
|
+
Otlp.resourceSpanSchema = zod.z.object({
|
|
1016
|
+
resource: Otlp.resourceSchema,
|
|
1017
|
+
scopeSpans: zod.z.array(Otlp.scopeSpanSchema),
|
|
1018
|
+
});
|
|
1019
|
+
Otlp.serviceRequestSchema = zod.z.object({
|
|
1020
|
+
resourceSpans: zod.z.array(Otlp.resourceSpanSchema),
|
|
1021
|
+
});
|
|
1022
|
+
})(Otlp || (Otlp = {}));
|
|
912
1023
|
|
|
913
1024
|
// TODO(tracing): deprecated
|
|
914
1025
|
const HEAD_COMMIT = 'live';
|
|
@@ -939,6 +1050,12 @@ var DocumentTriggerType;
|
|
|
939
1050
|
DocumentTriggerType["Scheduled"] = "scheduled";
|
|
940
1051
|
DocumentTriggerType["Integration"] = "integration";
|
|
941
1052
|
})(DocumentTriggerType || (DocumentTriggerType = {}));
|
|
1053
|
+
var DocumentTriggerStatus;
|
|
1054
|
+
(function (DocumentTriggerStatus) {
|
|
1055
|
+
DocumentTriggerStatus["Pending"] = "pending";
|
|
1056
|
+
DocumentTriggerStatus["Deployed"] = "deployed";
|
|
1057
|
+
DocumentTriggerStatus["Deprecated"] = "deprecated";
|
|
1058
|
+
})(DocumentTriggerStatus || (DocumentTriggerStatus = {}));
|
|
942
1059
|
var DocumentTriggerParameters;
|
|
943
1060
|
(function (DocumentTriggerParameters) {
|
|
944
1061
|
DocumentTriggerParameters["SenderEmail"] = "senderEmail";
|
|
@@ -950,11 +1067,9 @@ var DocumentTriggerParameters;
|
|
|
950
1067
|
|
|
951
1068
|
class ManualInstrumentation {
|
|
952
1069
|
enabled;
|
|
953
|
-
source;
|
|
954
1070
|
tracer;
|
|
955
|
-
constructor(
|
|
1071
|
+
constructor(tracer) {
|
|
956
1072
|
this.enabled = false;
|
|
957
|
-
this.source = source;
|
|
958
1073
|
this.tracer = tracer;
|
|
959
1074
|
}
|
|
960
1075
|
isEnabled() {
|
|
@@ -966,96 +1081,9 @@ class ManualInstrumentation {
|
|
|
966
1081
|
disable() {
|
|
967
1082
|
this.enabled = false;
|
|
968
1083
|
}
|
|
969
|
-
baggage(ctx) {
|
|
970
|
-
if ('traceparent' in ctx) {
|
|
971
|
-
ctx = otel.propagation.extract(otel__namespace.ROOT_CONTEXT, ctx);
|
|
972
|
-
}
|
|
973
|
-
const baggage = Object.fromEntries(otel.propagation.getBaggage(ctx)?.getAllEntries() || []);
|
|
974
|
-
if (!(ATTR_LATITUDE_SEGMENT_ID in baggage) ||
|
|
975
|
-
!(ATTR_LATITUDE_SEGMENTS in baggage)) {
|
|
976
|
-
return undefined;
|
|
977
|
-
}
|
|
978
|
-
const segment = {
|
|
979
|
-
id: baggage[ATTR_LATITUDE_SEGMENT_ID].value,
|
|
980
|
-
parentId: baggage[ATTR_LATITUDE_SEGMENT_PARENT_ID]?.value,
|
|
981
|
-
};
|
|
982
|
-
let segments = [];
|
|
983
|
-
try {
|
|
984
|
-
segments = JSON.parse(baggage[ATTR_LATITUDE_SEGMENTS].value);
|
|
985
|
-
}
|
|
986
|
-
catch (error) {
|
|
987
|
-
return undefined;
|
|
988
|
-
}
|
|
989
|
-
if (segments.length < 1) {
|
|
990
|
-
return undefined;
|
|
991
|
-
}
|
|
992
|
-
return { segment, segments };
|
|
993
|
-
}
|
|
994
|
-
setBaggage(ctx, baggage, extra) {
|
|
995
|
-
let parent = Object.fromEntries(otel.propagation.getBaggage(ctx)?.getAllEntries() || []);
|
|
996
|
-
parent = Object.fromEntries(Object.entries(parent).filter(([attribute]) => attribute !== ATTR_LATITUDE_SEGMENT_ID &&
|
|
997
|
-
attribute !== ATTR_LATITUDE_SEGMENT_PARENT_ID &&
|
|
998
|
-
attribute !== ATTR_LATITUDE_SEGMENTS));
|
|
999
|
-
if (!baggage) {
|
|
1000
|
-
const payload = otel.propagation.createBaggage({ ...parent, ...(extra || {}) });
|
|
1001
|
-
return otel.propagation.setBaggage(ctx, payload);
|
|
1002
|
-
}
|
|
1003
|
-
let jsonSegments = '';
|
|
1004
|
-
try {
|
|
1005
|
-
jsonSegments = JSON.stringify(baggage.segments);
|
|
1006
|
-
}
|
|
1007
|
-
catch (error) {
|
|
1008
|
-
jsonSegments = '[]';
|
|
1009
|
-
}
|
|
1010
|
-
const payload = otel.propagation.createBaggage({
|
|
1011
|
-
...parent,
|
|
1012
|
-
[ATTR_LATITUDE_SEGMENT_ID]: { value: baggage.segment.id },
|
|
1013
|
-
...(baggage.segment.parentId && {
|
|
1014
|
-
[ATTR_LATITUDE_SEGMENT_PARENT_ID]: { value: baggage.segment.parentId },
|
|
1015
|
-
}),
|
|
1016
|
-
[ATTR_LATITUDE_SEGMENTS]: { value: jsonSegments },
|
|
1017
|
-
...(extra || {}),
|
|
1018
|
-
});
|
|
1019
|
-
return otel.propagation.setBaggage(ctx, payload);
|
|
1020
|
-
}
|
|
1021
|
-
pause(ctx) {
|
|
1022
|
-
const baggage = this.baggage(ctx);
|
|
1023
|
-
if (baggage) {
|
|
1024
|
-
baggage.segments.at(-1).paused = true;
|
|
1025
|
-
}
|
|
1026
|
-
ctx = this.setBaggage(ctx, baggage);
|
|
1027
|
-
let carrier = {};
|
|
1028
|
-
otel.propagation.inject(ctx, carrier);
|
|
1029
|
-
return carrier;
|
|
1030
|
-
}
|
|
1031
1084
|
resume(ctx) {
|
|
1032
1085
|
return otel.propagation.extract(otel__namespace.ROOT_CONTEXT, ctx);
|
|
1033
1086
|
}
|
|
1034
|
-
restored(ctx) {
|
|
1035
|
-
const baggage = this.baggage(ctx);
|
|
1036
|
-
return !baggage?.segments.some((segment) => segment.paused);
|
|
1037
|
-
}
|
|
1038
|
-
restore(ctx) {
|
|
1039
|
-
let baggage = this.baggage(ctx);
|
|
1040
|
-
if (!baggage)
|
|
1041
|
-
return ctx;
|
|
1042
|
-
const segments = baggage.segments;
|
|
1043
|
-
while (segments.at(-1)?.paused)
|
|
1044
|
-
segments.pop();
|
|
1045
|
-
const segment = segments.at(-1);
|
|
1046
|
-
if (!segment)
|
|
1047
|
-
return otel__namespace.ROOT_CONTEXT;
|
|
1048
|
-
baggage = {
|
|
1049
|
-
segment: { id: segment.id, parentId: segment.parentId },
|
|
1050
|
-
segments: segments,
|
|
1051
|
-
};
|
|
1052
|
-
ctx = this.setBaggage(ctx, baggage);
|
|
1053
|
-
let carrier = {};
|
|
1054
|
-
otel.propagation.inject(ctx, carrier);
|
|
1055
|
-
carrier.traceparent = segment.traceparent;
|
|
1056
|
-
carrier.tracestate = segment.tracestate;
|
|
1057
|
-
return this.resume(carrier);
|
|
1058
|
-
}
|
|
1059
1087
|
capitalize(str) {
|
|
1060
1088
|
if (str.length === 0)
|
|
1061
1089
|
return str;
|
|
@@ -1388,6 +1416,9 @@ class ManualInstrumentation {
|
|
|
1388
1416
|
[ATTR_GEN_AI_REQUEST_MESSAGES]: jsonInput,
|
|
1389
1417
|
...attrInput,
|
|
1390
1418
|
...(start.attributes || {}),
|
|
1419
|
+
['latitude.commitUuid']: start.versionUuid,
|
|
1420
|
+
['latitude.documentUuid']: start.promptUuid,
|
|
1421
|
+
['latitude.experimentUuid']: start.experimentUuid,
|
|
1391
1422
|
},
|
|
1392
1423
|
});
|
|
1393
1424
|
return {
|
|
@@ -1502,49 +1533,7 @@ class ManualInstrumentation {
|
|
|
1502
1533
|
fail: span.fail,
|
|
1503
1534
|
};
|
|
1504
1535
|
}
|
|
1505
|
-
|
|
1506
|
-
options = options || {};
|
|
1507
|
-
let baggage = this.baggage(ctx);
|
|
1508
|
-
const parent = baggage?.segments.at(-1);
|
|
1509
|
-
const segments = baggage?.segments || [];
|
|
1510
|
-
segments.push({
|
|
1511
|
-
...{
|
|
1512
|
-
id: options._internal?.id || uuid.v4(),
|
|
1513
|
-
...(parent?.id && { parentId: parent.id }),
|
|
1514
|
-
source: options._internal?.source || parent?.source || this.source,
|
|
1515
|
-
type: type,
|
|
1516
|
-
data: data,
|
|
1517
|
-
},
|
|
1518
|
-
traceparent: 'undefined',
|
|
1519
|
-
tracestate: undefined,
|
|
1520
|
-
});
|
|
1521
|
-
const segment = segments.at(-1);
|
|
1522
|
-
baggage = {
|
|
1523
|
-
segment: { id: segment.id, parentId: segment.parentId },
|
|
1524
|
-
segments: segments,
|
|
1525
|
-
};
|
|
1526
|
-
ctx = this.setBaggage(ctx, baggage, options.baggage);
|
|
1527
|
-
// Dummy wrapper to force the same trace and carry on some segment attributes
|
|
1528
|
-
const span = this.span(ctx, SEGMENT_SPECIFICATIONS[type].name, SpanType.Segment, { attributes: options.attributes });
|
|
1529
|
-
let carrier = {};
|
|
1530
|
-
otel.propagation.inject(span.context, carrier);
|
|
1531
|
-
baggage.segments.at(-1).traceparent = carrier.traceparent;
|
|
1532
|
-
baggage.segments.at(-1).tracestate = carrier.tracestate;
|
|
1533
|
-
// Fix current segment span segments attribute now that we know the trace
|
|
1534
|
-
otel.trace
|
|
1535
|
-
.getSpan(span.context)
|
|
1536
|
-
.setAttribute(ATTR_LATITUDE_SEGMENTS, JSON.stringify(baggage.segments));
|
|
1537
|
-
ctx = this.setBaggage(span.context, baggage, options.baggage);
|
|
1538
|
-
return { context: ctx, end: span.end, fail: span.fail };
|
|
1539
|
-
}
|
|
1540
|
-
prompt(ctx, { logUuid, versionUuid, promptUuid, experimentUuid, externalId, template, parameters, ...rest }) {
|
|
1541
|
-
const baggage = {
|
|
1542
|
-
...(logUuid && { logUuid }), // TODO(tracing): temporal related log, remove when observability is ready
|
|
1543
|
-
commitUuid: versionUuid || HEAD_COMMIT,
|
|
1544
|
-
documentUuid: promptUuid,
|
|
1545
|
-
...(experimentUuid && { experimentUuid }),
|
|
1546
|
-
...(externalId && { externalId }),
|
|
1547
|
-
};
|
|
1536
|
+
prompt(ctx, { documentLogUuid, versionUuid, promptUuid, projectId, experimentUuid, testDeploymentId, externalId, template, parameters, name, source, ...rest }) {
|
|
1548
1537
|
let jsonParameters = '';
|
|
1549
1538
|
try {
|
|
1550
1539
|
jsonParameters = JSON.stringify(parameters || {});
|
|
@@ -1555,23 +1544,32 @@ class ManualInstrumentation {
|
|
|
1555
1544
|
const attributes = {
|
|
1556
1545
|
[ATTR_GEN_AI_REQUEST_TEMPLATE]: template,
|
|
1557
1546
|
[ATTR_GEN_AI_REQUEST_PARAMETERS]: jsonParameters,
|
|
1547
|
+
['latitude.commitUuid']: versionUuid || HEAD_COMMIT,
|
|
1548
|
+
['latitude.documentUuid']: promptUuid,
|
|
1549
|
+
['latitude.projectId']: projectId,
|
|
1550
|
+
...(documentLogUuid && { ['latitude.documentLogUuid']: documentLogUuid }),
|
|
1551
|
+
...(experimentUuid && { ['latitude.experimentUuid']: experimentUuid }),
|
|
1552
|
+
...(testDeploymentId && {
|
|
1553
|
+
[ATTR_LATITUDE_TEST_DEPLOYMENT_ID]: testDeploymentId,
|
|
1554
|
+
}),
|
|
1555
|
+
...(externalId && { ['latitude.externalId']: externalId }),
|
|
1556
|
+
...(source && { ['latitude.source']: source }),
|
|
1558
1557
|
...(rest.attributes || {}),
|
|
1559
1558
|
};
|
|
1560
|
-
return this.
|
|
1561
|
-
...rest,
|
|
1559
|
+
return this.span(ctx, name || `prompt-${promptUuid}`, SpanType.Prompt, {
|
|
1562
1560
|
attributes,
|
|
1563
1561
|
});
|
|
1564
1562
|
}
|
|
1565
1563
|
step(ctx, options) {
|
|
1566
|
-
return this.
|
|
1564
|
+
return this.span(ctx, 'step', SpanType.Step, options);
|
|
1567
1565
|
}
|
|
1568
1566
|
}
|
|
1569
1567
|
|
|
1570
1568
|
class LatitudeInstrumentation {
|
|
1571
1569
|
options;
|
|
1572
1570
|
telemetry;
|
|
1573
|
-
constructor(
|
|
1574
|
-
this.telemetry = new ManualInstrumentation(
|
|
1571
|
+
constructor(tracer, options) {
|
|
1572
|
+
this.telemetry = new ManualInstrumentation(tracer);
|
|
1575
1573
|
this.options = options;
|
|
1576
1574
|
}
|
|
1577
1575
|
isEnabled() {
|
|
@@ -1729,18 +1727,16 @@ const DEFAULT_SPAN_EXPORTER = (apiKey) => new exporterTraceOtlpHttp.OTLPTraceExp
|
|
|
1729
1727
|
// Note: Only exporting typescript instrumentations
|
|
1730
1728
|
exports.Instrumentation = void 0;
|
|
1731
1729
|
(function (Instrumentation) {
|
|
1732
|
-
Instrumentation["Latitude"] = "latitude";
|
|
1733
|
-
Instrumentation["OpenAI"] = "openai";
|
|
1734
1730
|
Instrumentation["Anthropic"] = "anthropic";
|
|
1735
|
-
Instrumentation["AzureOpenAI"] = "azure";
|
|
1736
|
-
Instrumentation["VercelAI"] = "vercelai";
|
|
1737
|
-
Instrumentation["VertexAI"] = "vertexai";
|
|
1738
1731
|
Instrumentation["AIPlatform"] = "aiplatform";
|
|
1739
1732
|
Instrumentation["Bedrock"] = "bedrock";
|
|
1740
|
-
Instrumentation["TogetherAI"] = "togetherai";
|
|
1741
1733
|
Instrumentation["Cohere"] = "cohere";
|
|
1742
1734
|
Instrumentation["Langchain"] = "langchain";
|
|
1735
|
+
Instrumentation["Latitude"] = "latitude";
|
|
1743
1736
|
Instrumentation["LlamaIndex"] = "llamaindex";
|
|
1737
|
+
Instrumentation["OpenAI"] = "openai";
|
|
1738
|
+
Instrumentation["TogetherAI"] = "togetherai";
|
|
1739
|
+
Instrumentation["VertexAI"] = "vertexai";
|
|
1744
1740
|
})(exports.Instrumentation || (exports.Instrumentation = {}));
|
|
1745
1741
|
class LatitudeTelemetry {
|
|
1746
1742
|
options;
|
|
@@ -1806,136 +1802,37 @@ class LatitudeTelemetry {
|
|
|
1806
1802
|
initInstrumentations() {
|
|
1807
1803
|
this.instrumentations = [];
|
|
1808
1804
|
const tracer = this.tracer(InstrumentationScope.Manual);
|
|
1809
|
-
this.telemetry = new ManualInstrumentation(
|
|
1805
|
+
this.telemetry = new ManualInstrumentation(tracer);
|
|
1810
1806
|
this.instrumentations.push(this.telemetry);
|
|
1811
1807
|
const latitude = this.options.instrumentations?.latitude;
|
|
1812
1808
|
if (latitude) {
|
|
1813
1809
|
const tracer = this.tracer(exports.Instrumentation.Latitude);
|
|
1814
|
-
const instrumentation = new LatitudeInstrumentation(
|
|
1810
|
+
const instrumentation = new LatitudeInstrumentation(tracer, typeof latitude === 'object' ? latitude : { module: latitude });
|
|
1815
1811
|
this.instrumentations.push(instrumentation);
|
|
1816
1812
|
}
|
|
1817
|
-
const
|
|
1818
|
-
|
|
1819
|
-
const provider = this.tracerProvider(
|
|
1820
|
-
const instrumentation$1 = new
|
|
1821
|
-
instrumentation$1.setTracerProvider(provider);
|
|
1822
|
-
instrumentation$1.manuallyInstrument(openai);
|
|
1823
|
-
instrumentation.registerInstrumentations({
|
|
1824
|
-
instrumentations: [instrumentation$1],
|
|
1825
|
-
tracerProvider: provider,
|
|
1826
|
-
});
|
|
1827
|
-
this.instrumentations.push(instrumentation$1);
|
|
1828
|
-
}
|
|
1829
|
-
const anthropic = this.options.instrumentations?.anthropic;
|
|
1830
|
-
if (anthropic) {
|
|
1831
|
-
const provider = this.tracerProvider(exports.Instrumentation.Anthropic);
|
|
1832
|
-
const instrumentation$1 = new instrumentationAnthropic.AnthropicInstrumentation();
|
|
1813
|
+
const configureInstrumentation = (instrumentationType, InstrumentationConstructor, instrumentationOptions) => {
|
|
1814
|
+
const providerPkg = this.options.instrumentations?.[instrumentationType];
|
|
1815
|
+
const provider = this.tracerProvider(instrumentationType);
|
|
1816
|
+
const instrumentation$1 = new InstrumentationConstructor(instrumentationOptions); // prettier-ignore
|
|
1833
1817
|
instrumentation$1.setTracerProvider(provider);
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
tracerProvider: provider,
|
|
1838
|
-
});
|
|
1839
|
-
this.instrumentations.push(instrumentation$1);
|
|
1840
|
-
}
|
|
1841
|
-
const azure = this.options.instrumentations?.azure;
|
|
1842
|
-
if (azure) {
|
|
1843
|
-
const provider = this.tracerProvider(exports.Instrumentation.AzureOpenAI);
|
|
1844
|
-
const instrumentation$1 = new instrumentationAzure.AzureOpenAIInstrumentation();
|
|
1845
|
-
instrumentation$1.setTracerProvider(provider);
|
|
1846
|
-
instrumentation$1.manuallyInstrument(azure);
|
|
1847
|
-
instrumentation.registerInstrumentations({
|
|
1848
|
-
instrumentations: [instrumentation$1],
|
|
1849
|
-
tracerProvider: provider,
|
|
1850
|
-
});
|
|
1851
|
-
this.instrumentations.push(instrumentation$1);
|
|
1852
|
-
}
|
|
1853
|
-
const vertexai = this.options.instrumentations?.vertexai;
|
|
1854
|
-
if (vertexai) {
|
|
1855
|
-
const provider = this.tracerProvider(exports.Instrumentation.VertexAI);
|
|
1856
|
-
const instrumentation$1 = new instrumentationVertexai.VertexAIInstrumentation();
|
|
1857
|
-
instrumentation$1.setTracerProvider(provider);
|
|
1858
|
-
instrumentation$1.manuallyInstrument(vertexai);
|
|
1859
|
-
instrumentation.registerInstrumentations({
|
|
1860
|
-
instrumentations: [instrumentation$1],
|
|
1861
|
-
tracerProvider: provider,
|
|
1862
|
-
});
|
|
1863
|
-
this.instrumentations.push(instrumentation$1);
|
|
1864
|
-
}
|
|
1865
|
-
const aiplatform = this.options.instrumentations?.aiplatform;
|
|
1866
|
-
if (aiplatform) {
|
|
1867
|
-
const provider = this.tracerProvider(exports.Instrumentation.AIPlatform);
|
|
1868
|
-
const instrumentation$1 = new instrumentationVertexai.AIPlatformInstrumentation();
|
|
1869
|
-
instrumentation$1.setTracerProvider(provider);
|
|
1870
|
-
instrumentation$1.manuallyInstrument(aiplatform);
|
|
1871
|
-
instrumentation.registerInstrumentations({
|
|
1872
|
-
instrumentations: [instrumentation$1],
|
|
1873
|
-
tracerProvider: provider,
|
|
1874
|
-
});
|
|
1875
|
-
this.instrumentations.push(instrumentation$1);
|
|
1876
|
-
}
|
|
1877
|
-
const bedrock = this.options.instrumentations?.bedrock;
|
|
1878
|
-
if (bedrock) {
|
|
1879
|
-
const provider = this.tracerProvider(exports.Instrumentation.Bedrock);
|
|
1880
|
-
const instrumentation$1 = new instrumentationBedrock.BedrockInstrumentation();
|
|
1881
|
-
instrumentation$1.setTracerProvider(provider);
|
|
1882
|
-
instrumentation$1.manuallyInstrument(bedrock);
|
|
1883
|
-
instrumentation.registerInstrumentations({
|
|
1884
|
-
instrumentations: [instrumentation$1],
|
|
1885
|
-
tracerProvider: provider,
|
|
1886
|
-
});
|
|
1887
|
-
this.instrumentations.push(instrumentation$1);
|
|
1888
|
-
}
|
|
1889
|
-
const togetherai = this.options.instrumentations?.togetherai;
|
|
1890
|
-
if (togetherai) {
|
|
1891
|
-
const provider = this.tracerProvider(exports.Instrumentation.TogetherAI);
|
|
1892
|
-
const instrumentation$1 = new instrumentationTogether.TogetherInstrumentation({
|
|
1893
|
-
enrichTokens: true,
|
|
1894
|
-
});
|
|
1895
|
-
instrumentation$1.setTracerProvider(provider);
|
|
1896
|
-
instrumentation$1.manuallyInstrument(togetherai);
|
|
1897
|
-
instrumentation.registerInstrumentations({
|
|
1898
|
-
instrumentations: [instrumentation$1],
|
|
1899
|
-
tracerProvider: provider,
|
|
1900
|
-
});
|
|
1901
|
-
this.instrumentations.push(instrumentation$1);
|
|
1902
|
-
}
|
|
1903
|
-
const cohere = this.options.instrumentations?.cohere;
|
|
1904
|
-
if (cohere) {
|
|
1905
|
-
const provider = this.tracerProvider(exports.Instrumentation.Cohere);
|
|
1906
|
-
const instrumentation$1 = new instrumentationCohere.CohereInstrumentation();
|
|
1907
|
-
instrumentation$1.setTracerProvider(provider);
|
|
1908
|
-
instrumentation$1.manuallyInstrument(cohere);
|
|
1909
|
-
instrumentation.registerInstrumentations({
|
|
1910
|
-
instrumentations: [instrumentation$1],
|
|
1911
|
-
tracerProvider: provider,
|
|
1912
|
-
});
|
|
1913
|
-
this.instrumentations.push(instrumentation$1);
|
|
1914
|
-
}
|
|
1915
|
-
const langchain = this.options.instrumentations?.langchain;
|
|
1916
|
-
if (langchain) {
|
|
1917
|
-
const provider = this.tracerProvider(exports.Instrumentation.Langchain);
|
|
1918
|
-
const instrumentation$1 = new instrumentationLangchain.LangChainInstrumentation();
|
|
1919
|
-
instrumentation$1.setTracerProvider(provider);
|
|
1920
|
-
instrumentation$1.manuallyInstrument(langchain);
|
|
1921
|
-
instrumentation.registerInstrumentations({
|
|
1922
|
-
instrumentations: [instrumentation$1],
|
|
1923
|
-
tracerProvider: provider,
|
|
1924
|
-
});
|
|
1925
|
-
this.instrumentations.push(instrumentation$1);
|
|
1926
|
-
}
|
|
1927
|
-
const llamaindex = this.options.instrumentations?.llamaindex;
|
|
1928
|
-
if (llamaindex) {
|
|
1929
|
-
const provider = this.tracerProvider(exports.Instrumentation.LlamaIndex);
|
|
1930
|
-
const instrumentation$1 = new instrumentationLlamaindex.LlamaIndexInstrumentation();
|
|
1931
|
-
instrumentation$1.setTracerProvider(provider);
|
|
1932
|
-
instrumentation$1.manuallyInstrument(llamaindex);
|
|
1818
|
+
if (providerPkg) {
|
|
1819
|
+
instrumentation$1.manuallyInstrument(providerPkg);
|
|
1820
|
+
}
|
|
1933
1821
|
instrumentation.registerInstrumentations({
|
|
1934
1822
|
instrumentations: [instrumentation$1],
|
|
1935
1823
|
tracerProvider: provider,
|
|
1936
1824
|
});
|
|
1937
1825
|
this.instrumentations.push(instrumentation$1);
|
|
1938
|
-
}
|
|
1826
|
+
};
|
|
1827
|
+
configureInstrumentation(exports.Instrumentation.Anthropic, instrumentationAnthropic.AnthropicInstrumentation); // prettier-ignore
|
|
1828
|
+
configureInstrumentation(exports.Instrumentation.AIPlatform, instrumentationVertexai.AIPlatformInstrumentation); // prettier-ignore
|
|
1829
|
+
configureInstrumentation(exports.Instrumentation.Bedrock, instrumentationBedrock.BedrockInstrumentation); // prettier-ignore
|
|
1830
|
+
configureInstrumentation(exports.Instrumentation.Cohere, instrumentationCohere.CohereInstrumentation); // prettier-ignore
|
|
1831
|
+
configureInstrumentation(exports.Instrumentation.Langchain, instrumentationLangchain.LangChainInstrumentation); // prettier-ignore
|
|
1832
|
+
configureInstrumentation(exports.Instrumentation.LlamaIndex, instrumentationLlamaindex.LlamaIndexInstrumentation); // prettier-ignore
|
|
1833
|
+
configureInstrumentation(exports.Instrumentation.OpenAI, instrumentationOpenai.OpenAIInstrumentation, { enrichTokens: true }); // prettier-ignore
|
|
1834
|
+
configureInstrumentation(exports.Instrumentation.TogetherAI, instrumentationTogether.TogetherInstrumentation, { enrichTokens: true }); // prettier-ignore
|
|
1835
|
+
configureInstrumentation(exports.Instrumentation.VertexAI, instrumentationVertexai.VertexAIInstrumentation); // prettier-ignore
|
|
1939
1836
|
}
|
|
1940
1837
|
instrument() {
|
|
1941
1838
|
this.instrumentations.forEach((instrumentation) => {
|
|
@@ -1949,21 +1846,9 @@ class LatitudeTelemetry {
|
|
|
1949
1846
|
instrumentation.disable();
|
|
1950
1847
|
});
|
|
1951
1848
|
}
|
|
1952
|
-
baggage(ctx) {
|
|
1953
|
-
return this.telemetry.baggage(ctx);
|
|
1954
|
-
}
|
|
1955
|
-
pause(ctx) {
|
|
1956
|
-
return this.telemetry.pause(ctx);
|
|
1957
|
-
}
|
|
1958
1849
|
resume(ctx) {
|
|
1959
1850
|
return this.telemetry.resume(ctx);
|
|
1960
1851
|
}
|
|
1961
|
-
restored(ctx) {
|
|
1962
|
-
return this.telemetry.restored(ctx);
|
|
1963
|
-
}
|
|
1964
|
-
restore(ctx) {
|
|
1965
|
-
return this.telemetry.restore(ctx);
|
|
1966
|
-
}
|
|
1967
1852
|
tool(ctx, options) {
|
|
1968
1853
|
return this.telemetry.tool(ctx, options);
|
|
1969
1854
|
}
|