@latitude-data/telemetry 1.0.0 → 1.0.2

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
@@ -141,20 +141,32 @@ const env = { GATEWAY_BASE_URL: GET_GATEWAY_BASE_URL() };
141
141
  var SegmentSource;
142
142
  (function (SegmentSource) {
143
143
  SegmentSource["API"] = "api";
144
- SegmentSource["Playground"] = "playground";
145
- SegmentSource["Evaluation"] = "evaluation";
146
- SegmentSource["Experiment"] = "experiment";
147
- SegmentSource["User"] = "user";
148
- SegmentSource["SharedPrompt"] = "shared_prompt";
149
144
  SegmentSource["AgentAsTool"] = "agent_as_tool";
145
+ SegmentSource["Copilot"] = "copilot";
150
146
  SegmentSource["EmailTrigger"] = "email_trigger";
147
+ SegmentSource["Evaluation"] = "evaluation";
148
+ SegmentSource["Experiment"] = "experiment";
149
+ SegmentSource["Playground"] = "playground";
151
150
  SegmentSource["ScheduledTrigger"] = "scheduled_trigger";
151
+ SegmentSource["IntegrationTrigger"] = "integration_trigger";
152
+ SegmentSource["SharedPrompt"] = "shared_prompt";
153
+ SegmentSource["User"] = "user";
152
154
  })(SegmentSource || (SegmentSource = {}));
153
155
  var SegmentType;
154
156
  (function (SegmentType) {
155
157
  SegmentType["Document"] = "document";
156
158
  SegmentType["Step"] = "step";
157
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
+ };
158
170
  const baseSegmentBaggageSchema = zod.z.object({
159
171
  id: zod.z.string(),
160
172
  parentId: zod.z.string().optional(),
@@ -197,14 +209,56 @@ var SpanType;
197
209
  SpanType["Segment"] = "segment";
198
210
  SpanType["Unknown"] = "unknown";
199
211
  })(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];
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
+ };
208
262
  var SpanStatus;
209
263
  (function (SpanStatus) {
210
264
  SpanStatus["Unset"] = "unset";
@@ -284,9 +338,9 @@ const GEN_AI_RESPONSE_FINISH_REASON_VALUE_STOP = 'stop';
284
338
  const GEN_AI_RESPONSE_FINISH_REASON_VALUE_TOOL_CALLS = 'tool_calls';
285
339
  const ATTR_HTTP_REQUEST_URL = 'http.request.url';
286
340
  const ATTR_HTTP_REQUEST_BODY = 'http.request.body';
287
- const ATTR_HTTP_REQUEST_HEADERS = 'http.request.header';
341
+ const ATTR_HTTP_REQUEST_HEADER = 'http.request.header';
288
342
  const ATTR_HTTP_RESPONSE_BODY = 'http.response.body';
289
- const ATTR_HTTP_RESPONSE_HEADERS = 'http.response.header';
343
+ const ATTR_HTTP_RESPONSE_HEADER = 'http.response.header';
290
344
  /* Note: Schemas for span ingestion following OpenTelemetry service request specification */
291
345
  var Otlp;
292
346
  (function (Otlp) {
@@ -318,10 +372,22 @@ var Otlp;
318
372
  spanId: zod.z.string(),
319
373
  attributes: zod.z.array(Otlp.attributeSchema).optional(),
320
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 = {}));
321
380
  Otlp.statusSchema = zod.z.object({
322
381
  code: zod.z.number(),
323
382
  message: zod.z.string().optional(),
324
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 = {}));
325
391
  Otlp.spanSchema = zod.z.object({
326
392
  traceId: zod.z.string(),
327
393
  spanId: zod.z.string(),
@@ -704,17 +770,18 @@ var LegacyChainEventTypes;
704
770
 
705
771
  var ChainEventTypes;
706
772
  (function (ChainEventTypes) {
773
+ ChainEventTypes["ChainCompleted"] = "chain-completed";
774
+ ChainEventTypes["ChainError"] = "chain-error";
707
775
  ChainEventTypes["ChainStarted"] = "chain-started";
708
- ChainEventTypes["StepStarted"] = "step-started";
709
- ChainEventTypes["ProviderStarted"] = "provider-started";
776
+ ChainEventTypes["IntegrationWakingUp"] = "integration-waking-up";
710
777
  ChainEventTypes["ProviderCompleted"] = "provider-completed";
711
- ChainEventTypes["ToolsStarted"] = "tools-started";
712
- ChainEventTypes["ToolCompleted"] = "tool-completed";
778
+ ChainEventTypes["ProviderStarted"] = "provider-started";
713
779
  ChainEventTypes["StepCompleted"] = "step-completed";
714
- ChainEventTypes["ChainCompleted"] = "chain-completed";
715
- ChainEventTypes["ChainError"] = "chain-error";
780
+ ChainEventTypes["StepStarted"] = "step-started";
781
+ ChainEventTypes["ToolCompleted"] = "tool-completed";
716
782
  ChainEventTypes["ToolsRequested"] = "tools-requested";
717
- ChainEventTypes["IntegrationWakingUp"] = "integration-waking-up";
783
+ ChainEventTypes["ToolResult"] = "tool-result";
784
+ ChainEventTypes["ToolsStarted"] = "tools-started";
718
785
  })(ChainEventTypes || (ChainEventTypes = {}));
719
786
 
720
787
  var IntegrationType;
@@ -722,6 +789,7 @@ var IntegrationType;
722
789
  IntegrationType["Latitude"] = "latitude";
723
790
  IntegrationType["ExternalMCP"] = "custom_mcp";
724
791
  IntegrationType["HostedMCP"] = "mcp_server";
792
+ IntegrationType["Pipedream"] = "pipedream";
725
793
  })(IntegrationType || (IntegrationType = {}));
726
794
  var HostedIntegrationType;
727
795
  (function (HostedIntegrationType) {
@@ -826,6 +894,14 @@ var EvaluationResultableType;
826
894
  EvaluationResultableType["Number"] = "evaluation_resultable_numbers";
827
895
  })(EvaluationResultableType || (EvaluationResultableType = {}));
828
896
 
897
+ var MessageRole;
898
+ (function (MessageRole) {
899
+ MessageRole["system"] = "system";
900
+ MessageRole["user"] = "user";
901
+ MessageRole["assistant"] = "assistant";
902
+ MessageRole["tool"] = "tool";
903
+ })(MessageRole || (MessageRole = {}));
904
+
829
905
  var ModifiedDocumentType;
830
906
  (function (ModifiedDocumentType) {
831
907
  ModifiedDocumentType["Created"] = "created";
@@ -861,6 +937,7 @@ var DocumentTriggerType;
861
937
  (function (DocumentTriggerType) {
862
938
  DocumentTriggerType["Email"] = "email";
863
939
  DocumentTriggerType["Scheduled"] = "scheduled";
940
+ DocumentTriggerType["Integration"] = "integration";
864
941
  })(DocumentTriggerType || (DocumentTriggerType = {}));
865
942
  var DocumentTriggerParameters;
866
943
  (function (DocumentTriggerParameters) {
@@ -1029,7 +1106,7 @@ class ManualInstrumentation {
1029
1106
  }
1030
1107
  const start = options || {};
1031
1108
  let operation = undefined;
1032
- if (GENAI_SPANS.includes(type)) {
1109
+ if (SPAN_SPECIFICATIONS[type].isGenAI) {
1033
1110
  operation = type;
1034
1111
  }
1035
1112
  const span = this.tracer.startSpan(name, {
@@ -1347,18 +1424,18 @@ class ManualInstrumentation {
1347
1424
  };
1348
1425
  }
1349
1426
  embedding(ctx, options) {
1350
- return this.span(ctx, options?.name || 'Embedding', SpanType.Embedding, options);
1427
+ return this.span(ctx, options?.name || SPAN_SPECIFICATIONS[SpanType.Embedding].name, SpanType.Embedding, options);
1351
1428
  }
1352
1429
  retrieval(ctx, options) {
1353
- return this.span(ctx, options?.name || 'Retrieval', SpanType.Retrieval, options);
1430
+ return this.span(ctx, options?.name || SPAN_SPECIFICATIONS[SpanType.Retrieval].name, SpanType.Retrieval, options);
1354
1431
  }
1355
1432
  reranking(ctx, options) {
1356
- return this.span(ctx, options?.name || 'Reranking', SpanType.Reranking, options);
1433
+ return this.span(ctx, options?.name || SPAN_SPECIFICATIONS[SpanType.Reranking].name, SpanType.Reranking, options);
1357
1434
  }
1358
1435
  attribifyHeaders(direction, headers) {
1359
1436
  const prefix = direction === 'request'
1360
- ? ATTR_HTTP_REQUEST_HEADERS
1361
- : ATTR_HTTP_RESPONSE_HEADERS;
1437
+ ? ATTR_HTTP_REQUEST_HEADER
1438
+ : ATTR_HTTP_RESPONSE_HEADER;
1362
1439
  const attributes = {};
1363
1440
  for (const key in headers) {
1364
1441
  const field = this.toKebabCase(key);
@@ -1372,6 +1449,7 @@ class ManualInstrumentation {
1372
1449
  http(ctx, options) {
1373
1450
  const start = options;
1374
1451
  const method = start.request.method.toUpperCase();
1452
+ // Note: do not serialize headers as a single attribute because fields won't be redacted
1375
1453
  const attrHeaders = this.attribifyHeaders('request', start.request.headers);
1376
1454
  let finalBody = '';
1377
1455
  if (typeof start.request.body === 'string') {
@@ -1398,6 +1476,7 @@ class ManualInstrumentation {
1398
1476
  context: span.context,
1399
1477
  end: (options) => {
1400
1478
  const end = options;
1479
+ // Note: do not serialize headers as a single attribute because fields won't be redacted
1401
1480
  const attrHeaders = this.attribifyHeaders('response', end.response.headers);
1402
1481
  let finalBody = '';
1403
1482
  if (typeof end.response.body === 'string') {
@@ -1446,9 +1525,7 @@ class ManualInstrumentation {
1446
1525
  };
1447
1526
  ctx = this.setBaggage(ctx, baggage, options.baggage);
1448
1527
  // 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
- });
1528
+ const span = this.span(ctx, SEGMENT_SPECIFICATIONS[type].name, SpanType.Segment, { attributes: options.attributes });
1452
1529
  let carrier = {};
1453
1530
  otel.propagation.inject(span.context, carrier);
1454
1531
  baggage.segments.at(-1).traceparent = carrier.traceparent;
@@ -1532,11 +1609,11 @@ class LatitudeInstrumentation {
1532
1609
  }
1533
1610
  async wrapToolHandler(fn, ...args) {
1534
1611
  const toolArguments = args[0];
1535
- const { toolId, toolName } = args[1];
1612
+ const { id, name } = args[1];
1536
1613
  const $tool = this.telemetry.tool(otel.context.active(), {
1537
- name: toolName,
1614
+ name,
1538
1615
  call: {
1539
- id: toolId,
1616
+ id,
1540
1617
  arguments: toolArguments,
1541
1618
  },
1542
1619
  });
@@ -1584,25 +1661,6 @@ class LatitudeInstrumentation {
1584
1661
  $prompt.end();
1585
1662
  return result;
1586
1663
  }
1587
- async wrapRenderAgent(fn, ...args) {
1588
- const { prompt, parameters } = args[0];
1589
- const $prompt = this.telemetry.prompt(otel.context.active(), {
1590
- versionUuid: prompt.versionUuid,
1591
- promptUuid: prompt.uuid,
1592
- template: prompt.content,
1593
- parameters: parameters,
1594
- });
1595
- let result;
1596
- try {
1597
- result = await otel.context.with($prompt.context, async () => await fn(...args));
1598
- }
1599
- catch (error) {
1600
- $prompt.fail(error);
1601
- throw error;
1602
- }
1603
- $prompt.end();
1604
- return result;
1605
- }
1606
1664
  async wrapRenderStep(fn, ...args) {
1607
1665
  const $step = this.telemetry.step(otel.context.active());
1608
1666
  let result;
@@ -1681,7 +1739,7 @@ class LatitudeInstrumentation {
1681
1739
  }
1682
1740
  }
1683
1741
 
1684
- const TRACES_URL = `${env.GATEWAY_BASE_URL}/api/v3/otlp/v1/traces`;
1742
+ const TRACES_URL = `${env.GATEWAY_BASE_URL}/api/v3/traces`;
1685
1743
  const SERVICE_NAME = process.env.npm_package_name || 'unknown';
1686
1744
  const SCOPE_VERSION = process.env.npm_package_version || 'unknown';
1687
1745
  const BACKGROUND = () => otel__namespace.ROOT_CONTEXT;