@kortyx/otel 0.5.3 → 0.7.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.7.0](https://github.com/kortyx-io/kortyx/compare/otel-v0.6.0...otel-v0.7.0) (2026-09-21)
4
+
5
+
6
+ ### Features
7
+
8
+ * **observability:** report handled workflow errors ([#222](https://github.com/kortyx-io/kortyx/issues/222)) ([68a3b0e](https://github.com/kortyx-io/kortyx/commit/68a3b0eea5d93cb89bdcef63c4767f3b0d59e60d))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @kortyx/hooks bumped to 0.27.0
16
+
17
+ ## [0.6.0](https://github.com/kortyx-io/kortyx/compare/otel-v0.5.3...otel-v0.6.0) (2026-09-18)
18
+
19
+
20
+ ### Features
21
+
22
+ * **tools:** add useTool and first-class Studio observability ([#215](https://github.com/kortyx-io/kortyx/issues/215)) ([224c92d](https://github.com/kortyx-io/kortyx/commit/224c92d73caead320dd14582d8b624efc3252c9f))
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @kortyx/hooks bumped to 0.26.0
30
+
3
31
  ## [0.5.3](https://github.com/kortyx-io/kortyx/compare/otel-v0.5.2...otel-v0.5.3) (2026-09-16)
4
32
 
5
33
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as _kortyx_hooks from '@kortyx/hooks';
1
2
  import { ReasonTraceAttributes, KortyxTraceMetadata, ReasonTraceSpanEndArgs, KortyxTelemetryPrompt, ReasonTraceAdapter } from '@kortyx/hooks';
2
3
  import { Tracer } from '@opentelemetry/api';
3
4
 
@@ -26,6 +27,8 @@ interface OpenTelemetryTraceAdapterOptions {
26
27
  instrumentationName?: string | undefined;
27
28
  instrumentationVersion?: string | undefined;
28
29
  defaultAttributes?: ReasonTraceAttributes | undefined;
30
+ /** Optional replacement or suppression of captured error diagnostics. */
31
+ error?: _kortyx_hooks.KortyxTraceErrorProjection;
29
32
  captureContent?: boolean | {
30
33
  input?: boolean | undefined;
31
34
  output?: boolean | undefined;
package/dist/index.js CHANGED
@@ -24,8 +24,13 @@ __export(index_exports, {
24
24
  module.exports = __toCommonJS(index_exports);
25
25
 
26
26
  // src/adapter.ts
27
+ var import_node_async_hooks = require("async_hooks");
28
+ var import_internal3 = require("@kortyx/hooks/internal");
27
29
  var import_api2 = require("@opentelemetry/api");
28
30
 
31
+ // src/attributes.ts
32
+ var import_internal = require("@kortyx/hooks/internal");
33
+
29
34
  // src/content.ts
30
35
  var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
31
36
  var shouldCapture = (value, side) => {
@@ -130,6 +135,17 @@ var normalizeKnownAttributes = (attributes) => {
130
135
  if (typeof attributes.toolCallId === "string") {
131
136
  normalized["kortyx.tool.call.id"] = attributes.toolCallId;
132
137
  }
138
+ if (attributes.version === 1 && typeof attributes.attemptId === "string") {
139
+ normalized["gen_ai.operation.name"] = "execute_tool";
140
+ normalized["gen_ai.tool.name"] = attributes.name;
141
+ normalized["gen_ai.tool.call.id"] = attributes.toolCallId;
142
+ normalized["kortyx.tool.attempt.id"] = attributes.attemptId;
143
+ normalized["kortyx.tool.outcome"] = attributes.outcome;
144
+ normalized["kortyx.tool.executed"] = attributes.executed;
145
+ normalized["kortyx.tool.denial.code"] = attributes.denialCode;
146
+ normalized["error.type"] = attributes.errorType;
147
+ normalized["error.message"] = attributes.errorMessage;
148
+ }
133
149
  return normalized;
134
150
  };
135
151
  var telemetryAttributes = (telemetry, options, side) => {
@@ -150,13 +166,18 @@ var telemetryAttributes = (telemetry, options, side) => {
150
166
  if (prompt.type) attributes["gen_ai.prompt.type"] = prompt.type;
151
167
  if (prompt.type) attributes["kortyx.prompt.type"] = prompt.type;
152
168
  if (prompt.source) attributes["kortyx.prompt.source"] = prompt.source;
153
- Object.assign(attributes, options.mapPromptMetadata?.(prompt) ?? {});
169
+ try {
170
+ Object.assign(attributes, options.mapPromptMetadata?.(prompt) ?? {});
171
+ } catch {
172
+ }
154
173
  }
155
174
  if (telemetry.tags?.length) {
156
175
  attributes["kortyx.trace.tags"] = telemetry.tags;
157
176
  }
158
177
  if (telemetry.metadata) {
159
- for (const [key, value] of Object.entries(telemetry.metadata)) {
178
+ for (const [key, value] of Object.entries(
179
+ (0, import_internal.safeTelemetryMetadata)(telemetry.metadata)
180
+ )) {
160
181
  attributes[`kortyx.trace.metadata.${key}`] = value;
161
182
  }
162
183
  }
@@ -191,16 +212,17 @@ var startAttributes = (args, options) => ({
191
212
  ...telemetryAttributes(args.telemetry, options, "input")
192
213
  });
193
214
  var applyAttributeMapping = (name, attributes, options, args) => {
194
- const mapped = options.mapAttributes?.({
195
- ...args,
196
- name,
197
- attributes
198
- }) ?? {};
215
+ let mapped = {};
216
+ try {
217
+ mapped = options.mapAttributes?.({ ...args, name, attributes }) ?? {};
218
+ } catch {
219
+ }
199
220
  return normalizeKnownAttributes({ ...attributes, ...mapped });
200
221
  };
201
222
 
202
223
  // src/span-wrapper.ts
203
224
  var import_errors = require("@kortyx/core/errors");
225
+ var import_internal2 = require("@kortyx/hooks/internal");
204
226
  var import_api = require("@opentelemetry/api");
205
227
  var createSpanWrapper = (span, name, options) => {
206
228
  const wrapper = {
@@ -220,46 +242,70 @@ var createSpanWrapper = (span, name, options) => {
220
242
  },
221
243
  end: (args) => {
222
244
  if (wrapper.ended) return;
223
- const attributes = spanEndAttributes(args, options);
224
- span.setAttributes(
225
- toAttributes(
226
- applyAttributeMapping(name, attributes, options, {
227
- phase: "end",
228
- telemetry: args?.telemetry,
229
- end: args
230
- })
231
- )
232
- );
245
+ try {
246
+ const attributes = spanEndAttributes(args, options);
247
+ if (name === "kortyx.tool" && args?.attributes?.outcome === "fault")
248
+ span.setStatus({
249
+ code: import_api.SpanStatusCode.ERROR,
250
+ message: "Tool execution failed."
251
+ });
252
+ span.setAttributes(
253
+ toAttributes(
254
+ applyAttributeMapping(name, attributes, options, {
255
+ phase: "end",
256
+ telemetry: args?.telemetry,
257
+ end: args
258
+ })
259
+ )
260
+ );
261
+ } catch {
262
+ }
233
263
  wrapper.ended = true;
234
264
  span.end();
235
265
  const spanContext = span.spanContext();
236
- options.onSpanEnd?.({
237
- name,
238
- traceId: spanContext.traceId,
239
- spanId: spanContext.spanId
240
- });
266
+ try {
267
+ options.onSpanEnd?.({
268
+ name,
269
+ traceId: spanContext.traceId,
270
+ spanId: spanContext.spanId
271
+ });
272
+ } catch {
273
+ }
241
274
  },
242
275
  fail: (error, args) => {
276
+ if (wrapper.ended) return;
243
277
  if ((0, import_errors.isControlFlowError)(error)) {
244
278
  span.setAttribute("kortyx.control_flow", true);
245
279
  wrapper.end?.(args);
246
280
  return;
247
281
  }
248
282
  const failure = (0, import_errors.serializeFailure)(error);
249
- const message = failure.message;
250
- span.recordException({ name: failure.code, message });
283
+ const diagnostic = (0, import_internal2.exceptionDiagnostics)(error, options.error);
284
+ const message = diagnostic?.message ?? failure.message;
285
+ span.recordException({
286
+ name: diagnostic?.type ?? failure.code,
287
+ message,
288
+ ...diagnostic?.stack ? { stack: diagnostic.stack } : {}
289
+ });
251
290
  span.setStatus({ code: import_api.SpanStatusCode.ERROR, message });
252
- const attributes = spanErrorAttributes(error, args);
253
- span.setAttributes(
254
- toAttributes(
255
- applyAttributeMapping(name, attributes, options, {
256
- phase: "error",
257
- telemetry: args?.telemetry,
258
- end: args,
259
- error
260
- })
261
- )
262
- );
291
+ try {
292
+ const attributes = spanErrorAttributes(error, args, {
293
+ type: diagnostic?.type,
294
+ message: diagnostic?.message,
295
+ cause: diagnostic?.cause
296
+ });
297
+ span.setAttributes(
298
+ toAttributes(
299
+ applyAttributeMapping(name, attributes, options, {
300
+ phase: "error",
301
+ telemetry: args?.telemetry,
302
+ end: args,
303
+ error
304
+ })
305
+ )
306
+ );
307
+ } catch {
308
+ }
263
309
  wrapper.end?.(args);
264
310
  }
265
311
  };
@@ -270,14 +316,15 @@ var spanEndAttributes = (args, options) => ({
270
316
  ...usageAttributes(args),
271
317
  ...telemetryAttributes(args?.telemetry, options, "output")
272
318
  });
273
- var spanErrorAttributes = (error, args) => {
319
+ var spanErrorAttributes = (error, args, diagnostic) => {
274
320
  const failure = (0, import_errors.serializeFailure)(error);
275
- const message = failure.message;
321
+ const message = diagnostic.message ?? failure.message;
276
322
  return {
277
323
  ...args?.attributes ?? {},
278
- "error.type": failure.code,
324
+ "error.type": diagnostic.type ?? failure.code,
279
325
  "kortyx.error.category": failure.category,
280
326
  "error.message": message,
327
+ ...diagnostic.cause ? { "kortyx.error.cause": diagnostic.cause } : {},
281
328
  ...usageAttributes(args)
282
329
  };
283
330
  };
@@ -288,6 +335,7 @@ function createOpenTelemetryTraceAdapter(options = {}) {
288
335
  options.instrumentationName ?? "kortyx",
289
336
  options.instrumentationVersion
290
337
  );
338
+ const activeSpans = new import_node_async_hooks.AsyncLocalStorage();
291
339
  const start = (args) => {
292
340
  const attributes = startAttributes(args, options);
293
341
  const span = tracer.startSpan(
@@ -299,12 +347,15 @@ function createOpenTelemetryTraceAdapter(options = {}) {
299
347
  import_api2.context.active()
300
348
  );
301
349
  const spanContext = span.spanContext();
302
- options.onSpanStart?.({
303
- name: args.name,
304
- traceId: spanContext.traceId,
305
- spanId: spanContext.spanId,
306
- attributes
307
- });
350
+ try {
351
+ options.onSpanStart?.({
352
+ name: args.name,
353
+ traceId: spanContext.traceId,
354
+ spanId: spanContext.spanId,
355
+ attributes
356
+ });
357
+ } catch {
358
+ }
308
359
  return createSpanWrapper(span, args.name, options);
309
360
  };
310
361
  return {
@@ -320,34 +371,74 @@ function createOpenTelemetryTraceAdapter(options = {}) {
320
371
  async (span) => {
321
372
  const wrapped = createSpanWrapper(span, args.name, options);
322
373
  const spanContext = span.spanContext();
323
- options.onSpanStart?.({
324
- name: args.name,
325
- traceId: spanContext.traceId,
326
- spanId: spanContext.spanId,
327
- attributes
328
- });
329
374
  try {
330
- const result = await fn(wrapped);
331
- if (!wrapped.ended) wrapped.end?.();
332
- return result;
333
- } catch (error) {
375
+ options.onSpanStart?.({
376
+ name: args.name,
377
+ traceId: spanContext.traceId,
378
+ spanId: spanContext.spanId,
379
+ attributes
380
+ });
381
+ } catch {
382
+ }
383
+ return activeSpans.run(span, async () => {
334
384
  try {
335
- wrapped.fail?.(error);
336
- } catch {
385
+ const result = await fn(wrapped);
386
+ if (!wrapped.ended) wrapped.end?.();
387
+ return result;
388
+ } catch (error) {
389
+ try {
390
+ wrapped.fail?.(error);
391
+ } catch {
392
+ }
393
+ throw error;
337
394
  }
338
- throw error;
339
- }
395
+ });
340
396
  }
341
397
  );
342
398
  },
343
399
  getActiveContext: () => {
344
- const span = import_api2.trace.getActiveSpan();
400
+ const span = activeSpans.getStore() ?? import_api2.trace.getActiveSpan();
345
401
  if (!span) return void 0;
346
402
  const spanContext = span.spanContext();
347
403
  return {
348
404
  traceId: spanContext.traceId,
349
405
  spanId: spanContext.spanId
350
406
  };
407
+ },
408
+ reportError: (error, reportOptions = {}) => {
409
+ try {
410
+ const span = activeSpans.getStore() ?? import_api2.trace.getActiveSpan();
411
+ if (!span) return;
412
+ const diagnostic = (0, import_internal3.exceptionDiagnostics)(error, options.error);
413
+ if (!diagnostic) return;
414
+ span.recordException({
415
+ name: diagnostic.type ?? "Error",
416
+ message: diagnostic.message,
417
+ ...diagnostic.stack ? { stack: diagnostic.stack } : {}
418
+ });
419
+ span.addEvent(
420
+ "kortyx.error.reported",
421
+ toAttributes({
422
+ "exception.type": diagnostic.type ?? "Error",
423
+ "exception.message": diagnostic.message,
424
+ ...diagnostic.stack ? { "exception.stacktrace": diagnostic.stack } : {},
425
+ ...diagnostic.cause ? { "kortyx.error.cause": diagnostic.cause } : {},
426
+ "exception.escaped": false,
427
+ "kortyx.error.handled": true,
428
+ "kortyx.error.severity": reportOptions.severity === "warning" ? "warning" : "error",
429
+ ...reportOptions.tags?.length ? { "kortyx.trace.tags": reportOptions.tags } : {},
430
+ ...reportOptions.metadata ? Object.fromEntries(
431
+ Object.entries(
432
+ (0, import_internal3.safeTelemetryMetadata)(reportOptions.metadata)
433
+ ).map(([key, value]) => [
434
+ `kortyx.error.metadata.${key}`,
435
+ value
436
+ ])
437
+ ) : {}
438
+ })
439
+ );
440
+ } catch {
441
+ }
351
442
  }
352
443
  };
353
444
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/adapter.ts","../src/content.ts","../src/attributes.ts","../src/span-wrapper.ts"],"sourcesContent":["export { createOpenTelemetryTraceAdapter } from \"./adapter\";\nexport type {\n OpenTelemetryMapAttributesArgs,\n OpenTelemetrySpanEndInfo,\n OpenTelemetrySpanStartInfo,\n OpenTelemetryTraceAdapterOptions,\n OpenTelemetryTracePhase,\n} from \"./types\";\n","import type {\n ReasonTraceAdapter,\n ReasonTraceAttributes,\n ReasonTraceSpan,\n ReasonTraceSpanStartArgs,\n} from \"@kortyx/hooks\";\nimport { context, SpanKind, trace } from \"@opentelemetry/api\";\nimport {\n applyAttributeMapping,\n startAttributes,\n toAttributes,\n} from \"./attributes\";\nimport { createSpanWrapper } from \"./span-wrapper\";\nimport type { OpenTelemetryTraceAdapterOptions } from \"./types\";\n\nexport function createOpenTelemetryTraceAdapter(\n options: OpenTelemetryTraceAdapterOptions = {},\n): ReasonTraceAdapter {\n const tracer =\n options.tracer ??\n trace.getTracer(\n options.instrumentationName ?? \"kortyx\",\n options.instrumentationVersion,\n );\n\n const start = (args: ReasonTraceSpanStartArgs): ReasonTraceSpan => {\n const attributes = startAttributes(args, options);\n const span = tracer.startSpan(\n args.name,\n {\n kind: SpanKind.INTERNAL,\n attributes: spanStartOtelAttributes(args, attributes, options),\n },\n context.active(),\n );\n const spanContext = span.spanContext();\n options.onSpanStart?.({\n name: args.name,\n traceId: spanContext.traceId,\n spanId: spanContext.spanId,\n attributes,\n });\n return createSpanWrapper(span, args.name, options);\n };\n\n return {\n startSpan: start,\n withSpan: async (args, fn) => {\n const attributes = startAttributes(args, options);\n return tracer.startActiveSpan(\n args.name,\n {\n kind: SpanKind.INTERNAL,\n attributes: spanStartOtelAttributes(args, attributes, options),\n },\n async (span) => {\n const wrapped = createSpanWrapper(span, args.name, options);\n const spanContext = span.spanContext();\n options.onSpanStart?.({\n name: args.name,\n traceId: spanContext.traceId,\n spanId: spanContext.spanId,\n attributes,\n });\n try {\n const result = await fn(wrapped);\n if (!wrapped.ended) wrapped.end?.();\n return result;\n } catch (error) {\n try {\n wrapped.fail?.(error);\n } catch {\n /* Preserve the callback failure. */\n }\n throw error;\n }\n },\n );\n },\n getActiveContext: () => {\n const span = trace.getActiveSpan();\n if (!span) return undefined;\n const spanContext = span.spanContext();\n return {\n traceId: spanContext.traceId,\n spanId: spanContext.spanId,\n };\n },\n };\n}\n\nconst spanStartOtelAttributes = (\n args: ReasonTraceSpanStartArgs,\n attributes: ReasonTraceAttributes,\n options: OpenTelemetryTraceAdapterOptions,\n) =>\n toAttributes(\n applyAttributeMapping(args.name, attributes, options, {\n phase: \"start\",\n telemetry: args.telemetry,\n }),\n );\n","import type { OpenTelemetryTraceAdapterOptions } from \"./types\";\n\nexport type ContentCaptureSide = \"input\" | \"output\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n\nexport const shouldCapture = (\n value: OpenTelemetryTraceAdapterOptions[\"captureContent\"],\n side: ContentCaptureSide,\n): boolean => {\n if (value === true) return true;\n if (!isRecord(value)) return false;\n return Boolean(value[side]);\n};\n","import type {\n KortyxTraceMetadata,\n ReasonTraceAttributes,\n ReasonTraceSpanEndArgs,\n ReasonTraceSpanStartArgs,\n} from \"@kortyx/hooks\";\nimport type { Attributes } from \"@opentelemetry/api\";\nimport { type ContentCaptureSide, shouldCapture } from \"./content\";\nimport type { OpenTelemetryTraceAdapterOptions } from \"./types\";\n\ntype OpenTelemetryAttributeValue =\n | string\n | number\n | boolean\n | string[]\n | number[]\n | boolean[];\n\nexport const toAttributeValue = (\n value: unknown,\n): OpenTelemetryAttributeValue | undefined => {\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\"\n ) {\n return value;\n }\n if (Array.isArray(value)) {\n if (value.every((item) => typeof item === \"string\")) {\n return value as string[];\n }\n if (value.every((item) => typeof item === \"number\")) {\n return value as number[];\n }\n if (value.every((item) => typeof item === \"boolean\")) {\n return value as boolean[];\n }\n }\n if (value === null || value === undefined) return undefined;\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n};\n\nexport const toAttributes = (attributes: ReasonTraceAttributes): Attributes => {\n const result: Attributes = {};\n for (const [key, value] of Object.entries(attributes)) {\n const attributeValue = toAttributeValue(value);\n if (attributeValue !== undefined) result[key] = attributeValue;\n }\n return result;\n};\n\nexport const normalizeKnownAttributes = (\n attributes: ReasonTraceAttributes,\n): ReasonTraceAttributes => {\n const normalized: ReasonTraceAttributes = { ...attributes };\n\n if (typeof attributes.providerId === \"string\") {\n normalized[\"gen_ai.provider.name\"] = attributes.providerId;\n normalized[\"kortyx.provider.id\"] = attributes.providerId;\n }\n if (typeof attributes.modelId === \"string\") {\n normalized[\"gen_ai.request.model\"] = attributes.modelId;\n normalized[\"kortyx.model.id\"] = attributes.modelId;\n }\n if (typeof attributes.stream === \"boolean\") {\n normalized[\"gen_ai.request.stream\"] = attributes.stream;\n }\n if (typeof attributes.operation === \"string\") {\n normalized[\"gen_ai.operation.name\"] = attributes.operation;\n normalized[\"kortyx.operation.name\"] = attributes.operation;\n }\n if (typeof attributes.nodeId === \"string\") {\n normalized[\"kortyx.node.id\"] = attributes.nodeId;\n }\n if (typeof attributes.workflowId === \"string\") {\n normalized[\"kortyx.workflow.id\"] = attributes.workflowId;\n }\n if (typeof attributes.runId === \"string\") {\n normalized[\"kortyx.run.id\"] = attributes.runId;\n }\n if (typeof attributes.sessionId === \"string\") {\n normalized[\"session.id\"] = attributes.sessionId;\n normalized[\"gen_ai.conversation.id\"] = attributes.sessionId;\n normalized[\"kortyx.session.id\"] = attributes.sessionId;\n }\n if (typeof attributes.userId === \"string\") {\n normalized[\"user.id\"] = attributes.userId;\n }\n if (typeof attributes.tenantId === \"string\") {\n normalized[\"kortyx.tenant.id\"] = attributes.tenantId;\n }\n if (typeof attributes.promptName === \"string\") {\n normalized[\"gen_ai.prompt.name\"] = attributes.promptName;\n normalized[\"kortyx.prompt.name\"] = attributes.promptName;\n }\n if (attributes.promptVersion !== undefined) {\n normalized[\"gen_ai.prompt.version\"] = attributes.promptVersion;\n normalized[\"kortyx.prompt.version\"] = attributes.promptVersion;\n }\n if (typeof attributes.promptType === \"string\") {\n normalized[\"gen_ai.prompt.type\"] = attributes.promptType;\n normalized[\"kortyx.prompt.type\"] = attributes.promptType;\n }\n if (typeof attributes.toolCallCount === \"number\") {\n normalized[\"kortyx.tool.call.count\"] = attributes.toolCallCount;\n }\n if (typeof attributes.toolResultCount === \"number\") {\n normalized[\"kortyx.tool.result.count\"] = attributes.toolResultCount;\n }\n if (typeof attributes.toolStepCount === \"number\") {\n normalized[\"kortyx.tool.step.count\"] = attributes.toolStepCount;\n }\n if (typeof attributes.tool === \"string\") {\n normalized[\"gen_ai.tool.name\"] = attributes.tool;\n normalized[\"kortyx.tool.name\"] = attributes.tool;\n }\n if (typeof attributes.toolCallId === \"string\") {\n normalized[\"kortyx.tool.call.id\"] = attributes.toolCallId;\n }\n\n return normalized;\n};\n\nexport const telemetryAttributes = (\n telemetry: KortyxTraceMetadata | undefined,\n options: OpenTelemetryTraceAdapterOptions,\n side?: ContentCaptureSide,\n): ReasonTraceAttributes => {\n const attributes: ReasonTraceAttributes = {};\n if (!telemetry) return attributes;\n\n if (telemetry.operation) {\n attributes.operation = telemetry.operation;\n attributes[\"gen_ai.operation.name\"] = telemetry.operation;\n }\n\n if (telemetry.prompt) {\n const prompt = telemetry.prompt;\n if (prompt.name) attributes[\"gen_ai.prompt.name\"] = prompt.name;\n if (prompt.name) attributes[\"kortyx.prompt.name\"] = prompt.name;\n if (prompt.version !== undefined) {\n attributes[\"gen_ai.prompt.version\"] = prompt.version;\n attributes[\"kortyx.prompt.version\"] = prompt.version;\n }\n if (prompt.type) attributes[\"gen_ai.prompt.type\"] = prompt.type;\n if (prompt.type) attributes[\"kortyx.prompt.type\"] = prompt.type;\n if (prompt.source) attributes[\"kortyx.prompt.source\"] = prompt.source;\n Object.assign(attributes, options.mapPromptMetadata?.(prompt) ?? {});\n }\n\n if (telemetry.tags?.length) {\n attributes[\"kortyx.trace.tags\"] = telemetry.tags;\n }\n\n if (telemetry.metadata) {\n for (const [key, value] of Object.entries(telemetry.metadata)) {\n attributes[`kortyx.trace.metadata.${key}`] = value;\n }\n }\n\n if (\n side === \"input\" &&\n shouldCapture(telemetry.captureContent ?? options.captureContent, \"input\")\n ) {\n attributes[\"gen_ai.prompt\"] = telemetry.input;\n attributes[\"kortyx.trace.input\"] = telemetry.input;\n }\n if (\n side === \"output\" &&\n shouldCapture(telemetry.captureContent ?? options.captureContent, \"output\")\n ) {\n attributes[\"gen_ai.completion\"] = telemetry.output;\n attributes[\"kortyx.trace.output\"] = telemetry.output;\n }\n\n return attributes;\n};\n\nexport const usageAttributes = (\n args: ReasonTraceSpanEndArgs | undefined,\n): ReasonTraceAttributes => {\n const usage = args?.usage;\n if (!usage) return {};\n return {\n ...(usage.input !== undefined\n ? { \"gen_ai.usage.input_tokens\": usage.input }\n : {}),\n ...(usage.output !== undefined\n ? { \"gen_ai.usage.output_tokens\": usage.output }\n : {}),\n ...(usage.total !== undefined\n ? { \"gen_ai.usage.total_tokens\": usage.total }\n : {}),\n ...(usage.reasoning !== undefined\n ? { \"gen_ai.usage.reasoning.output_tokens\": usage.reasoning }\n : {}),\n ...(usage.cacheRead !== undefined\n ? { \"gen_ai.usage.cache_read.input_tokens\": usage.cacheRead }\n : {}),\n ...(usage.cacheWrite !== undefined\n ? { \"gen_ai.usage.cache_creation.input_tokens\": usage.cacheWrite }\n : {}),\n ...(args.finishReason?.unified\n ? { \"gen_ai.response.finish_reasons\": [args.finishReason.unified] }\n : {}),\n ...(args.finishReason?.raw\n ? { \"kortyx.finish_reason.raw\": args.finishReason.raw }\n : {}),\n ...(args.warnings?.length\n ? { \"kortyx.warning.count\": args.warnings.length }\n : {}),\n };\n};\n\nexport const startAttributes = (\n args: ReasonTraceSpanStartArgs,\n options: OpenTelemetryTraceAdapterOptions,\n): ReasonTraceAttributes => ({\n ...(options.defaultAttributes ?? {}),\n ...(args.attributes ?? {}),\n ...telemetryAttributes(args.telemetry, options, \"input\"),\n});\n\nexport const applyAttributeMapping = (\n name: string,\n attributes: ReasonTraceAttributes,\n options: OpenTelemetryTraceAdapterOptions,\n args: Omit<\n Parameters<\n NonNullable<OpenTelemetryTraceAdapterOptions[\"mapAttributes\"]>\n >[0],\n \"name\" | \"attributes\"\n >,\n): ReasonTraceAttributes => {\n const mapped =\n options.mapAttributes?.({\n ...args,\n name,\n attributes,\n }) ?? {};\n return normalizeKnownAttributes({ ...attributes, ...mapped });\n};\n","import { isControlFlowError, serializeFailure } from \"@kortyx/core/errors\";\nimport type { ReasonTraceSpan, ReasonTraceSpanEndArgs } from \"@kortyx/hooks\";\nimport { type Span, SpanStatusCode } from \"@opentelemetry/api\";\nimport {\n applyAttributeMapping,\n normalizeKnownAttributes,\n telemetryAttributes,\n toAttributes,\n usageAttributes,\n} from \"./attributes\";\nimport type { OpenTelemetryTraceAdapterOptions } from \"./types\";\n\nexport type OpenTelemetryReasonSpan = ReasonTraceSpan & { ended: boolean };\n\nexport const createSpanWrapper = (\n span: Span,\n name: string,\n options: OpenTelemetryTraceAdapterOptions,\n): OpenTelemetryReasonSpan => {\n const wrapper: OpenTelemetryReasonSpan = {\n ended: false,\n setAttributes: (attributes) => {\n span.setAttributes(toAttributes(normalizeKnownAttributes(attributes)));\n },\n addEvent: (eventName, attributes) => {\n span.addEvent(\n eventName,\n toAttributes(\n applyAttributeMapping(name, attributes ?? {}, options, {\n phase: \"event\",\n }),\n ),\n );\n },\n end: (args) => {\n if (wrapper.ended) return;\n const attributes = spanEndAttributes(args, options);\n span.setAttributes(\n toAttributes(\n applyAttributeMapping(name, attributes, options, {\n phase: \"end\",\n telemetry: args?.telemetry,\n end: args,\n }),\n ),\n );\n wrapper.ended = true;\n span.end();\n const spanContext = span.spanContext();\n options.onSpanEnd?.({\n name,\n traceId: spanContext.traceId,\n spanId: spanContext.spanId,\n });\n },\n fail: (error, args) => {\n if (isControlFlowError(error)) {\n span.setAttribute(\"kortyx.control_flow\", true);\n wrapper.end?.(args);\n return;\n }\n const failure = serializeFailure(error);\n const message = failure.message;\n span.recordException({ name: failure.code, message });\n span.setStatus({ code: SpanStatusCode.ERROR, message });\n const attributes = spanErrorAttributes(error, args);\n span.setAttributes(\n toAttributes(\n applyAttributeMapping(name, attributes, options, {\n phase: \"error\",\n telemetry: args?.telemetry,\n end: args,\n error,\n }),\n ),\n );\n wrapper.end?.(args);\n },\n };\n return wrapper;\n};\n\nconst spanEndAttributes = (\n args: ReasonTraceSpanEndArgs | undefined,\n options: OpenTelemetryTraceAdapterOptions,\n) => ({\n ...(args?.attributes ?? {}),\n ...usageAttributes(args),\n ...telemetryAttributes(args?.telemetry, options, \"output\"),\n});\n\nconst spanErrorAttributes = (\n error: unknown,\n args: ReasonTraceSpanEndArgs | undefined,\n) => {\n const failure = serializeFailure(error);\n const message = failure.message;\n return {\n ...(args?.attributes ?? {}),\n \"error.type\": failure.code,\n \"kortyx.error.category\": failure.category,\n \"error.message\": message,\n ...usageAttributes(args),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,IAAAA,cAAyC;;;ACFzC,IAAM,WAAW,CAAC,UAChB,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAE9D,IAAM,gBAAgB,CAC3B,OACA,SACY;AACZ,MAAI,UAAU,KAAM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IACP,WAAW,KAAK;AAAA,EAClB,CAAC;AACH;","names":["import_api"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/adapter.ts","../src/attributes.ts","../src/content.ts","../src/span-wrapper.ts"],"sourcesContent":["export { createOpenTelemetryTraceAdapter } from \"./adapter\";\nexport type {\n OpenTelemetryMapAttributesArgs,\n OpenTelemetrySpanEndInfo,\n OpenTelemetrySpanStartInfo,\n OpenTelemetryTraceAdapterOptions,\n OpenTelemetryTracePhase,\n} from \"./types\";\n","import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type {\n ReasonTraceAdapter,\n ReasonTraceAttributes,\n ReasonTraceSpan,\n ReasonTraceSpanStartArgs,\n} from \"@kortyx/hooks\";\nimport {\n exceptionDiagnostics,\n safeTelemetryMetadata,\n} from \"@kortyx/hooks/internal\";\nimport { context, type Span, SpanKind, trace } from \"@opentelemetry/api\";\nimport {\n applyAttributeMapping,\n startAttributes,\n toAttributes,\n} from \"./attributes\";\nimport { createSpanWrapper } from \"./span-wrapper\";\nimport type { OpenTelemetryTraceAdapterOptions } from \"./types\";\n\nexport function createOpenTelemetryTraceAdapter(\n options: OpenTelemetryTraceAdapterOptions = {},\n): ReasonTraceAdapter {\n const tracer =\n options.tracer ??\n trace.getTracer(\n options.instrumentationName ?? \"kortyx\",\n options.instrumentationVersion,\n );\n const activeSpans = new AsyncLocalStorage<Span>();\n\n const start = (args: ReasonTraceSpanStartArgs): ReasonTraceSpan => {\n const attributes = startAttributes(args, options);\n const span = tracer.startSpan(\n args.name,\n {\n kind: SpanKind.INTERNAL,\n attributes: spanStartOtelAttributes(args, attributes, options),\n },\n context.active(),\n );\n const spanContext = span.spanContext();\n try {\n options.onSpanStart?.({\n name: args.name,\n traceId: spanContext.traceId,\n spanId: spanContext.spanId,\n attributes,\n });\n } catch {}\n return createSpanWrapper(span, args.name, options);\n };\n\n return {\n startSpan: start,\n withSpan: async (args, fn) => {\n const attributes = startAttributes(args, options);\n return tracer.startActiveSpan(\n args.name,\n {\n kind: SpanKind.INTERNAL,\n attributes: spanStartOtelAttributes(args, attributes, options),\n },\n async (span) => {\n const wrapped = createSpanWrapper(span, args.name, options);\n const spanContext = span.spanContext();\n try {\n options.onSpanStart?.({\n name: args.name,\n traceId: spanContext.traceId,\n spanId: spanContext.spanId,\n attributes,\n });\n } catch {}\n return activeSpans.run(span, async () => {\n try {\n const result = await fn(wrapped);\n if (!wrapped.ended) wrapped.end?.();\n return result;\n } catch (error) {\n try {\n wrapped.fail?.(error);\n } catch {\n /* Preserve the callback failure. */\n }\n throw error;\n }\n });\n },\n );\n },\n getActiveContext: () => {\n const span = activeSpans.getStore() ?? trace.getActiveSpan();\n if (!span) return undefined;\n const spanContext = span.spanContext();\n return {\n traceId: spanContext.traceId,\n spanId: spanContext.spanId,\n };\n },\n reportError: (error, reportOptions = {}) => {\n try {\n const span = activeSpans.getStore() ?? trace.getActiveSpan();\n if (!span) return;\n const diagnostic = exceptionDiagnostics(error, options.error);\n if (!diagnostic) return;\n span.recordException({\n name: diagnostic.type ?? \"Error\",\n message: diagnostic.message,\n ...(diagnostic.stack ? { stack: diagnostic.stack } : {}),\n });\n span.addEvent(\n \"kortyx.error.reported\",\n toAttributes({\n \"exception.type\": diagnostic.type ?? \"Error\",\n \"exception.message\": diagnostic.message,\n ...(diagnostic.stack\n ? { \"exception.stacktrace\": diagnostic.stack }\n : {}),\n ...(diagnostic.cause\n ? { \"kortyx.error.cause\": diagnostic.cause }\n : {}),\n \"exception.escaped\": false,\n \"kortyx.error.handled\": true,\n \"kortyx.error.severity\":\n reportOptions.severity === \"warning\" ? \"warning\" : \"error\",\n ...(reportOptions.tags?.length\n ? { \"kortyx.trace.tags\": reportOptions.tags }\n : {}),\n ...(reportOptions.metadata\n ? Object.fromEntries(\n Object.entries(\n safeTelemetryMetadata(reportOptions.metadata),\n ).map(([key, value]) => [\n `kortyx.error.metadata.${key}`,\n value,\n ]),\n )\n : {}),\n }),\n );\n } catch {\n // Error reporting is an observer and cannot change execution.\n }\n },\n };\n}\n\nconst spanStartOtelAttributes = (\n args: ReasonTraceSpanStartArgs,\n attributes: ReasonTraceAttributes,\n options: OpenTelemetryTraceAdapterOptions,\n) =>\n toAttributes(\n applyAttributeMapping(args.name, attributes, options, {\n phase: \"start\",\n telemetry: args.telemetry,\n }),\n );\n","import type {\n KortyxTraceMetadata,\n ReasonTraceAttributes,\n ReasonTraceSpanEndArgs,\n ReasonTraceSpanStartArgs,\n} from \"@kortyx/hooks\";\nimport { safeTelemetryMetadata } from \"@kortyx/hooks/internal\";\nimport type { Attributes } from \"@opentelemetry/api\";\nimport { type ContentCaptureSide, shouldCapture } from \"./content\";\nimport type { OpenTelemetryTraceAdapterOptions } from \"./types\";\n\ntype OpenTelemetryAttributeValue =\n | string\n | number\n | boolean\n | string[]\n | number[]\n | boolean[];\n\nexport const toAttributeValue = (\n value: unknown,\n): OpenTelemetryAttributeValue | undefined => {\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\"\n ) {\n return value;\n }\n if (Array.isArray(value)) {\n if (value.every((item) => typeof item === \"string\")) {\n return value as string[];\n }\n if (value.every((item) => typeof item === \"number\")) {\n return value as number[];\n }\n if (value.every((item) => typeof item === \"boolean\")) {\n return value as boolean[];\n }\n }\n if (value === null || value === undefined) return undefined;\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n};\n\nexport const toAttributes = (attributes: ReasonTraceAttributes): Attributes => {\n const result: Attributes = {};\n for (const [key, value] of Object.entries(attributes)) {\n const attributeValue = toAttributeValue(value);\n if (attributeValue !== undefined) result[key] = attributeValue;\n }\n return result;\n};\n\nexport const normalizeKnownAttributes = (\n attributes: ReasonTraceAttributes,\n): ReasonTraceAttributes => {\n const normalized: ReasonTraceAttributes = { ...attributes };\n\n if (typeof attributes.providerId === \"string\") {\n normalized[\"gen_ai.provider.name\"] = attributes.providerId;\n normalized[\"kortyx.provider.id\"] = attributes.providerId;\n }\n if (typeof attributes.modelId === \"string\") {\n normalized[\"gen_ai.request.model\"] = attributes.modelId;\n normalized[\"kortyx.model.id\"] = attributes.modelId;\n }\n if (typeof attributes.stream === \"boolean\") {\n normalized[\"gen_ai.request.stream\"] = attributes.stream;\n }\n if (typeof attributes.operation === \"string\") {\n normalized[\"gen_ai.operation.name\"] = attributes.operation;\n normalized[\"kortyx.operation.name\"] = attributes.operation;\n }\n if (typeof attributes.nodeId === \"string\") {\n normalized[\"kortyx.node.id\"] = attributes.nodeId;\n }\n if (typeof attributes.workflowId === \"string\") {\n normalized[\"kortyx.workflow.id\"] = attributes.workflowId;\n }\n if (typeof attributes.runId === \"string\") {\n normalized[\"kortyx.run.id\"] = attributes.runId;\n }\n if (typeof attributes.sessionId === \"string\") {\n normalized[\"session.id\"] = attributes.sessionId;\n normalized[\"gen_ai.conversation.id\"] = attributes.sessionId;\n normalized[\"kortyx.session.id\"] = attributes.sessionId;\n }\n if (typeof attributes.userId === \"string\") {\n normalized[\"user.id\"] = attributes.userId;\n }\n if (typeof attributes.tenantId === \"string\") {\n normalized[\"kortyx.tenant.id\"] = attributes.tenantId;\n }\n if (typeof attributes.promptName === \"string\") {\n normalized[\"gen_ai.prompt.name\"] = attributes.promptName;\n normalized[\"kortyx.prompt.name\"] = attributes.promptName;\n }\n if (attributes.promptVersion !== undefined) {\n normalized[\"gen_ai.prompt.version\"] = attributes.promptVersion;\n normalized[\"kortyx.prompt.version\"] = attributes.promptVersion;\n }\n if (typeof attributes.promptType === \"string\") {\n normalized[\"gen_ai.prompt.type\"] = attributes.promptType;\n normalized[\"kortyx.prompt.type\"] = attributes.promptType;\n }\n if (typeof attributes.toolCallCount === \"number\") {\n normalized[\"kortyx.tool.call.count\"] = attributes.toolCallCount;\n }\n if (typeof attributes.toolResultCount === \"number\") {\n normalized[\"kortyx.tool.result.count\"] = attributes.toolResultCount;\n }\n if (typeof attributes.toolStepCount === \"number\") {\n normalized[\"kortyx.tool.step.count\"] = attributes.toolStepCount;\n }\n if (typeof attributes.tool === \"string\") {\n normalized[\"gen_ai.tool.name\"] = attributes.tool;\n normalized[\"kortyx.tool.name\"] = attributes.tool;\n }\n if (typeof attributes.toolCallId === \"string\") {\n normalized[\"kortyx.tool.call.id\"] = attributes.toolCallId;\n }\n\n if (attributes.version === 1 && typeof attributes.attemptId === \"string\") {\n normalized[\"gen_ai.operation.name\"] = \"execute_tool\";\n normalized[\"gen_ai.tool.name\"] = attributes.name;\n normalized[\"gen_ai.tool.call.id\"] = attributes.toolCallId;\n normalized[\"kortyx.tool.attempt.id\"] = attributes.attemptId;\n normalized[\"kortyx.tool.outcome\"] = attributes.outcome;\n normalized[\"kortyx.tool.executed\"] = attributes.executed;\n normalized[\"kortyx.tool.denial.code\"] = attributes.denialCode;\n normalized[\"error.type\"] = attributes.errorType;\n normalized[\"error.message\"] = attributes.errorMessage;\n }\n return normalized;\n};\n\nexport const telemetryAttributes = (\n telemetry: KortyxTraceMetadata | undefined,\n options: OpenTelemetryTraceAdapterOptions,\n side?: ContentCaptureSide,\n): ReasonTraceAttributes => {\n const attributes: ReasonTraceAttributes = {};\n if (!telemetry) return attributes;\n\n if (telemetry.operation) {\n attributes.operation = telemetry.operation;\n attributes[\"gen_ai.operation.name\"] = telemetry.operation;\n }\n\n if (telemetry.prompt) {\n const prompt = telemetry.prompt;\n if (prompt.name) attributes[\"gen_ai.prompt.name\"] = prompt.name;\n if (prompt.name) attributes[\"kortyx.prompt.name\"] = prompt.name;\n if (prompt.version !== undefined) {\n attributes[\"gen_ai.prompt.version\"] = prompt.version;\n attributes[\"kortyx.prompt.version\"] = prompt.version;\n }\n if (prompt.type) attributes[\"gen_ai.prompt.type\"] = prompt.type;\n if (prompt.type) attributes[\"kortyx.prompt.type\"] = prompt.type;\n if (prompt.source) attributes[\"kortyx.prompt.source\"] = prompt.source;\n try {\n Object.assign(attributes, options.mapPromptMetadata?.(prompt) ?? {});\n } catch {}\n }\n\n if (telemetry.tags?.length) {\n attributes[\"kortyx.trace.tags\"] = telemetry.tags;\n }\n\n if (telemetry.metadata) {\n for (const [key, value] of Object.entries(\n safeTelemetryMetadata(telemetry.metadata),\n )) {\n attributes[`kortyx.trace.metadata.${key}`] = value;\n }\n }\n\n if (\n side === \"input\" &&\n shouldCapture(telemetry.captureContent ?? options.captureContent, \"input\")\n ) {\n attributes[\"gen_ai.prompt\"] = telemetry.input;\n attributes[\"kortyx.trace.input\"] = telemetry.input;\n }\n if (\n side === \"output\" &&\n shouldCapture(telemetry.captureContent ?? options.captureContent, \"output\")\n ) {\n attributes[\"gen_ai.completion\"] = telemetry.output;\n attributes[\"kortyx.trace.output\"] = telemetry.output;\n }\n\n return attributes;\n};\n\nexport const usageAttributes = (\n args: ReasonTraceSpanEndArgs | undefined,\n): ReasonTraceAttributes => {\n const usage = args?.usage;\n if (!usage) return {};\n return {\n ...(usage.input !== undefined\n ? { \"gen_ai.usage.input_tokens\": usage.input }\n : {}),\n ...(usage.output !== undefined\n ? { \"gen_ai.usage.output_tokens\": usage.output }\n : {}),\n ...(usage.total !== undefined\n ? { \"gen_ai.usage.total_tokens\": usage.total }\n : {}),\n ...(usage.reasoning !== undefined\n ? { \"gen_ai.usage.reasoning.output_tokens\": usage.reasoning }\n : {}),\n ...(usage.cacheRead !== undefined\n ? { \"gen_ai.usage.cache_read.input_tokens\": usage.cacheRead }\n : {}),\n ...(usage.cacheWrite !== undefined\n ? { \"gen_ai.usage.cache_creation.input_tokens\": usage.cacheWrite }\n : {}),\n ...(args.finishReason?.unified\n ? { \"gen_ai.response.finish_reasons\": [args.finishReason.unified] }\n : {}),\n ...(args.finishReason?.raw\n ? { \"kortyx.finish_reason.raw\": args.finishReason.raw }\n : {}),\n ...(args.warnings?.length\n ? { \"kortyx.warning.count\": args.warnings.length }\n : {}),\n };\n};\n\nexport const startAttributes = (\n args: ReasonTraceSpanStartArgs,\n options: OpenTelemetryTraceAdapterOptions,\n): ReasonTraceAttributes => ({\n ...(options.defaultAttributes ?? {}),\n ...(args.attributes ?? {}),\n ...telemetryAttributes(args.telemetry, options, \"input\"),\n});\n\nexport const applyAttributeMapping = (\n name: string,\n attributes: ReasonTraceAttributes,\n options: OpenTelemetryTraceAdapterOptions,\n args: Omit<\n Parameters<\n NonNullable<OpenTelemetryTraceAdapterOptions[\"mapAttributes\"]>\n >[0],\n \"name\" | \"attributes\"\n >,\n): ReasonTraceAttributes => {\n let mapped: ReasonTraceAttributes = {};\n try {\n mapped = options.mapAttributes?.({ ...args, name, attributes }) ?? {};\n } catch {}\n return normalizeKnownAttributes({ ...attributes, ...mapped });\n};\n","import type { OpenTelemetryTraceAdapterOptions } from \"./types\";\n\nexport type ContentCaptureSide = \"input\" | \"output\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n\nexport const shouldCapture = (\n value: OpenTelemetryTraceAdapterOptions[\"captureContent\"],\n side: ContentCaptureSide,\n): boolean => {\n if (value === true) return true;\n if (!isRecord(value)) return false;\n return Boolean(value[side]);\n};\n","import { isControlFlowError, serializeFailure } from \"@kortyx/core/errors\";\nimport type { ReasonTraceSpan, ReasonTraceSpanEndArgs } from \"@kortyx/hooks\";\nimport { exceptionDiagnostics } from \"@kortyx/hooks/internal\";\nimport { type Span, SpanStatusCode } from \"@opentelemetry/api\";\nimport {\n applyAttributeMapping,\n normalizeKnownAttributes,\n telemetryAttributes,\n toAttributes,\n usageAttributes,\n} from \"./attributes\";\nimport type { OpenTelemetryTraceAdapterOptions } from \"./types\";\n\nexport type OpenTelemetryReasonSpan = ReasonTraceSpan & { ended: boolean };\n\nexport const createSpanWrapper = (\n span: Span,\n name: string,\n options: OpenTelemetryTraceAdapterOptions,\n): OpenTelemetryReasonSpan => {\n const wrapper: OpenTelemetryReasonSpan = {\n ended: false,\n setAttributes: (attributes) => {\n span.setAttributes(toAttributes(normalizeKnownAttributes(attributes)));\n },\n addEvent: (eventName, attributes) => {\n span.addEvent(\n eventName,\n toAttributes(\n applyAttributeMapping(name, attributes ?? {}, options, {\n phase: \"event\",\n }),\n ),\n );\n },\n end: (args) => {\n if (wrapper.ended) return;\n try {\n const attributes = spanEndAttributes(args, options);\n if (name === \"kortyx.tool\" && args?.attributes?.outcome === \"fault\")\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: \"Tool execution failed.\",\n });\n span.setAttributes(\n toAttributes(\n applyAttributeMapping(name, attributes, options, {\n phase: \"end\",\n telemetry: args?.telemetry,\n end: args,\n }),\n ),\n );\n } catch {\n /* Attribute callbacks are observers. */\n }\n wrapper.ended = true;\n span.end();\n const spanContext = span.spanContext();\n try {\n options.onSpanEnd?.({\n name,\n traceId: spanContext.traceId,\n spanId: spanContext.spanId,\n });\n } catch {}\n },\n fail: (error, args) => {\n if (wrapper.ended) return;\n if (isControlFlowError(error)) {\n span.setAttribute(\"kortyx.control_flow\", true);\n wrapper.end?.(args);\n return;\n }\n const failure = serializeFailure(error);\n const diagnostic = exceptionDiagnostics(error, options.error);\n const message = diagnostic?.message ?? failure.message;\n span.recordException({\n name: diagnostic?.type ?? failure.code,\n message,\n ...(diagnostic?.stack ? { stack: diagnostic.stack } : {}),\n });\n span.setStatus({ code: SpanStatusCode.ERROR, message });\n try {\n const attributes = spanErrorAttributes(error, args, {\n type: diagnostic?.type,\n message: diagnostic?.message,\n cause: diagnostic?.cause,\n });\n span.setAttributes(\n toAttributes(\n applyAttributeMapping(name, attributes, options, {\n phase: \"error\",\n telemetry: args?.telemetry,\n end: args,\n error,\n }),\n ),\n );\n } catch {\n /* Preserve execution failure and finish the physical span. */\n }\n wrapper.end?.(args);\n },\n };\n return wrapper;\n};\n\nconst spanEndAttributes = (\n args: ReasonTraceSpanEndArgs | undefined,\n options: OpenTelemetryTraceAdapterOptions,\n) => ({\n ...(args?.attributes ?? {}),\n ...usageAttributes(args),\n ...telemetryAttributes(args?.telemetry, options, \"output\"),\n});\n\nconst spanErrorAttributes = (\n error: unknown,\n args: ReasonTraceSpanEndArgs | undefined,\n diagnostic: {\n type: string | undefined;\n message: string | undefined;\n cause: import(\"@kortyx/hooks\").KortyxErrorDetails | undefined;\n },\n) => {\n const failure = serializeFailure(error);\n const message = diagnostic.message ?? failure.message;\n return {\n ...(args?.attributes ?? {}),\n \"error.type\": diagnostic.type ?? failure.code,\n \"kortyx.error.category\": failure.category,\n \"error.message\": message,\n ...(diagnostic.cause ? { \"kortyx.error.cause\": diagnostic.cause } : {}),\n ...usageAttributes(args),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,8BAAkC;AAOlC,IAAAA,mBAGO;AACP,IAAAC,cAAoD;;;ACLpD,sBAAsC;;;ACFtC,IAAM,WAAW,CAAC,UAChB,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAE9D,IAAM,gBAAgB,CAC3B,OACA,SACY;AACZ,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI,CAAC,SAAS,KAAK,EAAG,QAAO;AAC7B,SAAO,QAAQ,MAAM,IAAI,CAAC;AAC5B;;;ADKO,IAAM,mBAAmB,CAC9B,UAC4C;AAC5C,MACE,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU,WACjB;AACA,WAAO;AAAA,EACT;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,QAAI,MAAM,MAAM,CAAC,SAAS,OAAO,SAAS,QAAQ,GAAG;AACnD,aAAO;AAAA,IACT;AACA,QAAI,MAAM,MAAM,CAAC,SAAS,OAAO,SAAS,QAAQ,GAAG;AACnD,aAAO;AAAA,IACT;AACA,QAAI,MAAM,MAAM,CAAC,SAAS,OAAO,SAAS,SAAS,GAAG;AACpD,aAAO;AAAA,IACT;AAAA,EACF;AACA,MAAI,UAAU,QAAQ,UAAU,OAAW,QAAO;AAClD,MAAI;AACF,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B,QAAQ;AACN,WAAO,OAAO,KAAK;AAAA,EACrB;AACF;AAEO,IAAM,eAAe,CAAC,eAAk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YACL,GAAI,cAAc,WACd,OAAO;AAAA,cACL,OAAO;AAAA,oBACL,wCAAsB,cAAc,QAAQ;AAAA,cAC9C,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,gBACtB,yBAAyB,GAAG;AAAA,gBAC5B;AAAA,cACF,CAAC;AAAA,YACH,IACA,CAAC;AAAA,UACP,CAAC;AAAA,QACH;AAAA,MACF,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAM,0BAA0B,CAC9B,MACA,YACA,YAEA;AAAA,EACE,sBAAsB,KAAK,MAAM,YAAY,SAAS;AAAA,IACpD,OAAO;AAAA,IACP,WAAW,KAAK;AAAA,EAClB,CAAC;AACH;","names":["import_internal","import_api","import_internal"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kortyx/otel",
3
- "version": "0.5.3",
3
+ "version": "0.7.0",
4
4
  "private": false,
5
5
  "description": "OpenTelemetry adapter for Kortyx tracing.",
6
6
  "keywords": [
@@ -32,7 +32,7 @@
32
32
  "CHANGELOG.md"
33
33
  ],
34
34
  "dependencies": {
35
- "@kortyx/hooks": "0.25.3",
35
+ "@kortyx/hooks": "0.27.0",
36
36
  "@kortyx/core": "0.9.0"
37
37
  },
38
38
  "peerDependencies": {