@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.d.ts CHANGED
@@ -37,14 +37,16 @@ declare const DEFAULT_REDACT_SPAN_PROCESSOR: () => RedactSpanProcessor;
37
37
 
38
38
  declare enum SegmentSource {
39
39
  API = "api",
40
- Playground = "playground",
40
+ AgentAsTool = "agent_as_tool",// TODO(tracing): deprecated, use SegmentType.Document with DocumentType.Agent instead
41
+ Copilot = "copilot",
42
+ EmailTrigger = "email_trigger",
41
43
  Evaluation = "evaluation",// Note: from prompts of llm evaluations
42
44
  Experiment = "experiment",
43
- User = "user",
45
+ Playground = "playground",
46
+ ScheduledTrigger = "scheduled_trigger",
47
+ IntegrationTrigger = "integration_trigger",
44
48
  SharedPrompt = "shared_prompt",
45
- AgentAsTool = "agent_as_tool",// TODO(tracing): deprecated, use SegmentType.Document with DocumentType.Agent instead
46
- EmailTrigger = "email_trigger",
47
- ScheduledTrigger = "scheduled_trigger"
49
+ User = "user"
48
50
  }
49
51
  declare enum SegmentType {
50
52
  Document = "document",
package/dist/index.js CHANGED
@@ -121,20 +121,32 @@ const env = { GATEWAY_BASE_URL: GET_GATEWAY_BASE_URL() };
121
121
  var SegmentSource;
122
122
  (function (SegmentSource) {
123
123
  SegmentSource["API"] = "api";
124
- SegmentSource["Playground"] = "playground";
125
- SegmentSource["Evaluation"] = "evaluation";
126
- SegmentSource["Experiment"] = "experiment";
127
- SegmentSource["User"] = "user";
128
- SegmentSource["SharedPrompt"] = "shared_prompt";
129
124
  SegmentSource["AgentAsTool"] = "agent_as_tool";
125
+ SegmentSource["Copilot"] = "copilot";
130
126
  SegmentSource["EmailTrigger"] = "email_trigger";
127
+ SegmentSource["Evaluation"] = "evaluation";
128
+ SegmentSource["Experiment"] = "experiment";
129
+ SegmentSource["Playground"] = "playground";
131
130
  SegmentSource["ScheduledTrigger"] = "scheduled_trigger";
131
+ SegmentSource["IntegrationTrigger"] = "integration_trigger";
132
+ SegmentSource["SharedPrompt"] = "shared_prompt";
133
+ SegmentSource["User"] = "user";
132
134
  })(SegmentSource || (SegmentSource = {}));
133
135
  var SegmentType;
134
136
  (function (SegmentType) {
135
137
  SegmentType["Document"] = "document";
136
138
  SegmentType["Step"] = "step";
137
139
  })(SegmentType || (SegmentType = {}));
140
+ const SEGMENT_SPECIFICATIONS = {
141
+ [SegmentType.Document]: {
142
+ name: 'Prompt',
143
+ description: 'A prompt',
144
+ },
145
+ [SegmentType.Step]: {
146
+ name: 'Step',
147
+ description: 'A step in a prompt',
148
+ },
149
+ };
138
150
  const baseSegmentBaggageSchema = z.object({
139
151
  id: z.string(),
140
152
  parentId: z.string().optional(),
@@ -177,14 +189,56 @@ var SpanType;
177
189
  SpanType["Segment"] = "segment";
178
190
  SpanType["Unknown"] = "unknown";
179
191
  })(SpanType || (SpanType = {}));
180
- const GENAI_SPANS = [
181
- SpanType.Tool,
182
- SpanType.Completion,
183
- SpanType.Embedding,
184
- SpanType.Retrieval,
185
- SpanType.Reranking,
186
- ];
187
- [SpanType.Http, SpanType.Segment, SpanType.Unknown];
192
+ const SPAN_SPECIFICATIONS = {
193
+ [SpanType.Tool]: {
194
+ name: 'Tool',
195
+ description: 'A tool call',
196
+ isGenAI: true,
197
+ isHidden: false,
198
+ },
199
+ [SpanType.Completion]: {
200
+ name: 'Completion',
201
+ description: 'A completion call',
202
+ isGenAI: true,
203
+ isHidden: false,
204
+ },
205
+ [SpanType.Embedding]: {
206
+ name: 'Embedding',
207
+ description: 'An embedding call',
208
+ isGenAI: true,
209
+ isHidden: false,
210
+ },
211
+ [SpanType.Retrieval]: {
212
+ name: 'Retrieval',
213
+ description: 'A retrieval call',
214
+ isGenAI: true,
215
+ isHidden: false,
216
+ },
217
+ [SpanType.Reranking]: {
218
+ name: 'Reranking',
219
+ description: 'A reranking call',
220
+ isGenAI: true,
221
+ isHidden: false,
222
+ },
223
+ [SpanType.Http]: {
224
+ name: 'HTTP',
225
+ description: 'An HTTP request',
226
+ isGenAI: false,
227
+ isHidden: true,
228
+ },
229
+ [SpanType.Segment]: {
230
+ name: 'Segment',
231
+ description: 'A (partial) segment of a trace',
232
+ isGenAI: false,
233
+ isHidden: false,
234
+ },
235
+ [SpanType.Unknown]: {
236
+ name: 'Unknown',
237
+ description: 'An unknown span',
238
+ isGenAI: false,
239
+ isHidden: true,
240
+ },
241
+ };
188
242
  var SpanStatus;
189
243
  (function (SpanStatus) {
190
244
  SpanStatus["Unset"] = "unset";
@@ -264,9 +318,9 @@ const GEN_AI_RESPONSE_FINISH_REASON_VALUE_STOP = 'stop';
264
318
  const GEN_AI_RESPONSE_FINISH_REASON_VALUE_TOOL_CALLS = 'tool_calls';
265
319
  const ATTR_HTTP_REQUEST_URL = 'http.request.url';
266
320
  const ATTR_HTTP_REQUEST_BODY = 'http.request.body';
267
- const ATTR_HTTP_REQUEST_HEADERS = 'http.request.header';
321
+ const ATTR_HTTP_REQUEST_HEADER = 'http.request.header';
268
322
  const ATTR_HTTP_RESPONSE_BODY = 'http.response.body';
269
- const ATTR_HTTP_RESPONSE_HEADERS = 'http.response.header';
323
+ const ATTR_HTTP_RESPONSE_HEADER = 'http.response.header';
270
324
  /* Note: Schemas for span ingestion following OpenTelemetry service request specification */
271
325
  var Otlp;
272
326
  (function (Otlp) {
@@ -298,10 +352,22 @@ var Otlp;
298
352
  spanId: z.string(),
299
353
  attributes: z.array(Otlp.attributeSchema).optional(),
300
354
  });
355
+ (function (StatusCode) {
356
+ StatusCode[StatusCode["Unset"] = 0] = "Unset";
357
+ StatusCode[StatusCode["Ok"] = 1] = "Ok";
358
+ StatusCode[StatusCode["Error"] = 2] = "Error";
359
+ })(Otlp.StatusCode || (Otlp.StatusCode = {}));
301
360
  Otlp.statusSchema = z.object({
302
361
  code: z.number(),
303
362
  message: z.string().optional(),
304
363
  });
364
+ (function (SpanKind) {
365
+ SpanKind[SpanKind["Internal"] = 0] = "Internal";
366
+ SpanKind[SpanKind["Server"] = 1] = "Server";
367
+ SpanKind[SpanKind["Client"] = 2] = "Client";
368
+ SpanKind[SpanKind["Producer"] = 3] = "Producer";
369
+ SpanKind[SpanKind["Consumer"] = 4] = "Consumer";
370
+ })(Otlp.SpanKind || (Otlp.SpanKind = {}));
305
371
  Otlp.spanSchema = z.object({
306
372
  traceId: z.string(),
307
373
  spanId: z.string(),
@@ -684,17 +750,18 @@ var LegacyChainEventTypes;
684
750
 
685
751
  var ChainEventTypes;
686
752
  (function (ChainEventTypes) {
753
+ ChainEventTypes["ChainCompleted"] = "chain-completed";
754
+ ChainEventTypes["ChainError"] = "chain-error";
687
755
  ChainEventTypes["ChainStarted"] = "chain-started";
688
- ChainEventTypes["StepStarted"] = "step-started";
689
- ChainEventTypes["ProviderStarted"] = "provider-started";
756
+ ChainEventTypes["IntegrationWakingUp"] = "integration-waking-up";
690
757
  ChainEventTypes["ProviderCompleted"] = "provider-completed";
691
- ChainEventTypes["ToolsStarted"] = "tools-started";
692
- ChainEventTypes["ToolCompleted"] = "tool-completed";
758
+ ChainEventTypes["ProviderStarted"] = "provider-started";
693
759
  ChainEventTypes["StepCompleted"] = "step-completed";
694
- ChainEventTypes["ChainCompleted"] = "chain-completed";
695
- ChainEventTypes["ChainError"] = "chain-error";
760
+ ChainEventTypes["StepStarted"] = "step-started";
761
+ ChainEventTypes["ToolCompleted"] = "tool-completed";
696
762
  ChainEventTypes["ToolsRequested"] = "tools-requested";
697
- ChainEventTypes["IntegrationWakingUp"] = "integration-waking-up";
763
+ ChainEventTypes["ToolResult"] = "tool-result";
764
+ ChainEventTypes["ToolsStarted"] = "tools-started";
698
765
  })(ChainEventTypes || (ChainEventTypes = {}));
699
766
 
700
767
  var IntegrationType;
@@ -702,6 +769,7 @@ var IntegrationType;
702
769
  IntegrationType["Latitude"] = "latitude";
703
770
  IntegrationType["ExternalMCP"] = "custom_mcp";
704
771
  IntegrationType["HostedMCP"] = "mcp_server";
772
+ IntegrationType["Pipedream"] = "pipedream";
705
773
  })(IntegrationType || (IntegrationType = {}));
706
774
  var HostedIntegrationType;
707
775
  (function (HostedIntegrationType) {
@@ -806,6 +874,14 @@ var EvaluationResultableType;
806
874
  EvaluationResultableType["Number"] = "evaluation_resultable_numbers";
807
875
  })(EvaluationResultableType || (EvaluationResultableType = {}));
808
876
 
877
+ var MessageRole;
878
+ (function (MessageRole) {
879
+ MessageRole["system"] = "system";
880
+ MessageRole["user"] = "user";
881
+ MessageRole["assistant"] = "assistant";
882
+ MessageRole["tool"] = "tool";
883
+ })(MessageRole || (MessageRole = {}));
884
+
809
885
  var ModifiedDocumentType;
810
886
  (function (ModifiedDocumentType) {
811
887
  ModifiedDocumentType["Created"] = "created";
@@ -841,6 +917,7 @@ var DocumentTriggerType;
841
917
  (function (DocumentTriggerType) {
842
918
  DocumentTriggerType["Email"] = "email";
843
919
  DocumentTriggerType["Scheduled"] = "scheduled";
920
+ DocumentTriggerType["Integration"] = "integration";
844
921
  })(DocumentTriggerType || (DocumentTriggerType = {}));
845
922
  var DocumentTriggerParameters;
846
923
  (function (DocumentTriggerParameters) {
@@ -1009,7 +1086,7 @@ class ManualInstrumentation {
1009
1086
  }
1010
1087
  const start = options || {};
1011
1088
  let operation = undefined;
1012
- if (GENAI_SPANS.includes(type)) {
1089
+ if (SPAN_SPECIFICATIONS[type].isGenAI) {
1013
1090
  operation = type;
1014
1091
  }
1015
1092
  const span = this.tracer.startSpan(name, {
@@ -1327,18 +1404,18 @@ class ManualInstrumentation {
1327
1404
  };
1328
1405
  }
1329
1406
  embedding(ctx, options) {
1330
- return this.span(ctx, options?.name || 'Embedding', SpanType.Embedding, options);
1407
+ return this.span(ctx, options?.name || SPAN_SPECIFICATIONS[SpanType.Embedding].name, SpanType.Embedding, options);
1331
1408
  }
1332
1409
  retrieval(ctx, options) {
1333
- return this.span(ctx, options?.name || 'Retrieval', SpanType.Retrieval, options);
1410
+ return this.span(ctx, options?.name || SPAN_SPECIFICATIONS[SpanType.Retrieval].name, SpanType.Retrieval, options);
1334
1411
  }
1335
1412
  reranking(ctx, options) {
1336
- return this.span(ctx, options?.name || 'Reranking', SpanType.Reranking, options);
1413
+ return this.span(ctx, options?.name || SPAN_SPECIFICATIONS[SpanType.Reranking].name, SpanType.Reranking, options);
1337
1414
  }
1338
1415
  attribifyHeaders(direction, headers) {
1339
1416
  const prefix = direction === 'request'
1340
- ? ATTR_HTTP_REQUEST_HEADERS
1341
- : ATTR_HTTP_RESPONSE_HEADERS;
1417
+ ? ATTR_HTTP_REQUEST_HEADER
1418
+ : ATTR_HTTP_RESPONSE_HEADER;
1342
1419
  const attributes = {};
1343
1420
  for (const key in headers) {
1344
1421
  const field = this.toKebabCase(key);
@@ -1352,6 +1429,7 @@ class ManualInstrumentation {
1352
1429
  http(ctx, options) {
1353
1430
  const start = options;
1354
1431
  const method = start.request.method.toUpperCase();
1432
+ // Note: do not serialize headers as a single attribute because fields won't be redacted
1355
1433
  const attrHeaders = this.attribifyHeaders('request', start.request.headers);
1356
1434
  let finalBody = '';
1357
1435
  if (typeof start.request.body === 'string') {
@@ -1378,6 +1456,7 @@ class ManualInstrumentation {
1378
1456
  context: span.context,
1379
1457
  end: (options) => {
1380
1458
  const end = options;
1459
+ // Note: do not serialize headers as a single attribute because fields won't be redacted
1381
1460
  const attrHeaders = this.attribifyHeaders('response', end.response.headers);
1382
1461
  let finalBody = '';
1383
1462
  if (typeof end.response.body === 'string') {
@@ -1426,9 +1505,7 @@ class ManualInstrumentation {
1426
1505
  };
1427
1506
  ctx = this.setBaggage(ctx, baggage, options.baggage);
1428
1507
  // Dummy wrapper to force the same trace and carry on some segment attributes
1429
- const span = this.span(ctx, type, SpanType.Segment, {
1430
- attributes: options.attributes,
1431
- });
1508
+ const span = this.span(ctx, SEGMENT_SPECIFICATIONS[type].name, SpanType.Segment, { attributes: options.attributes });
1432
1509
  let carrier = {};
1433
1510
  propagation.inject(span.context, carrier);
1434
1511
  baggage.segments.at(-1).traceparent = carrier.traceparent;
@@ -1512,11 +1589,11 @@ class LatitudeInstrumentation {
1512
1589
  }
1513
1590
  async wrapToolHandler(fn, ...args) {
1514
1591
  const toolArguments = args[0];
1515
- const { toolId, toolName } = args[1];
1592
+ const { id, name } = args[1];
1516
1593
  const $tool = this.telemetry.tool(context.active(), {
1517
- name: toolName,
1594
+ name,
1518
1595
  call: {
1519
- id: toolId,
1596
+ id,
1520
1597
  arguments: toolArguments,
1521
1598
  },
1522
1599
  });
@@ -1564,25 +1641,6 @@ class LatitudeInstrumentation {
1564
1641
  $prompt.end();
1565
1642
  return result;
1566
1643
  }
1567
- async wrapRenderAgent(fn, ...args) {
1568
- const { prompt, parameters } = args[0];
1569
- const $prompt = this.telemetry.prompt(context.active(), {
1570
- versionUuid: prompt.versionUuid,
1571
- promptUuid: prompt.uuid,
1572
- template: prompt.content,
1573
- parameters: parameters,
1574
- });
1575
- let result;
1576
- try {
1577
- result = await context.with($prompt.context, async () => await fn(...args));
1578
- }
1579
- catch (error) {
1580
- $prompt.fail(error);
1581
- throw error;
1582
- }
1583
- $prompt.end();
1584
- return result;
1585
- }
1586
1644
  async wrapRenderStep(fn, ...args) {
1587
1645
  const $step = this.telemetry.step(context.active());
1588
1646
  let result;
@@ -1661,7 +1719,7 @@ class LatitudeInstrumentation {
1661
1719
  }
1662
1720
  }
1663
1721
 
1664
- const TRACES_URL = `${env.GATEWAY_BASE_URL}/api/v3/otlp/v1/traces`;
1722
+ const TRACES_URL = `${env.GATEWAY_BASE_URL}/api/v3/traces`;
1665
1723
  const SERVICE_NAME = process.env.npm_package_name || 'unknown';
1666
1724
  const SCOPE_VERSION = process.env.npm_package_version || 'unknown';
1667
1725
  const BACKGROUND = () => otel.ROOT_CONTEXT;