@kortyx/otel 0.5.2 → 0.6.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,28 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.0](https://github.com/kortyx-io/kortyx/compare/otel-v0.5.3...otel-v0.6.0) (2026-09-18)
4
+
5
+
6
+ ### Features
7
+
8
+ * **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))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @kortyx/hooks bumped to 0.26.0
16
+
17
+ ## [0.5.3](https://github.com/kortyx-io/kortyx/compare/otel-v0.5.2...otel-v0.5.3) (2026-09-16)
18
+
19
+
20
+ ### Dependencies
21
+
22
+ * The following workspace dependencies were updated
23
+ * dependencies
24
+ * @kortyx/hooks bumped to 0.25.3
25
+
3
26
  ## [0.5.2](https://github.com/kortyx-io/kortyx/compare/otel-v0.5.1...otel-v0.5.2) (2026-09-15)
4
27
 
5
28
 
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/suppression of automatically captured model fault 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
@@ -26,6 +26,9 @@ module.exports = __toCommonJS(index_exports);
26
26
  // src/adapter.ts
27
27
  var import_api2 = require("@opentelemetry/api");
28
28
 
29
+ // src/attributes.ts
30
+ var import_internal = require("@kortyx/hooks/internal");
31
+
29
32
  // src/content.ts
30
33
  var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
31
34
  var shouldCapture = (value, side) => {
@@ -130,6 +133,17 @@ var normalizeKnownAttributes = (attributes) => {
130
133
  if (typeof attributes.toolCallId === "string") {
131
134
  normalized["kortyx.tool.call.id"] = attributes.toolCallId;
132
135
  }
136
+ if (attributes.version === 1 && typeof attributes.attemptId === "string") {
137
+ normalized["gen_ai.operation.name"] = "execute_tool";
138
+ normalized["gen_ai.tool.name"] = attributes.name;
139
+ normalized["gen_ai.tool.call.id"] = attributes.toolCallId;
140
+ normalized["kortyx.tool.attempt.id"] = attributes.attemptId;
141
+ normalized["kortyx.tool.outcome"] = attributes.outcome;
142
+ normalized["kortyx.tool.executed"] = attributes.executed;
143
+ normalized["kortyx.tool.denial.code"] = attributes.denialCode;
144
+ normalized["error.type"] = attributes.errorType;
145
+ normalized["error.message"] = attributes.errorMessage;
146
+ }
133
147
  return normalized;
134
148
  };
135
149
  var telemetryAttributes = (telemetry, options, side) => {
@@ -150,13 +164,18 @@ var telemetryAttributes = (telemetry, options, side) => {
150
164
  if (prompt.type) attributes["gen_ai.prompt.type"] = prompt.type;
151
165
  if (prompt.type) attributes["kortyx.prompt.type"] = prompt.type;
152
166
  if (prompt.source) attributes["kortyx.prompt.source"] = prompt.source;
153
- Object.assign(attributes, options.mapPromptMetadata?.(prompt) ?? {});
167
+ try {
168
+ Object.assign(attributes, options.mapPromptMetadata?.(prompt) ?? {});
169
+ } catch {
170
+ }
154
171
  }
155
172
  if (telemetry.tags?.length) {
156
173
  attributes["kortyx.trace.tags"] = telemetry.tags;
157
174
  }
158
175
  if (telemetry.metadata) {
159
- for (const [key, value] of Object.entries(telemetry.metadata)) {
176
+ for (const [key, value] of Object.entries(
177
+ (0, import_internal.safeTelemetryMetadata)(telemetry.metadata)
178
+ )) {
160
179
  attributes[`kortyx.trace.metadata.${key}`] = value;
161
180
  }
162
181
  }
@@ -191,16 +210,17 @@ var startAttributes = (args, options) => ({
191
210
  ...telemetryAttributes(args.telemetry, options, "input")
192
211
  });
193
212
  var applyAttributeMapping = (name, attributes, options, args) => {
194
- const mapped = options.mapAttributes?.({
195
- ...args,
196
- name,
197
- attributes
198
- }) ?? {};
213
+ let mapped = {};
214
+ try {
215
+ mapped = options.mapAttributes?.({ ...args, name, attributes }) ?? {};
216
+ } catch {
217
+ }
199
218
  return normalizeKnownAttributes({ ...attributes, ...mapped });
200
219
  };
201
220
 
202
221
  // src/span-wrapper.ts
203
222
  var import_errors = require("@kortyx/core/errors");
223
+ var import_internal2 = require("@kortyx/hooks/internal");
204
224
  var import_api = require("@opentelemetry/api");
205
225
  var createSpanWrapper = (span, name, options) => {
206
226
  const wrapper = {
@@ -220,46 +240,65 @@ var createSpanWrapper = (span, name, options) => {
220
240
  },
221
241
  end: (args) => {
222
242
  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
- );
243
+ try {
244
+ const attributes = spanEndAttributes(args, options);
245
+ if (name === "kortyx.tool" && args?.attributes?.outcome === "fault")
246
+ span.setStatus({
247
+ code: import_api.SpanStatusCode.ERROR,
248
+ message: "Tool execution failed."
249
+ });
250
+ span.setAttributes(
251
+ toAttributes(
252
+ applyAttributeMapping(name, attributes, options, {
253
+ phase: "end",
254
+ telemetry: args?.telemetry,
255
+ end: args
256
+ })
257
+ )
258
+ );
259
+ } catch {
260
+ }
233
261
  wrapper.ended = true;
234
262
  span.end();
235
263
  const spanContext = span.spanContext();
236
- options.onSpanEnd?.({
237
- name,
238
- traceId: spanContext.traceId,
239
- spanId: spanContext.spanId
240
- });
264
+ try {
265
+ options.onSpanEnd?.({
266
+ name,
267
+ traceId: spanContext.traceId,
268
+ spanId: spanContext.spanId
269
+ });
270
+ } catch {
271
+ }
241
272
  },
242
273
  fail: (error, args) => {
274
+ if (wrapper.ended) return;
243
275
  if ((0, import_errors.isControlFlowError)(error)) {
244
276
  span.setAttribute("kortyx.control_flow", true);
245
277
  wrapper.end?.(args);
246
278
  return;
247
279
  }
248
280
  const failure = (0, import_errors.serializeFailure)(error);
249
- const message = failure.message;
250
- span.recordException({ name: failure.code, message });
281
+ const diagnostic = (0, import_internal2.isModelTraceSpan)(name) ? (0, import_internal2.errorDiagnostics)(error, options.error) : { errorType: failure.code, errorMessage: failure.message };
282
+ const message = diagnostic.errorMessage ?? "Model execution failed.";
283
+ span.recordException({
284
+ name: diagnostic.errorType ?? failure.code,
285
+ message
286
+ });
251
287
  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
- );
288
+ try {
289
+ const attributes = spanErrorAttributes(error, args, diagnostic);
290
+ span.setAttributes(
291
+ toAttributes(
292
+ applyAttributeMapping(name, attributes, options, {
293
+ phase: "error",
294
+ telemetry: args?.telemetry,
295
+ end: args,
296
+ error
297
+ })
298
+ )
299
+ );
300
+ } catch {
301
+ }
263
302
  wrapper.end?.(args);
264
303
  }
265
304
  };
@@ -270,12 +309,12 @@ var spanEndAttributes = (args, options) => ({
270
309
  ...usageAttributes(args),
271
310
  ...telemetryAttributes(args?.telemetry, options, "output")
272
311
  });
273
- var spanErrorAttributes = (error, args) => {
312
+ var spanErrorAttributes = (error, args, diagnostic) => {
274
313
  const failure = (0, import_errors.serializeFailure)(error);
275
- const message = failure.message;
314
+ const message = diagnostic.errorMessage ?? "Model execution failed.";
276
315
  return {
277
316
  ...args?.attributes ?? {},
278
- "error.type": failure.code,
317
+ "error.type": diagnostic.errorType ?? failure.code,
279
318
  "kortyx.error.category": failure.category,
280
319
  "error.message": message,
281
320
  ...usageAttributes(args)
@@ -299,12 +338,15 @@ function createOpenTelemetryTraceAdapter(options = {}) {
299
338
  import_api2.context.active()
300
339
  );
301
340
  const spanContext = span.spanContext();
302
- options.onSpanStart?.({
303
- name: args.name,
304
- traceId: spanContext.traceId,
305
- spanId: spanContext.spanId,
306
- attributes
307
- });
341
+ try {
342
+ options.onSpanStart?.({
343
+ name: args.name,
344
+ traceId: spanContext.traceId,
345
+ spanId: spanContext.spanId,
346
+ attributes
347
+ });
348
+ } catch {
349
+ }
308
350
  return createSpanWrapper(span, args.name, options);
309
351
  };
310
352
  return {
@@ -320,12 +362,15 @@ function createOpenTelemetryTraceAdapter(options = {}) {
320
362
  async (span) => {
321
363
  const wrapped = createSpanWrapper(span, args.name, options);
322
364
  const spanContext = span.spanContext();
323
- options.onSpanStart?.({
324
- name: args.name,
325
- traceId: spanContext.traceId,
326
- spanId: spanContext.spanId,
327
- attributes
328
- });
365
+ try {
366
+ options.onSpanStart?.({
367
+ name: args.name,
368
+ traceId: spanContext.traceId,
369
+ spanId: spanContext.spanId,
370
+ attributes
371
+ });
372
+ } catch {
373
+ }
329
374
  try {
330
375
  const result = await fn(wrapped);
331
376
  if (!wrapped.ended) wrapped.end?.();
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,QAAO;AAC3B,MAAI,CAAC,SAAS,KAAK,EAAG,QAAO;AAC7B,SAAO,QAAQ,MAAM,IAAI,CAAC;AAC5B;;;ACIO,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,KAA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;AAAA,YACrB,QAAQ,YAAY;AAAA,YACpB;AAAA,UACF,CAAC;AACD,cAAI;AACF,kBAAM,SAAS,MAAM,GAAG,OAAO;AAC/B,gBAAI,CAAC,QAAQ,MAAO,SAAQ,MAAM;AAClC,mBAAO;AAAA,UACT,SAAS,OAAO;AACd,gBAAI;AACF,sBAAQ,OAAO,KAAK;AAAA,YACtB,QAAQ;AAAA,YAER;AACA,kBAAM;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,kBAAkB,MAAM;AACtB,YAAM,OAAO,kBAAM,cAAc;AACjC,UAAI,CAAC,KAAM,QAAO;AAClB,YAAM,cAAc,KAAK,YAAY;AACrC,aAAO;AAAA,QACL,SAAS,YAAY;AAAA,QACrB,QAAQ,YAAY;AAAA,MACtB;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_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 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 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 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 {\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 { errorDiagnostics, isModelTraceSpan } 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 = isModelTraceSpan(name)\n ? errorDiagnostics(error, options.error)\n : { errorType: failure.code, errorMessage: failure.message };\n const message = diagnostic.errorMessage ?? \"Model execution failed.\";\n span.recordException({\n name: diagnostic.errorType ?? failure.code,\n message,\n });\n span.setStatus({ code: SpanStatusCode.ERROR, message });\n try {\n const attributes = spanErrorAttributes(error, args, diagnostic);\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: { errorType?: string; errorMessage?: string },\n) => {\n const failure = serializeFailure(error);\n const message = diagnostic.errorMessage ?? \"Model execution failed.\";\n return {\n ...(args?.attributes ?? {}),\n \"error.type\": diagnostic.errorType ?? 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;;;ACAzC,sBAAsC;;;ACFtC,IAAM,WAAW,CAAC,UAChB,QAA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1
  {
2
2
  "name": "@kortyx/otel",
3
- "version": "0.5.2",
3
+ "version": "0.6.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.2",
35
+ "@kortyx/hooks": "0.26.0",
36
36
  "@kortyx/core": "0.9.0"
37
37
  },
38
38
  "peerDependencies": {