@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.d.ts CHANGED
@@ -35,6 +35,27 @@ declare class RedactSpanProcessor implements SpanProcessor {
35
35
  }
36
36
  declare const DEFAULT_REDACT_SPAN_PROCESSOR: () => RedactSpanProcessor;
37
37
 
38
+ declare const traceContextSchema: z.ZodObject<{
39
+ traceparent: z.ZodString;
40
+ tracestate: z.ZodOptional<z.ZodString>;
41
+ baggage: z.ZodOptional<z.ZodString>;
42
+ }, "strip", z.ZodTypeAny, {
43
+ traceparent: string;
44
+ tracestate?: string | undefined;
45
+ baggage?: string | undefined;
46
+ }, {
47
+ traceparent: string;
48
+ tracestate?: string | undefined;
49
+ baggage?: string | undefined;
50
+ }>;
51
+ type TraceContext = z.infer<typeof traceContextSchema>;
52
+ type TraceBaggage = {
53
+ segment: Pick<SegmentBaggage, 'id' | 'parentId'>;
54
+ segments: (SegmentBaggage & Pick<TraceContext, 'traceparent' | 'tracestate'> & {
55
+ paused?: boolean;
56
+ })[];
57
+ };
58
+
38
59
  declare enum SegmentSource {
39
60
  API = "api",
40
61
  Playground = "playground",
@@ -123,27 +144,6 @@ type SegmentBaggage<T extends SegmentType = SegmentType> = Extract<z.infer<typeo
123
144
  type: T;
124
145
  }>;
125
146
 
126
- declare const traceContextSchema: z.ZodObject<{
127
- traceparent: z.ZodString;
128
- tracestate: z.ZodOptional<z.ZodString>;
129
- baggage: z.ZodOptional<z.ZodString>;
130
- }, "strip", z.ZodTypeAny, {
131
- traceparent: string;
132
- tracestate?: string | undefined;
133
- baggage?: string | undefined;
134
- }, {
135
- traceparent: string;
136
- tracestate?: string | undefined;
137
- baggage?: string | undefined;
138
- }>;
139
- type TraceContext = z.infer<typeof traceContextSchema>;
140
- type TraceBaggage = {
141
- segment: Pick<SegmentBaggage, 'id' | 'parentId'>;
142
- segments: (SegmentBaggage & Pick<TraceContext, 'traceparent' | 'tracestate'> & {
143
- paused?: boolean;
144
- })[];
145
- };
146
-
147
147
  type LatitudeInstrumentationOptions = {
148
148
  module: typeof latitude.Latitude;
149
149
  completions?: boolean;
package/dist/index.js CHANGED
@@ -135,6 +135,16 @@ var SegmentType;
135
135
  SegmentType["Document"] = "document";
136
136
  SegmentType["Step"] = "step";
137
137
  })(SegmentType || (SegmentType = {}));
138
+ const SEGMENT_SPECIFICATIONS = {
139
+ [SegmentType.Document]: {
140
+ name: 'Prompt',
141
+ description: 'A prompt',
142
+ },
143
+ [SegmentType.Step]: {
144
+ name: 'Step',
145
+ description: 'A step in a prompt',
146
+ },
147
+ };
138
148
  const baseSegmentBaggageSchema = z.object({
139
149
  id: z.string(),
140
150
  parentId: z.string().optional(),
@@ -177,14 +187,56 @@ var SpanType;
177
187
  SpanType["Segment"] = "segment";
178
188
  SpanType["Unknown"] = "unknown";
179
189
  })(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];
190
+ const SPAN_SPECIFICATIONS = {
191
+ [SpanType.Tool]: {
192
+ name: 'Tool',
193
+ description: 'A tool call',
194
+ isGenAI: true,
195
+ isHidden: false,
196
+ },
197
+ [SpanType.Completion]: {
198
+ name: 'Completion',
199
+ description: 'A completion call',
200
+ isGenAI: true,
201
+ isHidden: false,
202
+ },
203
+ [SpanType.Embedding]: {
204
+ name: 'Embedding',
205
+ description: 'An embedding call',
206
+ isGenAI: true,
207
+ isHidden: false,
208
+ },
209
+ [SpanType.Retrieval]: {
210
+ name: 'Retrieval',
211
+ description: 'A retrieval call',
212
+ isGenAI: true,
213
+ isHidden: false,
214
+ },
215
+ [SpanType.Reranking]: {
216
+ name: 'Reranking',
217
+ description: 'A reranking call',
218
+ isGenAI: true,
219
+ isHidden: false,
220
+ },
221
+ [SpanType.Http]: {
222
+ name: 'HTTP',
223
+ description: 'An HTTP request',
224
+ isGenAI: false,
225
+ isHidden: true,
226
+ },
227
+ [SpanType.Segment]: {
228
+ name: 'Segment',
229
+ description: 'A (partial) segment of a trace',
230
+ isGenAI: false,
231
+ isHidden: true,
232
+ },
233
+ [SpanType.Unknown]: {
234
+ name: 'Unknown',
235
+ description: 'An unknown span',
236
+ isGenAI: false,
237
+ isHidden: true,
238
+ },
239
+ };
188
240
  var SpanStatus;
189
241
  (function (SpanStatus) {
190
242
  SpanStatus["Unset"] = "unset";
@@ -264,9 +316,9 @@ const GEN_AI_RESPONSE_FINISH_REASON_VALUE_STOP = 'stop';
264
316
  const GEN_AI_RESPONSE_FINISH_REASON_VALUE_TOOL_CALLS = 'tool_calls';
265
317
  const ATTR_HTTP_REQUEST_URL = 'http.request.url';
266
318
  const ATTR_HTTP_REQUEST_BODY = 'http.request.body';
267
- const ATTR_HTTP_REQUEST_HEADERS = 'http.request.header';
319
+ const ATTR_HTTP_REQUEST_HEADER = 'http.request.header';
268
320
  const ATTR_HTTP_RESPONSE_BODY = 'http.response.body';
269
- const ATTR_HTTP_RESPONSE_HEADERS = 'http.response.header';
321
+ const ATTR_HTTP_RESPONSE_HEADER = 'http.response.header';
270
322
  /* Note: Schemas for span ingestion following OpenTelemetry service request specification */
271
323
  var Otlp;
272
324
  (function (Otlp) {
@@ -298,10 +350,22 @@ var Otlp;
298
350
  spanId: z.string(),
299
351
  attributes: z.array(Otlp.attributeSchema).optional(),
300
352
  });
353
+ (function (StatusCode) {
354
+ StatusCode[StatusCode["Unset"] = 0] = "Unset";
355
+ StatusCode[StatusCode["Ok"] = 1] = "Ok";
356
+ StatusCode[StatusCode["Error"] = 2] = "Error";
357
+ })(Otlp.StatusCode || (Otlp.StatusCode = {}));
301
358
  Otlp.statusSchema = z.object({
302
359
  code: z.number(),
303
360
  message: z.string().optional(),
304
361
  });
362
+ (function (SpanKind) {
363
+ SpanKind[SpanKind["Internal"] = 0] = "Internal";
364
+ SpanKind[SpanKind["Server"] = 1] = "Server";
365
+ SpanKind[SpanKind["Client"] = 2] = "Client";
366
+ SpanKind[SpanKind["Producer"] = 3] = "Producer";
367
+ SpanKind[SpanKind["Consumer"] = 4] = "Consumer";
368
+ })(Otlp.SpanKind || (Otlp.SpanKind = {}));
305
369
  Otlp.spanSchema = z.object({
306
370
  traceId: z.string(),
307
371
  spanId: z.string(),
@@ -347,6 +411,16 @@ z.object({
347
411
  isError: z.boolean().optional(),
348
412
  text: z.string().optional(),
349
413
  });
414
+ var FinishReason;
415
+ (function (FinishReason) {
416
+ FinishReason["Stop"] = "stop";
417
+ FinishReason["Length"] = "length";
418
+ FinishReason["ContentFilter"] = "content-filter";
419
+ FinishReason["ToolCalls"] = "tool-calls";
420
+ FinishReason["Error"] = "error";
421
+ FinishReason["Other"] = "other";
422
+ FinishReason["Unknown"] = "unknown";
423
+ })(FinishReason || (FinishReason = {}));
350
424
 
351
425
  var ParameterType;
352
426
  (function (ParameterType) {
@@ -702,6 +776,7 @@ var IntegrationType;
702
776
  IntegrationType["Latitude"] = "latitude";
703
777
  IntegrationType["ExternalMCP"] = "custom_mcp";
704
778
  IntegrationType["HostedMCP"] = "mcp_server";
779
+ IntegrationType["Pipedream"] = "pipedream";
705
780
  })(IntegrationType || (IntegrationType = {}));
706
781
  var HostedIntegrationType;
707
782
  (function (HostedIntegrationType) {
@@ -1009,7 +1084,7 @@ class ManualInstrumentation {
1009
1084
  }
1010
1085
  const start = options || {};
1011
1086
  let operation = undefined;
1012
- if (GENAI_SPANS.includes(type)) {
1087
+ if (SPAN_SPECIFICATIONS[type].isGenAI) {
1013
1088
  operation = type;
1014
1089
  }
1015
1090
  const span = this.tracer.startSpan(name, {
@@ -1327,18 +1402,18 @@ class ManualInstrumentation {
1327
1402
  };
1328
1403
  }
1329
1404
  embedding(ctx, options) {
1330
- return this.span(ctx, options?.name || 'Embedding', SpanType.Embedding, options);
1405
+ return this.span(ctx, options?.name || SPAN_SPECIFICATIONS[SpanType.Embedding].name, SpanType.Embedding, options);
1331
1406
  }
1332
1407
  retrieval(ctx, options) {
1333
- return this.span(ctx, options?.name || 'Retrieval', SpanType.Retrieval, options);
1408
+ return this.span(ctx, options?.name || SPAN_SPECIFICATIONS[SpanType.Retrieval].name, SpanType.Retrieval, options);
1334
1409
  }
1335
1410
  reranking(ctx, options) {
1336
- return this.span(ctx, options?.name || 'Reranking', SpanType.Reranking, options);
1411
+ return this.span(ctx, options?.name || SPAN_SPECIFICATIONS[SpanType.Reranking].name, SpanType.Reranking, options);
1337
1412
  }
1338
1413
  attribifyHeaders(direction, headers) {
1339
1414
  const prefix = direction === 'request'
1340
- ? ATTR_HTTP_REQUEST_HEADERS
1341
- : ATTR_HTTP_RESPONSE_HEADERS;
1415
+ ? ATTR_HTTP_REQUEST_HEADER
1416
+ : ATTR_HTTP_RESPONSE_HEADER;
1342
1417
  const attributes = {};
1343
1418
  for (const key in headers) {
1344
1419
  const field = this.toKebabCase(key);
@@ -1352,6 +1427,7 @@ class ManualInstrumentation {
1352
1427
  http(ctx, options) {
1353
1428
  const start = options;
1354
1429
  const method = start.request.method.toUpperCase();
1430
+ // Note: do not serialize headers as a single attribute because fields won't be redacted
1355
1431
  const attrHeaders = this.attribifyHeaders('request', start.request.headers);
1356
1432
  let finalBody = '';
1357
1433
  if (typeof start.request.body === 'string') {
@@ -1378,6 +1454,7 @@ class ManualInstrumentation {
1378
1454
  context: span.context,
1379
1455
  end: (options) => {
1380
1456
  const end = options;
1457
+ // Note: do not serialize headers as a single attribute because fields won't be redacted
1381
1458
  const attrHeaders = this.attribifyHeaders('response', end.response.headers);
1382
1459
  let finalBody = '';
1383
1460
  if (typeof end.response.body === 'string') {
@@ -1426,9 +1503,7 @@ class ManualInstrumentation {
1426
1503
  };
1427
1504
  ctx = this.setBaggage(ctx, baggage, options.baggage);
1428
1505
  // 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
- });
1506
+ const span = this.span(ctx, SEGMENT_SPECIFICATIONS[type].name, SpanType.Segment, { attributes: options.attributes });
1432
1507
  let carrier = {};
1433
1508
  propagation.inject(span.context, carrier);
1434
1509
  baggage.segments.at(-1).traceparent = carrier.traceparent;
@@ -1661,7 +1736,7 @@ class LatitudeInstrumentation {
1661
1736
  }
1662
1737
  }
1663
1738
 
1664
- const TRACES_URL = `${env.GATEWAY_BASE_URL}/api/v3/otlp/v1/traces`;
1739
+ const TRACES_URL = `${env.GATEWAY_BASE_URL}/api/v3/traces`;
1665
1740
  const SERVICE_NAME = process.env.npm_package_name || 'unknown';
1666
1741
  const SCOPE_VERSION = process.env.npm_package_version || 'unknown';
1667
1742
  const BACKGROUND = () => otel.ROOT_CONTEXT;