@kortyx/telemetry 0.1.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 ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Initial Studio telemetry HTTP adapter.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # @kortyx/telemetry
2
+
3
+ `@kortyx/telemetry` is the optional HTTP telemetry adapter for Kortyx Studio.
4
+ It is separate from the framework entry package, so applications that do not
5
+ send Studio telemetry do not include its HTTP transport.
6
+
7
+ ```ts
8
+ import { createAgent } from "kortyx";
9
+ import { createKortyxTelemetryAdapter } from "@kortyx/telemetry";
10
+
11
+ const telemetry = createKortyxTelemetryAdapter({
12
+ endpoint: process.env.KORTYX_TELEMETRY_ENDPOINT!,
13
+ apiKey: process.env.KORTYX_TELEMETRY_API_KEY!,
14
+ environment: "production",
15
+ service: { name: "support-agent" },
16
+ });
17
+
18
+ const agent = createAgent({
19
+ // ...workflow configuration
20
+ telemetry,
21
+ });
22
+ ```
23
+
24
+ `@kortyx/otel` is a separate optional adapter for OpenTelemetry. Applications
25
+ choose the adapter appropriate to their telemetry destination; `kortyx` itself
26
+ does not provide an HTTP telemetry transport.
27
+
28
+ ## Privacy
29
+
30
+ Prompt, input, and output content is excluded by default. Enable only the
31
+ content sides your application is allowed to export:
32
+
33
+ ```ts
34
+ createKortyxTelemetryAdapter({
35
+ // ...connection and service options
36
+ captureContent: { input: true, output: false },
37
+ });
38
+ ```
39
+
40
+ Telemetry metadata, tags, operation names, prompt identity (name, version,
41
+ type, source), and trusted `userId`/`tenantId` trace attributes remain
42
+ available without enabling content capture.
43
+
44
+ ## Delivery and lifecycle signals
45
+
46
+ Delivery is best-effort and at-least-once while the process remains alive. The
47
+ adapter batches events, retries transient failures, and exposes `flush()` for
48
+ controlled shutdown. It has no durable outbox; applications that need durable
49
+ delivery must own that outbox themselves. Telemetry failures never fail a
50
+ workflow execution.
51
+
52
+ `interrupt.expired` is intentionally API-derived from the durable `expiresAt`
53
+ included with `interrupt.created`. The SDK does not use an unreliable local TTL
54
+ timer.
55
+
56
+ `run.cancelled` is reserved until Kortyx exposes a real SDK cancellation
57
+ operation. A client disconnect is not a cancellation.
@@ -0,0 +1,27 @@
1
+ import { KortyxTelemetryService, KortyxTelemetryConfig } from '@kortyx/hooks';
2
+
3
+ type CreateKortyxTelemetryAdapterOptions = {
4
+ endpoint: string;
5
+ apiKey: string;
6
+ environment: string;
7
+ service: KortyxTelemetryService;
8
+ captureContent?: KortyxTelemetryConfig["captureContent"] | undefined;
9
+ metadata?: Record<string, unknown> | undefined;
10
+ tags?: string[] | undefined;
11
+ flushIntervalMs?: number | undefined;
12
+ maxQueueSize?: number | undefined;
13
+ fetch?: typeof globalThis.fetch | undefined;
14
+ };
15
+ type KortyxTelemetryAdapter = KortyxTelemetryConfig & {
16
+ flush: () => Promise<void>;
17
+ getDroppedEventCount: () => number;
18
+ getPermanentDeliveryFailureCount: () => number;
19
+ };
20
+
21
+ /**
22
+ * Creates the optional Kortyx Studio HTTP adapter. Execution paths only enqueue
23
+ * telemetry; delivery remains best-effort and cannot fail a workflow.
24
+ */
25
+ declare function createKortyxTelemetryAdapter(options: CreateKortyxTelemetryAdapterOptions): KortyxTelemetryAdapter;
26
+
27
+ export { type CreateKortyxTelemetryAdapterOptions, type KortyxTelemetryAdapter, createKortyxTelemetryAdapter };
package/dist/index.js ADDED
@@ -0,0 +1,466 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ createKortyxTelemetryAdapter: () => createKortyxTelemetryAdapter
23
+ });
24
+ module.exports = __toCommonJS(index_exports);
25
+
26
+ // src/adapter.ts
27
+ var import_node_crypto = require("crypto");
28
+
29
+ // src/delivery.ts
30
+ var TelemetryHttpError = class extends Error {
31
+ constructor(status) {
32
+ super(`Kortyx telemetry request failed (${status}).`);
33
+ this.status = status;
34
+ }
35
+ status;
36
+ };
37
+ var createDelivery = (args) => {
38
+ const queue = [];
39
+ let dropped = 0;
40
+ let permanentFailures = 0;
41
+ let retryAttempt = 0;
42
+ let timer;
43
+ let inFlight;
44
+ const schedule = (delay = args.flushIntervalMs) => {
45
+ if (timer || inFlight || queue.length === 0) return;
46
+ timer = setTimeout(() => {
47
+ timer = void 0;
48
+ void flush();
49
+ }, delay);
50
+ if (typeof timer === "object" && "unref" in timer) timer.unref?.();
51
+ };
52
+ const flush = async () => {
53
+ if (inFlight) return inFlight;
54
+ if (timer) {
55
+ clearTimeout(timer);
56
+ timer = void 0;
57
+ }
58
+ if (queue.length === 0) return;
59
+ const events = queue.splice(0);
60
+ inFlight = (async () => {
61
+ let retry;
62
+ try {
63
+ await args.send(events);
64
+ retryAttempt = 0;
65
+ } catch (error) {
66
+ const status = error instanceof TelemetryHttpError ? error.status : void 0;
67
+ if (status !== void 0 && status !== 429 && status < 500) {
68
+ permanentFailures += events.length;
69
+ return;
70
+ }
71
+ const overflow = Math.max(
72
+ 0,
73
+ queue.length + events.length - args.maxQueueSize
74
+ );
75
+ if (overflow) {
76
+ dropped += overflow;
77
+ events.splice(0, overflow);
78
+ }
79
+ queue.unshift(...events);
80
+ retryAttempt += 1;
81
+ const backoff = Math.min(3e4, 250 * 2 ** (retryAttempt - 1));
82
+ retry = Math.floor(backoff * (0.5 + Math.random() * 0.5));
83
+ } finally {
84
+ inFlight = void 0;
85
+ if (retry !== void 0) schedule(retry);
86
+ }
87
+ })();
88
+ return inFlight;
89
+ };
90
+ return {
91
+ enqueue: (event) => {
92
+ if (queue.length >= args.maxQueueSize) {
93
+ queue.shift();
94
+ dropped += 1;
95
+ }
96
+ queue.push(event);
97
+ schedule();
98
+ },
99
+ flush,
100
+ getDroppedEventCount: () => dropped,
101
+ getPermanentDeliveryFailureCount: () => permanentFailures
102
+ };
103
+ };
104
+
105
+ // src/event-mapper.ts
106
+ var stringValue = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
107
+ var shouldCapture = (value, side) => {
108
+ if (value === true) return true;
109
+ return Boolean(value && typeof value === "object" && value[side]);
110
+ };
111
+ var asErrorPayload = (error) => ({
112
+ message: error instanceof Error ? error.message : String(error),
113
+ ...error instanceof Error && error.name ? { name: error.name } : {}
114
+ });
115
+ var correlationFrom = (attributes, active) => {
116
+ const source = attributes ?? {};
117
+ const runId = stringValue(source.runId) ?? active?.correlation.runId;
118
+ const workflowId = stringValue(source.workflowId) ?? active?.correlation.workflowId;
119
+ if (!runId || !workflowId) return void 0;
120
+ const sessionId = stringValue(source.sessionId) ?? active?.correlation.sessionId;
121
+ const workflowRevisionId = stringValue(source.workflowRevisionId) ?? active?.correlation.workflowRevisionId;
122
+ const topologyHash = stringValue(source.topologyHash) ?? active?.correlation.topologyHash;
123
+ const nodeId = stringValue(source.nodeId) ?? active?.correlation.nodeId;
124
+ return {
125
+ runId,
126
+ workflowId,
127
+ ...sessionId ? { sessionId } : {},
128
+ ...workflowRevisionId ? { workflowRevisionId } : {},
129
+ ...topologyHash ? { topologyHash } : {},
130
+ ...nodeId ? { nodeId } : {}
131
+ };
132
+ };
133
+ var createEventMapper = (args) => {
134
+ const createEvent = (input) => ({
135
+ schemaVersion: 1,
136
+ eventId: args.createId(),
137
+ occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
138
+ environment: args.environment,
139
+ service: args.service,
140
+ correlation: {
141
+ ...input.correlation,
142
+ ...input.span ? { traceId: input.span.traceId, spanId: input.span.spanId } : {},
143
+ ...input.parentSpanId ? { parentSpanId: input.parentSpanId } : {}
144
+ },
145
+ ...input.context || args.metadata || args.tags ? {
146
+ context: {
147
+ ...args.tags ? { tags: args.tags } : {},
148
+ ...args.metadata ? { metadata: args.metadata } : {},
149
+ ...input.context ?? {}
150
+ }
151
+ } : {},
152
+ type: input.type,
153
+ payload: input.payload
154
+ });
155
+ const spanContext = (telemetry, attributes) => {
156
+ const tags = [...args.tags ?? [], ...telemetry?.tags ?? []];
157
+ const metadata = {
158
+ ...args.metadata ?? {},
159
+ ...telemetry?.metadata ?? {}
160
+ };
161
+ const userId = stringValue(attributes.userId);
162
+ const tenantId = stringValue(attributes.tenantId);
163
+ return userId || tenantId || tags.length || Object.keys(metadata).length ? {
164
+ ...userId ? { userId } : {},
165
+ ...tenantId ? { tenantId } : {},
166
+ ...tags.length ? { tags } : {},
167
+ ...Object.keys(metadata).length ? { metadata } : {}
168
+ } : void 0;
169
+ };
170
+ const telemetryPayload = (telemetry) => ({
171
+ ...telemetry?.operation ? { operation: telemetry.operation } : {},
172
+ ...telemetry?.tags?.length ? { tags: telemetry.tags } : {},
173
+ ...telemetry?.metadata ? { metadata: telemetry.metadata } : {},
174
+ ...telemetry?.prompt ? {
175
+ prompt: {
176
+ ...telemetry.prompt.name ? { name: telemetry.prompt.name } : {},
177
+ ...telemetry.prompt.version !== void 0 ? { version: telemetry.prompt.version } : {},
178
+ ...telemetry.prompt.type ? { type: telemetry.prompt.type } : {},
179
+ ...telemetry.prompt.source ? { source: telemetry.prompt.source } : {}
180
+ }
181
+ } : {}
182
+ });
183
+ return {
184
+ asErrorPayload,
185
+ correlationFrom,
186
+ createEvent,
187
+ shouldCapture,
188
+ spanContext,
189
+ stringValue,
190
+ telemetryPayload
191
+ };
192
+ };
193
+
194
+ // src/topology.ts
195
+ var keyFor = ({ environment, workflowId, topologyHash }) => `${environment}:${workflowId}:${topologyHash}`;
196
+ var createTopologyResolver = (args) => {
197
+ const revisions = /* @__PURE__ */ new Map();
198
+ const pending = /* @__PURE__ */ new Map();
199
+ const ensureWorkflowTopology = (snapshot) => {
200
+ const key = keyFor({
201
+ environment: snapshot.environment,
202
+ workflowId: snapshot.workflow.id,
203
+ topologyHash: snapshot.workflow.topologyHash
204
+ });
205
+ const revision = revisions.get(key);
206
+ if (revision) {
207
+ return Promise.resolve({ workflowRevisionId: revision, created: false });
208
+ }
209
+ const existing = pending.get(key);
210
+ if (existing) return existing;
211
+ const request = args.ensure(snapshot).then((result) => {
212
+ if (!result.workflowRevisionId) {
213
+ throw new Error(
214
+ "Telemetry API returned an invalid workflow revision."
215
+ );
216
+ }
217
+ revisions.set(key, result.workflowRevisionId);
218
+ return result;
219
+ }).finally(() => {
220
+ pending.delete(key);
221
+ });
222
+ pending.set(key, request);
223
+ return request;
224
+ };
225
+ return {
226
+ ensureWorkflowTopology,
227
+ getWorkflowRevisionId: (args2) => revisions.get(keyFor(args2))
228
+ };
229
+ };
230
+
231
+ // src/trace.ts
232
+ var import_node_async_hooks = require("async_hooks");
233
+ var createTraceAdapter = (args) => {
234
+ const activeSpans = new import_node_async_hooks.AsyncLocalStorage();
235
+ const createSpan = (startArgs) => {
236
+ const parent = activeSpans.getStore();
237
+ const span = {
238
+ traceId: parent?.traceId ?? args.createId(),
239
+ spanId: args.createId()
240
+ };
241
+ const attributes = { ...startArgs.attributes ?? {} };
242
+ const currentAttributes = { ...attributes };
243
+ const correlation = args.eventMapper.correlationFrom(attributes, parent);
244
+ const startedAt = Date.now();
245
+ if (correlation) {
246
+ args.enqueue(
247
+ args.eventMapper.createEvent({
248
+ type: "span.started",
249
+ correlation,
250
+ span,
251
+ ...parent ? { parentSpanId: parent.spanId } : {},
252
+ payload: {
253
+ name: startArgs.name,
254
+ attributes: currentAttributes,
255
+ telemetry: args.eventMapper.telemetryPayload(startArgs.telemetry),
256
+ ...args.eventMapper.shouldCapture(
257
+ startArgs.telemetry?.captureContent ?? args.captureContent,
258
+ "input"
259
+ ) ? { input: startArgs.telemetry?.input } : {}
260
+ },
261
+ context: args.eventMapper.spanContext(
262
+ startArgs.telemetry,
263
+ currentAttributes
264
+ )
265
+ })
266
+ );
267
+ }
268
+ let ended = false;
269
+ const end = (endArgs) => {
270
+ if (ended) return;
271
+ ended = true;
272
+ if (!correlation) return;
273
+ const endAttributes = {
274
+ ...currentAttributes,
275
+ ...endArgs?.attributes ?? {}
276
+ };
277
+ const telemetry = endArgs?.telemetry ?? startArgs.telemetry;
278
+ args.enqueue(
279
+ args.eventMapper.createEvent({
280
+ type: "span.ended",
281
+ correlation,
282
+ span,
283
+ ...parent ? { parentSpanId: parent.spanId } : {},
284
+ payload: {
285
+ name: startArgs.name,
286
+ attributes: endAttributes,
287
+ durationMs: Date.now() - startedAt,
288
+ telemetry: args.eventMapper.telemetryPayload(telemetry),
289
+ ...args.eventMapper.shouldCapture(
290
+ endArgs?.telemetry?.captureContent ?? startArgs.telemetry?.captureContent ?? args.captureContent,
291
+ "output"
292
+ ) ? { output: endArgs?.telemetry?.output } : {}
293
+ },
294
+ context: args.eventMapper.spanContext(telemetry, endAttributes)
295
+ })
296
+ );
297
+ if (startArgs.name !== "runReasonEngine") return;
298
+ args.enqueue(
299
+ args.eventMapper.createEvent({
300
+ type: "generation.completed",
301
+ correlation,
302
+ span,
303
+ ...parent ? { parentSpanId: parent.spanId } : {},
304
+ payload: {
305
+ provider: args.eventMapper.stringValue(attributes.providerId) ?? "unknown",
306
+ model: args.eventMapper.stringValue(attributes.modelId) ?? "unknown",
307
+ ...endArgs?.usage ? { usage: endArgs.usage } : {},
308
+ ...endArgs?.finishReason ? { finishReason: endArgs.finishReason } : {},
309
+ ...endArgs?.warnings ? { warnings: endArgs.warnings } : {},
310
+ ...endArgs?.providerMetadata ? { providerMetadata: endArgs.providerMetadata } : {}
311
+ },
312
+ context: args.eventMapper.spanContext(telemetry, currentAttributes)
313
+ })
314
+ );
315
+ };
316
+ const traceSpan = {
317
+ setAttributes: (nextAttributes) => {
318
+ Object.assign(currentAttributes, nextAttributes);
319
+ },
320
+ addEvent: (name, eventAttributes = {}) => {
321
+ if (!correlation) return;
322
+ const type = name === "useReason.tool-call.start" ? "tool.started" : name === "useReason.tool-call.complete" ? "tool.completed" : name === "useReason.tool-call.error" ? "tool.failed" : void 0;
323
+ if (!type) return;
324
+ args.enqueue(
325
+ args.eventMapper.createEvent({
326
+ type,
327
+ correlation,
328
+ span,
329
+ ...parent ? { parentSpanId: parent.spanId } : {},
330
+ payload: eventAttributes
331
+ })
332
+ );
333
+ },
334
+ end,
335
+ fail: (error, endArgs) => {
336
+ if (ended) return;
337
+ if (correlation) {
338
+ args.enqueue(
339
+ args.eventMapper.createEvent({
340
+ type: "span.failed",
341
+ correlation,
342
+ span,
343
+ ...parent ? { parentSpanId: parent.spanId } : {},
344
+ payload: {
345
+ name: startArgs.name,
346
+ error: args.eventMapper.asErrorPayload(error),
347
+ durationMs: Date.now() - startedAt
348
+ }
349
+ })
350
+ );
351
+ }
352
+ end(endArgs);
353
+ }
354
+ };
355
+ return {
356
+ span: traceSpan,
357
+ ...correlation ? { active: { ...span, correlation } } : {}
358
+ };
359
+ };
360
+ return {
361
+ startSpan: (startArgs) => createSpan(startArgs).span,
362
+ withSpan: async (startArgs, fn) => {
363
+ const created = createSpan(startArgs);
364
+ const run = async () => {
365
+ try {
366
+ const result = await fn(created.span);
367
+ created.span.end?.();
368
+ return result;
369
+ } catch (error) {
370
+ created.span.fail?.(error);
371
+ throw error;
372
+ }
373
+ };
374
+ return created.active ? activeSpans.run(created.active, run) : run();
375
+ },
376
+ getActiveContext: () => {
377
+ const active = activeSpans.getStore();
378
+ return active ? { traceId: active.traceId, spanId: active.spanId } : void 0;
379
+ }
380
+ };
381
+ };
382
+
383
+ // src/adapter.ts
384
+ var DEFAULT_FLUSH_INTERVAL_MS = 250;
385
+ var DEFAULT_MAX_QUEUE_SIZE = 1e3;
386
+ var createId = () => {
387
+ try {
388
+ return (0, import_node_crypto.randomUUID)();
389
+ } catch {
390
+ return `${Date.now()}-${Math.random().toString(36).slice(2)}`;
391
+ }
392
+ };
393
+ var endpointFor = (endpoint, path) => `${endpoint.replace(/\/$/, "")}${path}`;
394
+ function createKortyxTelemetryAdapter(options) {
395
+ const fetchImpl = options.fetch ?? globalThis.fetch;
396
+ if (!fetchImpl) {
397
+ throw new Error(
398
+ "createKortyxTelemetryAdapter requires a fetch implementation."
399
+ );
400
+ }
401
+ const send = async (path, body) => {
402
+ const response = await fetchImpl(endpointFor(options.endpoint, path), {
403
+ method: "POST",
404
+ headers: {
405
+ authorization: `Bearer ${options.apiKey}`,
406
+ "content-type": "application/json"
407
+ },
408
+ body: JSON.stringify(body)
409
+ });
410
+ if (!response.ok) throw new TelemetryHttpError(response.status);
411
+ return response;
412
+ };
413
+ const delivery = createDelivery({
414
+ maxQueueSize: options.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE,
415
+ flushIntervalMs: options.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS,
416
+ send: async (events) => {
417
+ await send("/v1/telemetry/events:batch", { events });
418
+ }
419
+ });
420
+ const eventMapper = createEventMapper({
421
+ environment: options.environment,
422
+ service: options.service,
423
+ ...options.metadata ? { metadata: options.metadata } : {},
424
+ ...options.tags ? { tags: options.tags } : {},
425
+ createId
426
+ });
427
+ const topology = createTopologyResolver({
428
+ ensure: async (snapshot) => {
429
+ const response = await send(
430
+ "/v1/telemetry/workflow-revisions:ensure",
431
+ snapshot
432
+ );
433
+ return await response.json();
434
+ }
435
+ });
436
+ const trace = createTraceAdapter({
437
+ ...options.captureContent ? { captureContent: options.captureContent } : {},
438
+ createId,
439
+ enqueue: delivery.enqueue,
440
+ eventMapper
441
+ });
442
+ const emit = async (events) => {
443
+ for (const event of events) delivery.enqueue(event);
444
+ };
445
+ return {
446
+ trace,
447
+ reporter: {
448
+ ensureWorkflowTopology: topology.ensureWorkflowTopology,
449
+ emit,
450
+ getWorkflowRevisionId: topology.getWorkflowRevisionId
451
+ },
452
+ environment: options.environment,
453
+ service: options.service,
454
+ ...options.captureContent ? { captureContent: options.captureContent } : {},
455
+ ...options.metadata ? { metadata: options.metadata } : {},
456
+ ...options.tags ? { tags: options.tags } : {},
457
+ flush: delivery.flush,
458
+ getDroppedEventCount: delivery.getDroppedEventCount,
459
+ getPermanentDeliveryFailureCount: delivery.getPermanentDeliveryFailureCount
460
+ };
461
+ }
462
+ // Annotate the CommonJS export names for ESM import in node:
463
+ 0 && (module.exports = {
464
+ createKortyxTelemetryAdapter
465
+ });
466
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/adapter.ts","../src/delivery.ts","../src/event-mapper.ts","../src/topology.ts","../src/trace.ts"],"sourcesContent":["export { createKortyxTelemetryAdapter } from \"./adapter\";\nexport type {\n CreateKortyxTelemetryAdapterOptions,\n KortyxTelemetryAdapter,\n} from \"./types\";\n","import { randomUUID } from \"node:crypto\";\nimport type {\n EnsureWorkflowTopologyResponse,\n KortyxTelemetryEvent,\n} from \"@kortyx/hooks\";\nimport { createDelivery, TelemetryHttpError } from \"./delivery\";\nimport { createEventMapper } from \"./event-mapper\";\nimport { createTopologyResolver } from \"./topology\";\nimport { createTraceAdapter } from \"./trace\";\nimport type {\n CreateKortyxTelemetryAdapterOptions,\n KortyxTelemetryAdapter,\n} from \"./types\";\n\nexport type {\n CreateKortyxTelemetryAdapterOptions,\n KortyxTelemetryAdapter,\n} from \"./types\";\n\nconst DEFAULT_FLUSH_INTERVAL_MS = 250;\nconst DEFAULT_MAX_QUEUE_SIZE = 1_000;\n\nconst createId = (): string => {\n try {\n return randomUUID();\n } catch {\n return `${Date.now()}-${Math.random().toString(36).slice(2)}`;\n }\n};\n\nconst endpointFor = (endpoint: string, path: string): string =>\n `${endpoint.replace(/\\/$/, \"\")}${path}`;\n\n/**\n * Creates the optional Kortyx Studio HTTP adapter. Execution paths only enqueue\n * telemetry; delivery remains best-effort and cannot fail a workflow.\n */\nexport function createKortyxTelemetryAdapter(\n options: CreateKortyxTelemetryAdapterOptions,\n): KortyxTelemetryAdapter {\n const fetchImpl = options.fetch ?? globalThis.fetch;\n if (!fetchImpl) {\n throw new Error(\n \"createKortyxTelemetryAdapter requires a fetch implementation.\",\n );\n }\n\n const send = async (path: string, body: unknown): Promise<Response> => {\n const response = await fetchImpl(endpointFor(options.endpoint, path), {\n method: \"POST\",\n headers: {\n authorization: `Bearer ${options.apiKey}`,\n \"content-type\": \"application/json\",\n },\n body: JSON.stringify(body),\n });\n if (!response.ok) throw new TelemetryHttpError(response.status);\n return response;\n };\n\n const delivery = createDelivery({\n maxQueueSize: options.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE,\n flushIntervalMs: options.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS,\n send: async (events) => {\n await send(\"/v1/telemetry/events:batch\", { events });\n },\n });\n const eventMapper = createEventMapper({\n environment: options.environment,\n service: options.service,\n ...(options.metadata ? { metadata: options.metadata } : {}),\n ...(options.tags ? { tags: options.tags } : {}),\n createId,\n });\n const topology = createTopologyResolver({\n ensure: async (snapshot) => {\n const response = await send(\n \"/v1/telemetry/workflow-revisions:ensure\",\n snapshot,\n );\n return (await response.json()) as EnsureWorkflowTopologyResponse;\n },\n });\n const trace = createTraceAdapter({\n ...(options.captureContent\n ? { captureContent: options.captureContent }\n : {}),\n createId,\n enqueue: delivery.enqueue,\n eventMapper,\n });\n const emit = async (events: KortyxTelemetryEvent[]): Promise<void> => {\n for (const event of events) delivery.enqueue(event);\n };\n\n return {\n trace,\n reporter: {\n ensureWorkflowTopology: topology.ensureWorkflowTopology,\n emit,\n getWorkflowRevisionId: topology.getWorkflowRevisionId,\n },\n environment: options.environment,\n service: options.service,\n ...(options.captureContent\n ? { captureContent: options.captureContent }\n : {}),\n ...(options.metadata ? { metadata: options.metadata } : {}),\n ...(options.tags ? { tags: options.tags } : {}),\n flush: delivery.flush,\n getDroppedEventCount: delivery.getDroppedEventCount,\n getPermanentDeliveryFailureCount: delivery.getPermanentDeliveryFailureCount,\n };\n}\n","import type { KortyxTelemetryEvent } from \"@kortyx/hooks\";\n\nexport class TelemetryHttpError extends Error {\n constructor(readonly status: number) {\n super(`Kortyx telemetry request failed (${status}).`);\n }\n}\n\nexport const createDelivery = (args: {\n maxQueueSize: number;\n flushIntervalMs: number;\n send: (events: KortyxTelemetryEvent[]) => Promise<void>;\n}) => {\n const queue: KortyxTelemetryEvent[] = [];\n let dropped = 0;\n let permanentFailures = 0;\n let retryAttempt = 0;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let inFlight: Promise<void> | undefined;\n const schedule = (delay = args.flushIntervalMs) => {\n if (timer || inFlight || queue.length === 0) return;\n timer = setTimeout(() => {\n timer = undefined;\n void flush();\n }, delay);\n if (typeof timer === \"object\" && \"unref\" in timer) timer.unref?.();\n };\n const flush = async (): Promise<void> => {\n if (inFlight) return inFlight;\n if (timer) {\n clearTimeout(timer);\n timer = undefined;\n }\n if (queue.length === 0) return;\n const events = queue.splice(0);\n inFlight = (async () => {\n let retry: number | undefined;\n try {\n await args.send(events);\n retryAttempt = 0;\n } catch (error) {\n const status =\n error instanceof TelemetryHttpError ? error.status : undefined;\n if (status !== undefined && status !== 429 && status < 500) {\n permanentFailures += events.length;\n return;\n }\n const overflow = Math.max(\n 0,\n queue.length + events.length - args.maxQueueSize,\n );\n if (overflow) {\n dropped += overflow;\n events.splice(0, overflow);\n }\n queue.unshift(...events);\n retryAttempt += 1;\n const backoff = Math.min(30_000, 250 * 2 ** (retryAttempt - 1));\n retry = Math.floor(backoff * (0.5 + Math.random() * 0.5));\n } finally {\n inFlight = undefined;\n if (retry !== undefined) schedule(retry);\n }\n })();\n return inFlight;\n };\n return {\n enqueue: (event: KortyxTelemetryEvent) => {\n if (queue.length >= args.maxQueueSize) {\n queue.shift();\n dropped += 1;\n }\n queue.push(event);\n schedule();\n },\n flush,\n getDroppedEventCount: () => dropped,\n getPermanentDeliveryFailureCount: () => permanentFailures,\n };\n};\n","import type {\n KortyxTelemetryConfig,\n KortyxTelemetryEvent,\n KortyxTelemetryEventType,\n ReasonTraceAttributes,\n ReasonTraceSpanStartArgs,\n} from \"@kortyx/hooks\";\nimport type { ActiveSpan, SpanContext } from \"./types\";\n\nconst stringValue = (value: unknown): string | undefined =>\n typeof value === \"string\" && value.length > 0 ? value : undefined;\n\nconst shouldCapture = (\n value: KortyxTelemetryConfig[\"captureContent\"] | undefined,\n side: \"input\" | \"output\",\n): boolean => {\n if (value === true) return true;\n return Boolean(value && typeof value === \"object\" && value[side]);\n};\n\nconst asErrorPayload = (error: unknown): Record<string, unknown> => ({\n message: error instanceof Error ? error.message : String(error),\n ...(error instanceof Error && error.name ? { name: error.name } : {}),\n});\n\nconst correlationFrom = (\n attributes: ReasonTraceAttributes | undefined,\n active: ActiveSpan | undefined,\n): KortyxTelemetryEvent[\"correlation\"] | undefined => {\n const source = attributes ?? {};\n const runId = stringValue(source.runId) ?? active?.correlation.runId;\n const workflowId =\n stringValue(source.workflowId) ?? active?.correlation.workflowId;\n if (!runId || !workflowId) return undefined;\n\n const sessionId =\n stringValue(source.sessionId) ?? active?.correlation.sessionId;\n const workflowRevisionId =\n stringValue(source.workflowRevisionId) ??\n active?.correlation.workflowRevisionId;\n const topologyHash =\n stringValue(source.topologyHash) ?? active?.correlation.topologyHash;\n const nodeId = stringValue(source.nodeId) ?? active?.correlation.nodeId;\n return {\n runId,\n workflowId,\n ...(sessionId ? { sessionId } : {}),\n ...(workflowRevisionId ? { workflowRevisionId } : {}),\n ...(topologyHash ? { topologyHash } : {}),\n ...(nodeId ? { nodeId } : {}),\n };\n};\n\nexport const createEventMapper = (args: {\n environment: string;\n service: KortyxTelemetryEvent[\"service\"];\n metadata?: Record<string, unknown> | undefined;\n tags?: string[] | undefined;\n createId: () => string;\n}) => {\n const createEvent = (input: {\n type: KortyxTelemetryEventType;\n correlation: KortyxTelemetryEvent[\"correlation\"];\n span?: SpanContext | undefined;\n parentSpanId?: string | undefined;\n payload: Record<string, unknown>;\n context?: KortyxTelemetryEvent[\"context\"] | undefined;\n }): KortyxTelemetryEvent => ({\n schemaVersion: 1,\n eventId: args.createId(),\n occurredAt: new Date().toISOString(),\n environment: args.environment,\n service: args.service,\n correlation: {\n ...input.correlation,\n ...(input.span\n ? { traceId: input.span.traceId, spanId: input.span.spanId }\n : {}),\n ...(input.parentSpanId ? { parentSpanId: input.parentSpanId } : {}),\n },\n ...(input.context || args.metadata || args.tags\n ? {\n context: {\n ...(args.tags ? { tags: args.tags } : {}),\n ...(args.metadata ? { metadata: args.metadata } : {}),\n ...(input.context ?? {}),\n },\n }\n : {}),\n type: input.type,\n payload: input.payload,\n });\n\n const spanContext = (\n telemetry: ReasonTraceSpanStartArgs[\"telemetry\"] | undefined,\n attributes: ReasonTraceAttributes,\n ): KortyxTelemetryEvent[\"context\"] | undefined => {\n const tags = [...(args.tags ?? []), ...(telemetry?.tags ?? [])];\n const metadata = {\n ...(args.metadata ?? {}),\n ...(telemetry?.metadata ?? {}),\n };\n const userId = stringValue(attributes.userId);\n const tenantId = stringValue(attributes.tenantId);\n return userId || tenantId || tags.length || Object.keys(metadata).length\n ? {\n ...(userId ? { userId } : {}),\n ...(tenantId ? { tenantId } : {}),\n ...(tags.length ? { tags } : {}),\n ...(Object.keys(metadata).length ? { metadata } : {}),\n }\n : undefined;\n };\n\n const telemetryPayload = (\n telemetry: ReasonTraceSpanStartArgs[\"telemetry\"] | undefined,\n ): Record<string, unknown> => ({\n ...(telemetry?.operation ? { operation: telemetry.operation } : {}),\n ...(telemetry?.tags?.length ? { tags: telemetry.tags } : {}),\n ...(telemetry?.metadata ? { metadata: telemetry.metadata } : {}),\n ...(telemetry?.prompt\n ? {\n prompt: {\n ...(telemetry.prompt.name ? { name: telemetry.prompt.name } : {}),\n ...(telemetry.prompt.version !== undefined\n ? { version: telemetry.prompt.version }\n : {}),\n ...(telemetry.prompt.type ? { type: telemetry.prompt.type } : {}),\n ...(telemetry.prompt.source\n ? { source: telemetry.prompt.source }\n : {}),\n },\n }\n : {}),\n });\n\n return {\n asErrorPayload,\n correlationFrom,\n createEvent,\n shouldCapture,\n spanContext,\n stringValue,\n telemetryPayload,\n };\n};\n","import type {\n EnsureWorkflowTopologyRequest,\n EnsureWorkflowTopologyResponse,\n} from \"@kortyx/hooks\";\n\ntype TopologyKey = {\n environment: string;\n workflowId: string;\n topologyHash: string;\n};\n\nconst keyFor = ({ environment, workflowId, topologyHash }: TopologyKey) =>\n `${environment}:${workflowId}:${topologyHash}`;\n\n/** Caches successful topology ensures and coalesces concurrent requests. */\nexport const createTopologyResolver = (args: {\n ensure: (\n snapshot: EnsureWorkflowTopologyRequest,\n ) => Promise<EnsureWorkflowTopologyResponse>;\n}) => {\n const revisions = new Map<string, string>();\n const pending = new Map<string, Promise<EnsureWorkflowTopologyResponse>>();\n\n const ensureWorkflowTopology = (\n snapshot: EnsureWorkflowTopologyRequest,\n ): Promise<EnsureWorkflowTopologyResponse> => {\n const key = keyFor({\n environment: snapshot.environment,\n workflowId: snapshot.workflow.id,\n topologyHash: snapshot.workflow.topologyHash,\n });\n const revision = revisions.get(key);\n if (revision) {\n return Promise.resolve({ workflowRevisionId: revision, created: false });\n }\n\n const existing = pending.get(key);\n if (existing) return existing;\n\n const request = args\n .ensure(snapshot)\n .then((result) => {\n if (!result.workflowRevisionId) {\n throw new Error(\n \"Telemetry API returned an invalid workflow revision.\",\n );\n }\n revisions.set(key, result.workflowRevisionId);\n return result;\n })\n .finally(() => {\n pending.delete(key);\n });\n pending.set(key, request);\n return request;\n };\n\n return {\n ensureWorkflowTopology,\n getWorkflowRevisionId: (args: TopologyKey) => revisions.get(keyFor(args)),\n };\n};\n","import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type {\n KortyxTelemetryConfig,\n KortyxTelemetryEvent,\n ReasonTraceAdapter,\n ReasonTraceSpan,\n ReasonTraceSpanEndArgs,\n ReasonTraceSpanStartArgs,\n} from \"@kortyx/hooks\";\nimport type { createEventMapper } from \"./event-mapper\";\nimport type { ActiveSpan, SpanContext } from \"./types\";\n\n/** Maps generic SDK trace calls to Kortyx Studio's span and generation facts. */\nexport const createTraceAdapter = (args: {\n captureContent?: KortyxTelemetryConfig[\"captureContent\"] | undefined;\n createId: () => string;\n enqueue: (event: KortyxTelemetryEvent) => void;\n eventMapper: ReturnType<typeof createEventMapper>;\n}): ReasonTraceAdapter => {\n const activeSpans = new AsyncLocalStorage<ActiveSpan>();\n\n const createSpan = (\n startArgs: ReasonTraceSpanStartArgs,\n ): { span: ReasonTraceSpan; active?: ActiveSpan | undefined } => {\n const parent = activeSpans.getStore();\n const span: SpanContext = {\n traceId: parent?.traceId ?? args.createId(),\n spanId: args.createId(),\n };\n const attributes = { ...(startArgs.attributes ?? {}) };\n const currentAttributes = { ...attributes };\n const correlation = args.eventMapper.correlationFrom(attributes, parent);\n const startedAt = Date.now();\n\n if (correlation) {\n args.enqueue(\n args.eventMapper.createEvent({\n type: \"span.started\",\n correlation,\n span,\n ...(parent ? { parentSpanId: parent.spanId } : {}),\n payload: {\n name: startArgs.name,\n attributes: currentAttributes,\n telemetry: args.eventMapper.telemetryPayload(startArgs.telemetry),\n ...(args.eventMapper.shouldCapture(\n startArgs.telemetry?.captureContent ?? args.captureContent,\n \"input\",\n )\n ? { input: startArgs.telemetry?.input }\n : {}),\n },\n context: args.eventMapper.spanContext(\n startArgs.telemetry,\n currentAttributes,\n ),\n }),\n );\n }\n\n let ended = false;\n const end = (endArgs?: ReasonTraceSpanEndArgs): void => {\n if (ended) return;\n ended = true;\n if (!correlation) return;\n\n const endAttributes = {\n ...currentAttributes,\n ...(endArgs?.attributes ?? {}),\n };\n const telemetry = endArgs?.telemetry ?? startArgs.telemetry;\n args.enqueue(\n args.eventMapper.createEvent({\n type: \"span.ended\",\n correlation,\n span,\n ...(parent ? { parentSpanId: parent.spanId } : {}),\n payload: {\n name: startArgs.name,\n attributes: endAttributes,\n durationMs: Date.now() - startedAt,\n telemetry: args.eventMapper.telemetryPayload(telemetry),\n ...(args.eventMapper.shouldCapture(\n endArgs?.telemetry?.captureContent ??\n startArgs.telemetry?.captureContent ??\n args.captureContent,\n \"output\",\n )\n ? { output: endArgs?.telemetry?.output }\n : {}),\n },\n context: args.eventMapper.spanContext(telemetry, endAttributes),\n }),\n );\n\n if (startArgs.name !== \"runReasonEngine\") return;\n args.enqueue(\n args.eventMapper.createEvent({\n type: \"generation.completed\",\n correlation,\n span,\n ...(parent ? { parentSpanId: parent.spanId } : {}),\n payload: {\n provider:\n args.eventMapper.stringValue(attributes.providerId) ?? \"unknown\",\n model:\n args.eventMapper.stringValue(attributes.modelId) ?? \"unknown\",\n ...(endArgs?.usage ? { usage: endArgs.usage } : {}),\n ...(endArgs?.finishReason\n ? { finishReason: endArgs.finishReason }\n : {}),\n ...(endArgs?.warnings ? { warnings: endArgs.warnings } : {}),\n ...(endArgs?.providerMetadata\n ? { providerMetadata: endArgs.providerMetadata }\n : {}),\n },\n context: args.eventMapper.spanContext(telemetry, currentAttributes),\n }),\n );\n };\n\n const traceSpan: ReasonTraceSpan = {\n setAttributes: (nextAttributes) => {\n Object.assign(currentAttributes, nextAttributes);\n },\n addEvent: (name, eventAttributes = {}) => {\n if (!correlation) return;\n const type =\n name === \"useReason.tool-call.start\"\n ? \"tool.started\"\n : name === \"useReason.tool-call.complete\"\n ? \"tool.completed\"\n : name === \"useReason.tool-call.error\"\n ? \"tool.failed\"\n : undefined;\n if (!type) return;\n args.enqueue(\n args.eventMapper.createEvent({\n type,\n correlation,\n span,\n ...(parent ? { parentSpanId: parent.spanId } : {}),\n payload: eventAttributes,\n }),\n );\n },\n end,\n fail: (error, endArgs) => {\n if (ended) return;\n if (correlation) {\n args.enqueue(\n args.eventMapper.createEvent({\n type: \"span.failed\",\n correlation,\n span,\n ...(parent ? { parentSpanId: parent.spanId } : {}),\n payload: {\n name: startArgs.name,\n error: args.eventMapper.asErrorPayload(error),\n durationMs: Date.now() - startedAt,\n },\n }),\n );\n }\n end(endArgs);\n },\n };\n\n return {\n span: traceSpan,\n ...(correlation ? { active: { ...span, correlation } } : {}),\n };\n };\n\n return {\n startSpan: (startArgs) => createSpan(startArgs).span,\n withSpan: async (startArgs, fn) => {\n const created = createSpan(startArgs);\n const run = async (): Promise<Awaited<ReturnType<typeof fn>>> => {\n try {\n const result = await fn(created.span);\n created.span.end?.();\n return result;\n } catch (error) {\n created.span.fail?.(error);\n throw error;\n }\n };\n return created.active ? activeSpans.run(created.active, run) : run();\n },\n getActiveContext: () => {\n const active = activeSpans.getStore();\n return active\n ? { traceId: active.traceId, spanId: active.spanId }\n : undefined;\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,yBAA2B;;;ACEpB,IAAM,qBAAN,cAAiC,MAAM;AAAA,EAC5C,YAAqB,QAAgB;AACnC,UAAM,oCAAoC,MAAM,IAAI;AADjC;AAAA,EAErB;AAAA,EAFqB;AAGvB;AAEO,IAAM,iBAAiB,CAAC,SAIzB;AACJ,QAAM,QAAgC,CAAC;AACvC,MAAI,UAAU;AACd,MAAI,oBAAoB;AACxB,MAAI,eAAe;AACnB,MAAI;AACJ,MAAI;AACJ,QAAM,WAAW,CAAC,QAAQ,KAAK,oBAAoB;AACjD,QAAI,SAAS,YAAY,MAAM,WAAW,EAAG;AAC7C,YAAQ,WAAW,MAAM;AACvB,cAAQ;AACR,WAAK,MAAM;AAAA,IACb,GAAG,KAAK;AACR,QAAI,OAAO,UAAU,YAAY,WAAW,MAAO,OAAM,QAAQ;AAAA,EACnE;AACA,QAAM,QAAQ,YAA2B;AACvC,QAAI,SAAU,QAAO;A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AAgB,QAAQ,eAAe,IACzC,CAAC;AAAA,IACL,GAAI,QAAQ,WAAW,EAAE,UAAU,QAAQ,SAAS,IAAI,CAAC;AAAA,IACzD,GAAI,QAAQ,OAAO,EAAE,MAAM,QAAQ,KAAK,IAAI,CAAC;AAAA,IAC7C,OAAO,SAAS;AAAA,IAChB,sBAAsB,SAAS;AAAA,IAC/B,kCAAkC,SAAS;AAAA,EAC7C;AACF;","names":["args"]}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@kortyx/telemetry",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "description": "Kortyx Studio telemetry HTTP adapter.",
6
+ "license": "Apache-2.0",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist/**",
17
+ "README.md",
18
+ "CHANGELOG.md"
19
+ ],
20
+ "dependencies": {
21
+ "@kortyx/hooks": "0.17.1",
22
+ "@kortyx/telemetry-contracts": "0.1.0"
23
+ },
24
+ "devDependencies": {
25
+ "tsup": "^8.5.1",
26
+ "turbo": "2.6.1",
27
+ "typescript": "5.9.3",
28
+ "vitest": "^4.1.5"
29
+ },
30
+ "sideEffects": false,
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/kortyx-io/kortyx.git",
34
+ "directory": "packages/telemetry"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup",
41
+ "dev": "tsc --watch",
42
+ "lint": "biome check src test",
43
+ "test": "vitest run && pnpm -s type-check",
44
+ "type-check": "tsc --noEmit -p tsconfig.test.json"
45
+ }
46
+ }