@latitude-data/telemetry 1.0.0 → 1.0.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.cjs CHANGED
@@ -155,6 +155,16 @@ var SegmentType;
155
155
  SegmentType["Document"] = "document";
156
156
  SegmentType["Step"] = "step";
157
157
  })(SegmentType || (SegmentType = {}));
158
+ const SEGMENT_SPECIFICATIONS = {
159
+ [SegmentType.Document]: {
160
+ name: 'Prompt',
161
+ description: 'A prompt',
162
+ },
163
+ [SegmentType.Step]: {
164
+ name: 'Step',
165
+ description: 'A step in a prompt',
166
+ },
167
+ };
158
168
  const baseSegmentBaggageSchema = zod.z.object({
159
169
  id: zod.z.string(),
160
170
  parentId: zod.z.string().optional(),
@@ -197,14 +207,56 @@ var SpanType;
197
207
  SpanType["Segment"] = "segment";
198
208
  SpanType["Unknown"] = "unknown";
199
209
  })(SpanType || (SpanType = {}));
200
- const GENAI_SPANS = [
201
- SpanType.Tool,
202
- SpanType.Completion,
203
- SpanType.Embedding,
204
- SpanType.Retrieval,
205
- SpanType.Reranking,
206
- ];
207
- [SpanType.Http, SpanType.Segment, SpanType.Unknown];
210
+ const SPAN_SPECIFICATIONS = {
211
+ [SpanType.Tool]: {
212
+ name: 'Tool',
213
+ description: 'A tool call',
214
+ isGenAI: true,
215
+ isHidden: false,
216
+ },
217
+ [SpanType.Completion]: {
218
+ name: 'Completion',
219
+ description: 'A completion call',
220
+ isGenAI: true,
221
+ isHidden: false,
222
+ },
223
+ [SpanType.Embedding]: {
224
+ name: 'Embedding',
225
+ description: 'An embedding call',
226
+ isGenAI: true,
227
+ isHidden: false,
228
+ },
229
+ [SpanType.Retrieval]: {
230
+ name: 'Retrieval',
231
+ description: 'A retrieval call',
232
+ isGenAI: true,
233
+ isHidden: false,
234
+ },
235
+ [SpanType.Reranking]: {
236
+ name: 'Reranking',
237
+ description: 'A reranking call',
238
+ isGenAI: true,
239
+ isHidden: false,
240
+ },
241
+ [SpanType.Http]: {
242
+ name: 'HTTP',
243
+ description: 'An HTTP request',
244
+ isGenAI: false,
245
+ isHidden: true,
246
+ },
247
+ [SpanType.Segment]: {
248
+ name: 'Segment',
249
+ description: 'A (partial) segment of a trace',
250
+ isGenAI: false,
251
+ isHidden: true,
252
+ },
253
+ [SpanType.Unknown]: {
254
+ name: 'Unknown',
255
+ description: 'An unknown span',
256
+ isGenAI: false,
257
+ isHidden: true,
258
+ },
259
+ };
208
260
  var SpanStatus;
209
261
  (function (SpanStatus) {
210
262
  SpanStatus["Unset"] = "unset";
@@ -284,9 +336,9 @@ const GEN_AI_RESPONSE_FINISH_REASON_VALUE_STOP = 'stop';
284
336
  const GEN_AI_RESPONSE_FINISH_REASON_VALUE_TOOL_CALLS = 'tool_calls';
285
337
  const ATTR_HTTP_REQUEST_URL = 'http.request.url';
286
338
  const ATTR_HTTP_REQUEST_BODY = 'http.request.body';
287
- const ATTR_HTTP_REQUEST_HEADERS = 'http.request.header';
339
+ const ATTR_HTTP_REQUEST_HEADER = 'http.request.header';
288
340
  const ATTR_HTTP_RESPONSE_BODY = 'http.response.body';
289
- const ATTR_HTTP_RESPONSE_HEADERS = 'http.response.header';
341
+ const ATTR_HTTP_RESPONSE_HEADER = 'http.response.header';
290
342
  /* Note: Schemas for span ingestion following OpenTelemetry service request specification */
291
343
  var Otlp;
292
344
  (function (Otlp) {
@@ -318,10 +370,22 @@ var Otlp;
318
370
  spanId: zod.z.string(),
319
371
  attributes: zod.z.array(Otlp.attributeSchema).optional(),
320
372
  });
373
+ (function (StatusCode) {
374
+ StatusCode[StatusCode["Unset"] = 0] = "Unset";
375
+ StatusCode[StatusCode["Ok"] = 1] = "Ok";
376
+ StatusCode[StatusCode["Error"] = 2] = "Error";
377
+ })(Otlp.StatusCode || (Otlp.StatusCode = {}));
321
378
  Otlp.statusSchema = zod.z.object({
322
379
  code: zod.z.number(),
323
380
  message: zod.z.string().optional(),
324
381
  });
382
+ (function (SpanKind) {
383
+ SpanKind[SpanKind["Internal"] = 0] = "Internal";
384
+ SpanKind[SpanKind["Server"] = 1] = "Server";
385
+ SpanKind[SpanKind["Client"] = 2] = "Client";
386
+ SpanKind[SpanKind["Producer"] = 3] = "Producer";
387
+ SpanKind[SpanKind["Consumer"] = 4] = "Consumer";
388
+ })(Otlp.SpanKind || (Otlp.SpanKind = {}));
325
389
  Otlp.spanSchema = zod.z.object({
326
390
  traceId: zod.z.string(),
327
391
  spanId: zod.z.string(),
@@ -367,6 +431,16 @@ zod.z.object({
367
431
  isError: zod.z.boolean().optional(),
368
432
  text: zod.z.string().optional(),
369
433
  });
434
+ var FinishReason;
435
+ (function (FinishReason) {
436
+ FinishReason["Stop"] = "stop";
437
+ FinishReason["Length"] = "length";
438
+ FinishReason["ContentFilter"] = "content-filter";
439
+ FinishReason["ToolCalls"] = "tool-calls";
440
+ FinishReason["Error"] = "error";
441
+ FinishReason["Other"] = "other";
442
+ FinishReason["Unknown"] = "unknown";
443
+ })(FinishReason || (FinishReason = {}));
370
444
 
371
445
  var ParameterType;
372
446
  (function (ParameterType) {
@@ -722,6 +796,7 @@ var IntegrationType;
722
796
  IntegrationType["Latitude"] = "latitude";
723
797
  IntegrationType["ExternalMCP"] = "custom_mcp";
724
798
  IntegrationType["HostedMCP"] = "mcp_server";
799
+ IntegrationType["Pipedream"] = "pipedream";
725
800
  })(IntegrationType || (IntegrationType = {}));
726
801
  var HostedIntegrationType;
727
802
  (function (HostedIntegrationType) {
@@ -1029,7 +1104,7 @@ class ManualInstrumentation {
1029
1104
  }
1030
1105
  const start = options || {};
1031
1106
  let operation = undefined;
1032
- if (GENAI_SPANS.includes(type)) {
1107
+ if (SPAN_SPECIFICATIONS[type].isGenAI) {
1033
1108
  operation = type;
1034
1109
  }
1035
1110
  const span = this.tracer.startSpan(name, {
@@ -1347,18 +1422,18 @@ class ManualInstrumentation {
1347
1422
  };
1348
1423
  }
1349
1424
  embedding(ctx, options) {
1350
- return this.span(ctx, options?.name || 'Embedding', SpanType.Embedding, options);
1425
+ return this.span(ctx, options?.name || SPAN_SPECIFICATIONS[SpanType.Embedding].name, SpanType.Embedding, options);
1351
1426
  }
1352
1427
  retrieval(ctx, options) {
1353
- return this.span(ctx, options?.name || 'Retrieval', SpanType.Retrieval, options);
1428
+ return this.span(ctx, options?.name || SPAN_SPECIFICATIONS[SpanType.Retrieval].name, SpanType.Retrieval, options);
1354
1429
  }
1355
1430
  reranking(ctx, options) {
1356
- return this.span(ctx, options?.name || 'Reranking', SpanType.Reranking, options);
1431
+ return this.span(ctx, options?.name || SPAN_SPECIFICATIONS[SpanType.Reranking].name, SpanType.Reranking, options);
1357
1432
  }
1358
1433
  attribifyHeaders(direction, headers) {
1359
1434
  const prefix = direction === 'request'
1360
- ? ATTR_HTTP_REQUEST_HEADERS
1361
- : ATTR_HTTP_RESPONSE_HEADERS;
1435
+ ? ATTR_HTTP_REQUEST_HEADER
1436
+ : ATTR_HTTP_RESPONSE_HEADER;
1362
1437
  const attributes = {};
1363
1438
  for (const key in headers) {
1364
1439
  const field = this.toKebabCase(key);
@@ -1372,6 +1447,7 @@ class ManualInstrumentation {
1372
1447
  http(ctx, options) {
1373
1448
  const start = options;
1374
1449
  const method = start.request.method.toUpperCase();
1450
+ // Note: do not serialize headers as a single attribute because fields won't be redacted
1375
1451
  const attrHeaders = this.attribifyHeaders('request', start.request.headers);
1376
1452
  let finalBody = '';
1377
1453
  if (typeof start.request.body === 'string') {
@@ -1398,6 +1474,7 @@ class ManualInstrumentation {
1398
1474
  context: span.context,
1399
1475
  end: (options) => {
1400
1476
  const end = options;
1477
+ // Note: do not serialize headers as a single attribute because fields won't be redacted
1401
1478
  const attrHeaders = this.attribifyHeaders('response', end.response.headers);
1402
1479
  let finalBody = '';
1403
1480
  if (typeof end.response.body === 'string') {
@@ -1446,9 +1523,7 @@ class ManualInstrumentation {
1446
1523
  };
1447
1524
  ctx = this.setBaggage(ctx, baggage, options.baggage);
1448
1525
  // Dummy wrapper to force the same trace and carry on some segment attributes
1449
- const span = this.span(ctx, type, SpanType.Segment, {
1450
- attributes: options.attributes,
1451
- });
1526
+ const span = this.span(ctx, SEGMENT_SPECIFICATIONS[type].name, SpanType.Segment, { attributes: options.attributes });
1452
1527
  let carrier = {};
1453
1528
  otel.propagation.inject(span.context, carrier);
1454
1529
  baggage.segments.at(-1).traceparent = carrier.traceparent;
@@ -1681,7 +1756,7 @@ class LatitudeInstrumentation {
1681
1756
  }
1682
1757
  }
1683
1758
 
1684
- const TRACES_URL = `${env.GATEWAY_BASE_URL}/api/v3/otlp/v1/traces`;
1759
+ const TRACES_URL = `${env.GATEWAY_BASE_URL}/api/v3/traces`;
1685
1760
  const SERVICE_NAME = process.env.npm_package_name || 'unknown';
1686
1761
  const SCOPE_VERSION = process.env.npm_package_version || 'unknown';
1687
1762
  const BACKGROUND = () => otel__namespace.ROOT_CONTEXT;