@a5c-ai/genty-runtime 5.1.1-staging.583e3d9a6ed7
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/README.md +69 -0
- package/dist/apiResult.d.ts +19 -0
- package/dist/apiResult.d.ts.map +1 -0
- package/dist/apiResult.js +16 -0
- package/dist/background/state.d.ts +20 -0
- package/dist/background/state.d.ts.map +1 -0
- package/dist/background/state.js +52 -0
- package/dist/backgroundProcessRegistry.d.ts +124 -0
- package/dist/backgroundProcessRegistry.d.ts.map +1 -0
- package/dist/backgroundProcessRegistry.js +427 -0
- package/dist/cost/claudeCodeParser.d.ts +81 -0
- package/dist/cost/claudeCodeParser.d.ts.map +1 -0
- package/dist/cost/claudeCodeParser.js +232 -0
- package/dist/cost/collector.d.ts +42 -0
- package/dist/cost/collector.d.ts.map +1 -0
- package/dist/cost/collector.js +105 -0
- package/dist/cost/effectCost.d.ts +23 -0
- package/dist/cost/effectCost.d.ts.map +1 -0
- package/dist/cost/effectCost.js +26 -0
- package/dist/cost/index.d.ts +19 -0
- package/dist/cost/index.d.ts.map +1 -0
- package/dist/cost/index.js +39 -0
- package/dist/cost/journal.d.ts +40 -0
- package/dist/cost/journal.d.ts.map +1 -0
- package/dist/cost/journal.js +137 -0
- package/dist/cost/types.d.ts +164 -0
- package/dist/cost/types.d.ts.map +1 -0
- package/dist/cost/types.js +228 -0
- package/dist/daemon/automationExecutor.d.ts +16 -0
- package/dist/daemon/automationExecutor.d.ts.map +1 -0
- package/dist/daemon/automationExecutor.js +222 -0
- package/dist/daemon/config.d.ts +8 -0
- package/dist/daemon/config.d.ts.map +1 -0
- package/dist/daemon/config.js +245 -0
- package/dist/daemon/daemonLog.d.ts +30 -0
- package/dist/daemon/daemonLog.d.ts.map +1 -0
- package/dist/daemon/daemonLog.js +140 -0
- package/dist/daemon/durableQueue.d.ts +41 -0
- package/dist/daemon/durableQueue.d.ts.map +1 -0
- package/dist/daemon/durableQueue.js +183 -0
- package/dist/daemon/fileWatcher.d.ts +9 -0
- package/dist/daemon/fileWatcher.d.ts.map +1 -0
- package/dist/daemon/fileWatcher.js +144 -0
- package/dist/daemon/index.d.ts +15 -0
- package/dist/daemon/index.d.ts.map +1 -0
- package/dist/daemon/index.js +25 -0
- package/dist/daemon/lifecycle.d.ts +13 -0
- package/dist/daemon/lifecycle.d.ts.map +1 -0
- package/dist/daemon/lifecycle.js +320 -0
- package/dist/daemon/loop.d.ts +27 -0
- package/dist/daemon/loop.d.ts.map +1 -0
- package/dist/daemon/loop.js +387 -0
- package/dist/daemon/timerScheduler.d.ts +13 -0
- package/dist/daemon/timerScheduler.d.ts.map +1 -0
- package/dist/daemon/timerScheduler.js +212 -0
- package/dist/daemon/types.d.ts +122 -0
- package/dist/daemon/types.d.ts.map +1 -0
- package/dist/daemon/types.js +25 -0
- package/dist/daemon/webhookListener.d.ts +6 -0
- package/dist/daemon/webhookListener.d.ts.map +1 -0
- package/dist/daemon/webhookListener.js +132 -0
- package/dist/execution/index.d.ts +10 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +20 -0
- package/dist/execution/modes/docker.d.ts +26 -0
- package/dist/execution/modes/docker.d.ts.map +1 -0
- package/dist/execution/modes/docker.js +183 -0
- package/dist/execution/modes/index.d.ts +10 -0
- package/dist/execution/modes/index.d.ts.map +1 -0
- package/dist/execution/modes/index.js +14 -0
- package/dist/execution/modes/kubernetes.d.ts +46 -0
- package/dist/execution/modes/kubernetes.d.ts.map +1 -0
- package/dist/execution/modes/kubernetes.js +334 -0
- package/dist/execution/modes/local.d.ts +23 -0
- package/dist/execution/modes/local.d.ts.map +1 -0
- package/dist/execution/modes/local.js +117 -0
- package/dist/execution/modes/ssh.d.ts +23 -0
- package/dist/execution/modes/ssh.d.ts.map +1 -0
- package/dist/execution/modes/ssh.js +144 -0
- package/dist/execution/policy.d.ts +15 -0
- package/dist/execution/policy.d.ts.map +1 -0
- package/dist/execution/policy.js +121 -0
- package/dist/execution/provider.d.ts +32 -0
- package/dist/execution/provider.d.ts.map +1 -0
- package/dist/execution/provider.js +90 -0
- package/dist/execution/types.d.ts +189 -0
- package/dist/execution/types.d.ts.map +1 -0
- package/dist/execution/types.js +9 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/observability/diagnostics.d.ts +25 -0
- package/dist/observability/diagnostics.d.ts.map +1 -0
- package/dist/observability/diagnostics.js +98 -0
- package/dist/observability/health.d.ts +19 -0
- package/dist/observability/health.d.ts.map +1 -0
- package/dist/observability/health.js +145 -0
- package/dist/observability/index.d.ts +7 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +25 -0
- package/dist/observability/runStatus.d.ts +44 -0
- package/dist/observability/runStatus.d.ts.map +1 -0
- package/dist/observability/runStatus.js +169 -0
- package/dist/observability/timeline.d.ts +11 -0
- package/dist/observability/timeline.d.ts.map +1 -0
- package/dist/observability/timeline.js +176 -0
- package/dist/observability/types.d.ts +65 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability/types.js +8 -0
- package/dist/observability/webhooks.d.ts +68 -0
- package/dist/observability/webhooks.d.ts.map +1 -0
- package/dist/observability/webhooks.js +132 -0
- package/dist/resources/budget-tracker.d.ts +56 -0
- package/dist/resources/budget-tracker.d.ts.map +1 -0
- package/dist/resources/budget-tracker.js +131 -0
- package/dist/resources/concurrency-guard.d.ts +55 -0
- package/dist/resources/concurrency-guard.d.ts.map +1 -0
- package/dist/resources/concurrency-guard.js +132 -0
- package/dist/resources/index.d.ts +12 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +20 -0
- package/dist/resources/manager.d.ts +52 -0
- package/dist/resources/manager.d.ts.map +1 -0
- package/dist/resources/manager.js +150 -0
- package/dist/resources/timeout-cascade.d.ts +56 -0
- package/dist/resources/timeout-cascade.d.ts.map +1 -0
- package/dist/resources/timeout-cascade.js +145 -0
- package/dist/resources/types.d.ts +130 -0
- package/dist/resources/types.d.ts.map +1 -0
- package/dist/resources/types.js +9 -0
- package/dist/session/context.d.ts +22 -0
- package/dist/session/context.d.ts.map +1 -0
- package/dist/session/context.js +113 -0
- package/dist/session/continuityState.d.ts +39 -0
- package/dist/session/continuityState.d.ts.map +1 -0
- package/dist/session/continuityState.js +164 -0
- package/dist/session/cost.d.ts +63 -0
- package/dist/session/cost.d.ts.map +1 -0
- package/dist/session/cost.js +194 -0
- package/dist/session/discovery.d.ts +22 -0
- package/dist/session/discovery.d.ts.map +1 -0
- package/dist/session/discovery.js +35 -0
- package/dist/session/history.d.ts +30 -0
- package/dist/session/history.d.ts.map +1 -0
- package/dist/session/history.js +143 -0
- package/dist/session/index.d.ts +20 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +78 -0
- package/dist/session/memoryExtraction.d.ts +65 -0
- package/dist/session/memoryExtraction.d.ts.map +1 -0
- package/dist/session/memoryExtraction.js +201 -0
- package/dist/session/parse.d.ts +45 -0
- package/dist/session/parse.d.ts.map +1 -0
- package/dist/session/parse.js +170 -0
- package/dist/session/persistence.d.ts +46 -0
- package/dist/session/persistence.d.ts.map +1 -0
- package/dist/session/persistence.js +180 -0
- package/dist/session/types.d.ts +267 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +45 -0
- package/dist/session/write.d.ts +61 -0
- package/dist/session/write.d.ts.map +1 -0
- package/dist/session/write.js +213 -0
- package/dist/shellInvocation.d.ts +6 -0
- package/dist/shellInvocation.d.ts.map +1 -0
- package/dist/shellInvocation.js +8 -0
- package/dist/shellInvocation.test.d.ts +2 -0
- package/dist/shellInvocation.test.d.ts.map +1 -0
- package/dist/shellInvocation.test.js +18 -0
- package/dist/telemetry/audit-log.d.ts +56 -0
- package/dist/telemetry/audit-log.d.ts.map +1 -0
- package/dist/telemetry/audit-log.js +59 -0
- package/dist/telemetry/exporters.d.ts +35 -0
- package/dist/telemetry/exporters.d.ts.map +1 -0
- package/dist/telemetry/exporters.js +141 -0
- package/dist/telemetry/index.d.ts +12 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +25 -0
- package/dist/telemetry/provider.d.ts +57 -0
- package/dist/telemetry/provider.d.ts.map +1 -0
- package/dist/telemetry/provider.js +261 -0
- package/dist/telemetry/span-tree.d.ts +46 -0
- package/dist/telemetry/span-tree.d.ts.map +1 -0
- package/dist/telemetry/span-tree.js +93 -0
- package/dist/telemetry/traceContext.d.ts +10 -0
- package/dist/telemetry/traceContext.d.ts.map +1 -0
- package/dist/telemetry/traceContext.js +43 -0
- package/dist/telemetry/types.d.ts +109 -0
- package/dist/telemetry/types.d.ts.map +1 -0
- package/dist/telemetry/types.js +21 -0
- package/package.json +98 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telemetry module — OpenTelemetry-aligned structured telemetry interfaces
|
|
3
|
+
* and in-memory implementations.
|
|
4
|
+
*/
|
|
5
|
+
export { TelemetrySpanStatus, type TelemetryEvent, type TelemetrySpan, type TelemetryProvider, type TelemetryExporter, type TelemetryConfig, type TraceContext, type TelemetrySpanStartOptions, type TelemetryExportResult, } from "./types";
|
|
6
|
+
export { HttpTelemetryExporter, InMemoryTelemetryProvider, } from "./provider";
|
|
7
|
+
export type { HttpTelemetrySend, InMemoryTelemetryProviderOptions, } from "./provider";
|
|
8
|
+
export { AuditLog, type AuditEntry, type AuditFilter, } from "./audit-log";
|
|
9
|
+
export { SpanTree, type SpanTreeNode, type SerializedSpanTreeNode, } from "./span-tree";
|
|
10
|
+
export { createTraceContext, parseTraceParent, serializeTraceParent, type CreateTraceContextOptions, } from "./traceContext";
|
|
11
|
+
export { FileTelemetryExporter, InMemoryTelemetryExporter, NoopTelemetryExporter, OtlpHttpTraceExporter, type OtlpHttpTraceExporterOptions, } from "./exporters";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/telemetry/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,mBAAmB,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,GAC3B,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,iBAAiB,EACjB,gCAAgC,GACjC,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,QAAQ,EACR,KAAK,UAAU,EACf,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,QAAQ,EACR,KAAK,YAAY,EACjB,KAAK,sBAAsB,GAC5B,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,yBAAyB,GAC/B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,KAAK,4BAA4B,GAClC,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OtlpHttpTraceExporter = exports.NoopTelemetryExporter = exports.InMemoryTelemetryExporter = exports.FileTelemetryExporter = exports.serializeTraceParent = exports.parseTraceParent = exports.createTraceContext = exports.SpanTree = exports.AuditLog = exports.InMemoryTelemetryProvider = exports.HttpTelemetryExporter = exports.TelemetrySpanStatus = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Telemetry module — OpenTelemetry-aligned structured telemetry interfaces
|
|
6
|
+
* and in-memory implementations.
|
|
7
|
+
*/
|
|
8
|
+
var types_1 = require("./types");
|
|
9
|
+
Object.defineProperty(exports, "TelemetrySpanStatus", { enumerable: true, get: function () { return types_1.TelemetrySpanStatus; } });
|
|
10
|
+
var provider_1 = require("./provider");
|
|
11
|
+
Object.defineProperty(exports, "HttpTelemetryExporter", { enumerable: true, get: function () { return provider_1.HttpTelemetryExporter; } });
|
|
12
|
+
Object.defineProperty(exports, "InMemoryTelemetryProvider", { enumerable: true, get: function () { return provider_1.InMemoryTelemetryProvider; } });
|
|
13
|
+
var audit_log_1 = require("./audit-log");
|
|
14
|
+
Object.defineProperty(exports, "AuditLog", { enumerable: true, get: function () { return audit_log_1.AuditLog; } });
|
|
15
|
+
var span_tree_1 = require("./span-tree");
|
|
16
|
+
Object.defineProperty(exports, "SpanTree", { enumerable: true, get: function () { return span_tree_1.SpanTree; } });
|
|
17
|
+
var traceContext_1 = require("./traceContext");
|
|
18
|
+
Object.defineProperty(exports, "createTraceContext", { enumerable: true, get: function () { return traceContext_1.createTraceContext; } });
|
|
19
|
+
Object.defineProperty(exports, "parseTraceParent", { enumerable: true, get: function () { return traceContext_1.parseTraceParent; } });
|
|
20
|
+
Object.defineProperty(exports, "serializeTraceParent", { enumerable: true, get: function () { return traceContext_1.serializeTraceParent; } });
|
|
21
|
+
var exporters_1 = require("./exporters");
|
|
22
|
+
Object.defineProperty(exports, "FileTelemetryExporter", { enumerable: true, get: function () { return exporters_1.FileTelemetryExporter; } });
|
|
23
|
+
Object.defineProperty(exports, "InMemoryTelemetryExporter", { enumerable: true, get: function () { return exporters_1.InMemoryTelemetryExporter; } });
|
|
24
|
+
Object.defineProperty(exports, "NoopTelemetryExporter", { enumerable: true, get: function () { return exporters_1.NoopTelemetryExporter; } });
|
|
25
|
+
Object.defineProperty(exports, "OtlpHttpTraceExporter", { enumerable: true, get: function () { return exporters_1.OtlpHttpTraceExporter; } });
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InMemoryTelemetryProvider — in-process telemetry backend for development,
|
|
3
|
+
* testing, and single-process agent runtimes.
|
|
4
|
+
*
|
|
5
|
+
* Stores spans in memory and supports flush/drain for export pipelines.
|
|
6
|
+
*/
|
|
7
|
+
import type { TelemetryExporter, TelemetryExportResult, TelemetryProvider, TelemetrySpan, TelemetryEvent, TelemetrySpanStartOptions } from "./types";
|
|
8
|
+
import { TelemetrySpanStatus } from "./types";
|
|
9
|
+
export interface InMemoryTelemetryProviderOptions {
|
|
10
|
+
exporters?: TelemetryExporter[];
|
|
11
|
+
}
|
|
12
|
+
export declare class FileTelemetryExporter implements TelemetryExporter {
|
|
13
|
+
private readonly filePath;
|
|
14
|
+
constructor(filePath: string);
|
|
15
|
+
export(spans: readonly TelemetrySpan[]): Promise<TelemetryExportResult>;
|
|
16
|
+
}
|
|
17
|
+
export type HttpTelemetrySend = (url: string, payload: unknown) => Promise<void>;
|
|
18
|
+
export declare class HttpTelemetryExporter implements TelemetryExporter {
|
|
19
|
+
private readonly url;
|
|
20
|
+
private readonly send;
|
|
21
|
+
constructor(url: string, send?: HttpTelemetrySend);
|
|
22
|
+
export(spans: readonly TelemetrySpan[]): Promise<TelemetryExportResult>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* In-memory telemetry provider that satisfies the TelemetryProvider interface.
|
|
26
|
+
*
|
|
27
|
+
* - `startSpan` creates a new span and tracks it as active.
|
|
28
|
+
* - `endSpan` marks a span as completed and moves it to the completed set.
|
|
29
|
+
* - `recordEvent` appends a discrete event to an active span.
|
|
30
|
+
* - `flush` returns all completed spans and clears the completed buffer.
|
|
31
|
+
* - `getActiveSpans` returns all currently open (un-ended) spans.
|
|
32
|
+
*/
|
|
33
|
+
export declare class InMemoryTelemetryProvider implements TelemetryProvider {
|
|
34
|
+
/** Active (in-flight) spans keyed by spanId. */
|
|
35
|
+
private readonly active;
|
|
36
|
+
/** Completed spans awaiting flush. */
|
|
37
|
+
private readonly completed;
|
|
38
|
+
/** Maps spanId -> traceId so child spans inherit the parent's trace. */
|
|
39
|
+
private readonly traceIndex;
|
|
40
|
+
private readonly exporters;
|
|
41
|
+
constructor(options?: InMemoryTelemetryProviderOptions);
|
|
42
|
+
startSpan(name: string, parentSpanId?: string): Promise<TelemetrySpan>;
|
|
43
|
+
startSpan(name: string, options?: TelemetrySpanStartOptions): Promise<TelemetrySpan>;
|
|
44
|
+
endSpan(spanId: string, status?: TelemetrySpanStatus): Promise<void>;
|
|
45
|
+
recordEvent(spanId: string, event: TelemetryEvent): Promise<void>;
|
|
46
|
+
flush(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Drain completed spans — returns and clears the completed buffer.
|
|
49
|
+
*
|
|
50
|
+
* Unlike `flush()` (which satisfies the TelemetryProvider interface and
|
|
51
|
+
* returns void), this method hands the span data back to the caller.
|
|
52
|
+
*/
|
|
53
|
+
drain(): Promise<TelemetrySpan[]>;
|
|
54
|
+
/** Return a snapshot of all currently open (un-ended) spans. */
|
|
55
|
+
getActiveSpans(): TelemetrySpan[];
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/telemetry/provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAoB9C,MAAM,WAAW,gCAAgC;IAC/C,SAAS,CAAC,EAAE,iBAAiB,EAAE,CAAC;CACjC;AAED,qBAAa,qBAAsB,YAAW,iBAAiB;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,MAAM;IAEvC,MAAM,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAO9E;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEjF,qBAAa,qBAAsB,YAAW,iBAAiB;IAE3D,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBADJ,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,iBAAmC;IAGtD,MAAM,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAK9E;AAaD;;;;;;;;GAQG;AACH,qBAAa,yBAA0B,YAAW,iBAAiB;IACjE,gDAAgD;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;IACzD,sCAAsC;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAC/C,wEAAwE;IACxE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6B;IACxD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;gBAEpC,OAAO,CAAC,EAAE,gCAAgC;IAMhD,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IACtE,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC,aAAa,CAAC;IA2CpF,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAapE,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IASjE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAMvC,gEAAgE;IAChE,cAAc,IAAI,aAAa,EAAE;CAGlC"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* InMemoryTelemetryProvider — in-process telemetry backend for development,
|
|
4
|
+
* testing, and single-process agent runtimes.
|
|
5
|
+
*
|
|
6
|
+
* Stores spans in memory and supports flush/drain for export pipelines.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.InMemoryTelemetryProvider = exports.HttpTelemetryExporter = exports.FileTelemetryExporter = void 0;
|
|
43
|
+
const node_crypto_1 = require("node:crypto");
|
|
44
|
+
const node_fs_1 = require("node:fs");
|
|
45
|
+
const path = __importStar(require("node:path"));
|
|
46
|
+
const types_1 = require("./types");
|
|
47
|
+
class FileTelemetryExporter {
|
|
48
|
+
filePath;
|
|
49
|
+
constructor(filePath) {
|
|
50
|
+
this.filePath = filePath;
|
|
51
|
+
}
|
|
52
|
+
async export(spans) {
|
|
53
|
+
if (spans.length === 0)
|
|
54
|
+
return { ok: true, exported: 0 };
|
|
55
|
+
await node_fs_1.promises.mkdir(path.dirname(this.filePath), { recursive: true });
|
|
56
|
+
const payload = spans.map((span) => JSON.stringify(redactSpan(span))).join("\n") + "\n";
|
|
57
|
+
await node_fs_1.promises.appendFile(this.filePath, payload, "utf-8");
|
|
58
|
+
return { ok: true, exported: spans.length };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.FileTelemetryExporter = FileTelemetryExporter;
|
|
62
|
+
class HttpTelemetryExporter {
|
|
63
|
+
url;
|
|
64
|
+
send;
|
|
65
|
+
constructor(url, send = defaultHttpSend) {
|
|
66
|
+
this.url = url;
|
|
67
|
+
this.send = send;
|
|
68
|
+
}
|
|
69
|
+
async export(spans) {
|
|
70
|
+
if (spans.length === 0)
|
|
71
|
+
return { ok: true, exported: 0 };
|
|
72
|
+
await this.send(this.url, toOtlpPayload(spans.map(redactSpan)));
|
|
73
|
+
return { ok: true, exported: spans.length };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.HttpTelemetryExporter = HttpTelemetryExporter;
|
|
77
|
+
function toReadonly(span) {
|
|
78
|
+
return {
|
|
79
|
+
...span,
|
|
80
|
+
attributes: { ...span.attributes },
|
|
81
|
+
events: span.events.map((event) => ({
|
|
82
|
+
...event,
|
|
83
|
+
attributes: event.attributes ? { ...event.attributes } : undefined,
|
|
84
|
+
})),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* In-memory telemetry provider that satisfies the TelemetryProvider interface.
|
|
89
|
+
*
|
|
90
|
+
* - `startSpan` creates a new span and tracks it as active.
|
|
91
|
+
* - `endSpan` marks a span as completed and moves it to the completed set.
|
|
92
|
+
* - `recordEvent` appends a discrete event to an active span.
|
|
93
|
+
* - `flush` returns all completed spans and clears the completed buffer.
|
|
94
|
+
* - `getActiveSpans` returns all currently open (un-ended) spans.
|
|
95
|
+
*/
|
|
96
|
+
class InMemoryTelemetryProvider {
|
|
97
|
+
/** Active (in-flight) spans keyed by spanId. */
|
|
98
|
+
active = new Map();
|
|
99
|
+
/** Completed spans awaiting flush. */
|
|
100
|
+
completed = [];
|
|
101
|
+
/** Maps spanId -> traceId so child spans inherit the parent's trace. */
|
|
102
|
+
traceIndex = new Map();
|
|
103
|
+
exporters;
|
|
104
|
+
constructor(options) {
|
|
105
|
+
this.exporters = options?.exporters ?? [];
|
|
106
|
+
}
|
|
107
|
+
async startSpan(name, optionsOrParentSpanId) {
|
|
108
|
+
const spanId = (0, node_crypto_1.randomUUID)();
|
|
109
|
+
const options = typeof optionsOrParentSpanId === "string"
|
|
110
|
+
? { parentSpanId: optionsOrParentSpanId }
|
|
111
|
+
: optionsOrParentSpanId;
|
|
112
|
+
const parentSpanId = options?.traceContext?.spanId ?? options?.parentSpanId;
|
|
113
|
+
let traceId;
|
|
114
|
+
if (options?.traceContext) {
|
|
115
|
+
traceId = options.traceContext.traceId;
|
|
116
|
+
}
|
|
117
|
+
else if (parentSpanId) {
|
|
118
|
+
// Inherit traceId from the parent span.
|
|
119
|
+
traceId = this.traceIndex.get(parentSpanId) ?? (0, node_crypto_1.randomUUID)();
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
traceId = (0, node_crypto_1.randomUUID)();
|
|
123
|
+
}
|
|
124
|
+
const span = {
|
|
125
|
+
name,
|
|
126
|
+
traceId,
|
|
127
|
+
spanId,
|
|
128
|
+
parentSpanId,
|
|
129
|
+
startTime: new Date().toISOString(),
|
|
130
|
+
status: types_1.TelemetrySpanStatus.Unset,
|
|
131
|
+
attributes: {
|
|
132
|
+
...options?.attributes,
|
|
133
|
+
...(options?.correlationId
|
|
134
|
+
? { "babysitter.correlation_id": options.correlationId }
|
|
135
|
+
: {}),
|
|
136
|
+
...(options?.traceContext?.correlationId && !options?.correlationId
|
|
137
|
+
? { "babysitter.correlation_id": options.traceContext.correlationId }
|
|
138
|
+
: {}),
|
|
139
|
+
},
|
|
140
|
+
events: [],
|
|
141
|
+
};
|
|
142
|
+
this.active.set(spanId, span);
|
|
143
|
+
this.traceIndex.set(spanId, traceId);
|
|
144
|
+
return toReadonly(span);
|
|
145
|
+
}
|
|
146
|
+
async endSpan(spanId, status) {
|
|
147
|
+
const span = this.active.get(spanId);
|
|
148
|
+
if (!span) {
|
|
149
|
+
return; // Silently ignore unknown/already-ended spans.
|
|
150
|
+
}
|
|
151
|
+
span.endTime = new Date().toISOString();
|
|
152
|
+
span.status = status ?? types_1.TelemetrySpanStatus.Ok;
|
|
153
|
+
this.active.delete(spanId);
|
|
154
|
+
this.completed.push(span);
|
|
155
|
+
}
|
|
156
|
+
async recordEvent(spanId, event) {
|
|
157
|
+
const span = this.active.get(spanId);
|
|
158
|
+
if (!span) {
|
|
159
|
+
return; // Silently ignore events on unknown/ended spans.
|
|
160
|
+
}
|
|
161
|
+
span.events.push(event);
|
|
162
|
+
}
|
|
163
|
+
async flush() {
|
|
164
|
+
const spans = this.completed.map(toReadonly);
|
|
165
|
+
for (const exporter of this.exporters) {
|
|
166
|
+
await exporter.export(spans);
|
|
167
|
+
}
|
|
168
|
+
this.completed.length = 0;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Drain completed spans — returns and clears the completed buffer.
|
|
172
|
+
*
|
|
173
|
+
* Unlike `flush()` (which satisfies the TelemetryProvider interface and
|
|
174
|
+
* returns void), this method hands the span data back to the caller.
|
|
175
|
+
*/
|
|
176
|
+
async drain() {
|
|
177
|
+
return this.completed.splice(0).map(toReadonly);
|
|
178
|
+
}
|
|
179
|
+
// ---------- Extra helpers (not on interface) ----------
|
|
180
|
+
/** Return a snapshot of all currently open (un-ended) spans. */
|
|
181
|
+
getActiveSpans() {
|
|
182
|
+
return [...this.active.values()].map(toReadonly);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.InMemoryTelemetryProvider = InMemoryTelemetryProvider;
|
|
186
|
+
function redactSpan(span) {
|
|
187
|
+
return {
|
|
188
|
+
...span,
|
|
189
|
+
attributes: redactAttributes(span.attributes),
|
|
190
|
+
events: span.events.map((event) => ({
|
|
191
|
+
...event,
|
|
192
|
+
attributes: event.attributes ? redactAttributes(event.attributes) : undefined,
|
|
193
|
+
})),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function redactAttributes(attributes) {
|
|
197
|
+
return Object.fromEntries(Object.entries(attributes).map(([key, value]) => [
|
|
198
|
+
key,
|
|
199
|
+
isSecretKey(key) || (typeof value === "string" && looksSecretValue(value))
|
|
200
|
+
? "[REDACTED]"
|
|
201
|
+
: value,
|
|
202
|
+
]));
|
|
203
|
+
}
|
|
204
|
+
function isSecretKey(key) {
|
|
205
|
+
return /(token|secret|password|api[_-]?key|authorization|credential)/i.test(key);
|
|
206
|
+
}
|
|
207
|
+
function looksSecretValue(value) {
|
|
208
|
+
return /(bearer\s+\S+|token=\S+|password=\S+|secret=\S+)/i.test(value);
|
|
209
|
+
}
|
|
210
|
+
function toOtlpPayload(spans) {
|
|
211
|
+
return {
|
|
212
|
+
resourceSpans: [
|
|
213
|
+
{
|
|
214
|
+
resource: { attributes: [] },
|
|
215
|
+
scopeSpans: [
|
|
216
|
+
{
|
|
217
|
+
scope: { name: "@a5c-ai/genty-runtime" },
|
|
218
|
+
spans: spans.map((span) => ({
|
|
219
|
+
traceId: span.traceId,
|
|
220
|
+
spanId: span.spanId,
|
|
221
|
+
parentSpanId: span.parentSpanId,
|
|
222
|
+
name: span.name,
|
|
223
|
+
startTimeUnixNano: isoToUnixNano(span.startTime),
|
|
224
|
+
endTimeUnixNano: span.endTime ? isoToUnixNano(span.endTime) : undefined,
|
|
225
|
+
status: { code: span.status },
|
|
226
|
+
attributes: toOtlpAttributes(span.attributes),
|
|
227
|
+
events: span.events.map((event) => ({
|
|
228
|
+
name: event.name,
|
|
229
|
+
timeUnixNano: isoToUnixNano(event.timestamp),
|
|
230
|
+
attributes: event.attributes ? toOtlpAttributes(event.attributes) : [],
|
|
231
|
+
})),
|
|
232
|
+
})),
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function toOtlpAttributes(attributes) {
|
|
240
|
+
return Object.entries(attributes).map(([key, value]) => ({
|
|
241
|
+
key,
|
|
242
|
+
value: typeof value === "string"
|
|
243
|
+
? { stringValue: value }
|
|
244
|
+
: typeof value === "number"
|
|
245
|
+
? { doubleValue: value }
|
|
246
|
+
: { boolValue: value },
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
function isoToUnixNano(value) {
|
|
250
|
+
return String(BigInt(new Date(value).getTime()) * 1000000n);
|
|
251
|
+
}
|
|
252
|
+
async function defaultHttpSend(url, payload) {
|
|
253
|
+
const response = await fetch(url, {
|
|
254
|
+
method: "POST",
|
|
255
|
+
headers: { "content-type": "application/json" },
|
|
256
|
+
body: JSON.stringify(payload),
|
|
257
|
+
});
|
|
258
|
+
if (!response.ok) {
|
|
259
|
+
throw new Error(`Telemetry export failed with HTTP ${response.status}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SpanTree — builds a parent/child tree from a flat list of TelemetrySpans.
|
|
3
|
+
*
|
|
4
|
+
* Useful for rendering trace waterfalls, computing subtree durations, and
|
|
5
|
+
* serializing trace hierarchies to JSON for the observer UI.
|
|
6
|
+
*/
|
|
7
|
+
import type { TelemetrySpan } from "./types";
|
|
8
|
+
/** A tree node wrapping a span with its children. */
|
|
9
|
+
export interface SpanTreeNode {
|
|
10
|
+
readonly span: TelemetrySpan;
|
|
11
|
+
readonly children: SpanTreeNode[];
|
|
12
|
+
}
|
|
13
|
+
/** Serializable representation of a SpanTreeNode. */
|
|
14
|
+
export interface SerializedSpanTreeNode {
|
|
15
|
+
readonly spanId: string;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly traceId: string;
|
|
18
|
+
readonly parentSpanId?: string;
|
|
19
|
+
readonly startTime: string;
|
|
20
|
+
readonly endTime?: string;
|
|
21
|
+
readonly status: string;
|
|
22
|
+
readonly attributes: Record<string, string | number | boolean>;
|
|
23
|
+
readonly events: Array<{
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly timestamp: string;
|
|
26
|
+
readonly attributes?: Record<string, string | number | boolean>;
|
|
27
|
+
}>;
|
|
28
|
+
readonly children: SerializedSpanTreeNode[];
|
|
29
|
+
}
|
|
30
|
+
/** Tree built from a flat span list. */
|
|
31
|
+
export declare class SpanTree {
|
|
32
|
+
/** All nodes keyed by spanId for O(1) lookup. */
|
|
33
|
+
private readonly nodes;
|
|
34
|
+
/** Root node ids (spans with no parent or whose parent is unknown). */
|
|
35
|
+
private readonly rootIds;
|
|
36
|
+
/** Insert a span into the tree, linking it to its parent if present. */
|
|
37
|
+
addSpan(span: TelemetrySpan): void;
|
|
38
|
+
/** Get direct children of a span. */
|
|
39
|
+
getChildren(spanId: string): TelemetrySpan[];
|
|
40
|
+
/** Get top-level spans (those with no parent). */
|
|
41
|
+
getRoots(): TelemetrySpan[];
|
|
42
|
+
/** Serialize the full tree to a JSON-safe structure. */
|
|
43
|
+
toJSON(): SerializedSpanTreeNode[];
|
|
44
|
+
private serializeNode;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=span-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span-tree.d.ts","sourceRoot":"","sources":["../../src/telemetry/span-tree.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAM7C,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,YAAY,EAAE,CAAC;CACnC;AAED,qDAAqD;AACrD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IAC/D,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;QACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;KACjE,CAAC,CAAC;IACH,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,EAAE,CAAC;CAC7C;AAMD,wCAAwC;AACxC,qBAAa,QAAQ;IACnB,iDAAiD;IACjD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmC;IACzD,uEAAuE;IACvE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IAExC,wEAAwE;IACxE,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI;IAgClC,qCAAqC;IACrC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,EAAE;IAM5C,kDAAkD;IAClD,QAAQ,IAAI,aAAa,EAAE;IAO3B,wDAAwD;IACxD,MAAM,IAAI,sBAAsB,EAAE;IAOlC,OAAO,CAAC,aAAa;CAmBtB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SpanTree — builds a parent/child tree from a flat list of TelemetrySpans.
|
|
4
|
+
*
|
|
5
|
+
* Useful for rendering trace waterfalls, computing subtree durations, and
|
|
6
|
+
* serializing trace hierarchies to JSON for the observer UI.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SpanTree = void 0;
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Implementation
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
/** Tree built from a flat span list. */
|
|
14
|
+
class SpanTree {
|
|
15
|
+
/** All nodes keyed by spanId for O(1) lookup. */
|
|
16
|
+
nodes = new Map();
|
|
17
|
+
/** Root node ids (spans with no parent or whose parent is unknown). */
|
|
18
|
+
rootIds = [];
|
|
19
|
+
/** Insert a span into the tree, linking it to its parent if present. */
|
|
20
|
+
addSpan(span) {
|
|
21
|
+
// Create or retrieve the node for this span.
|
|
22
|
+
let node = this.nodes.get(span.spanId);
|
|
23
|
+
if (node) {
|
|
24
|
+
// Node was pre-created as a placeholder by a child — update the span.
|
|
25
|
+
node.span = span;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
node = { span, children: [] };
|
|
29
|
+
this.nodes.set(span.spanId, node);
|
|
30
|
+
}
|
|
31
|
+
if (span.parentSpanId) {
|
|
32
|
+
let parentNode = this.nodes.get(span.parentSpanId);
|
|
33
|
+
if (!parentNode) {
|
|
34
|
+
// Parent hasn't been added yet — create a placeholder.
|
|
35
|
+
parentNode = {
|
|
36
|
+
span: undefined,
|
|
37
|
+
children: [],
|
|
38
|
+
};
|
|
39
|
+
this.nodes.set(span.parentSpanId, parentNode);
|
|
40
|
+
}
|
|
41
|
+
// Avoid duplicate children on re-add.
|
|
42
|
+
if (!parentNode.children.some((c) => c.span?.spanId === span.spanId)) {
|
|
43
|
+
parentNode.children.push(node);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
if (!this.rootIds.includes(span.spanId)) {
|
|
48
|
+
this.rootIds.push(span.spanId);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Get direct children of a span. */
|
|
53
|
+
getChildren(spanId) {
|
|
54
|
+
const node = this.nodes.get(spanId);
|
|
55
|
+
if (!node)
|
|
56
|
+
return [];
|
|
57
|
+
return node.children.map((c) => c.span);
|
|
58
|
+
}
|
|
59
|
+
/** Get top-level spans (those with no parent). */
|
|
60
|
+
getRoots() {
|
|
61
|
+
return this.rootIds
|
|
62
|
+
.map((id) => this.nodes.get(id))
|
|
63
|
+
.filter((n) => n != null && n.span != null)
|
|
64
|
+
.map((n) => n.span);
|
|
65
|
+
}
|
|
66
|
+
/** Serialize the full tree to a JSON-safe structure. */
|
|
67
|
+
toJSON() {
|
|
68
|
+
return this.getRoots()
|
|
69
|
+
.map((root) => this.nodes.get(root.spanId))
|
|
70
|
+
.filter((n) => n != null)
|
|
71
|
+
.map((n) => this.serializeNode(n));
|
|
72
|
+
}
|
|
73
|
+
serializeNode(node) {
|
|
74
|
+
const { span } = node;
|
|
75
|
+
return {
|
|
76
|
+
spanId: span.spanId,
|
|
77
|
+
name: span.name,
|
|
78
|
+
traceId: span.traceId,
|
|
79
|
+
parentSpanId: span.parentSpanId,
|
|
80
|
+
startTime: span.startTime,
|
|
81
|
+
endTime: span.endTime,
|
|
82
|
+
status: span.status,
|
|
83
|
+
attributes: { ...span.attributes },
|
|
84
|
+
events: span.events.map((e) => ({
|
|
85
|
+
name: e.name,
|
|
86
|
+
timestamp: e.timestamp,
|
|
87
|
+
...(e.attributes ? { attributes: { ...e.attributes } } : {}),
|
|
88
|
+
})),
|
|
89
|
+
children: node.children.map((c) => this.serializeNode(c)),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.SpanTree = SpanTree;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TraceContext } from "./types";
|
|
2
|
+
export declare function parseTraceParent(header: string): TraceContext | null;
|
|
3
|
+
export declare function serializeTraceParent(context: TraceContext): string;
|
|
4
|
+
export interface CreateTraceContextOptions {
|
|
5
|
+
parent?: TraceContext;
|
|
6
|
+
correlationId?: string;
|
|
7
|
+
sampled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function createTraceContext(options?: CreateTraceContextOptions): TraceContext;
|
|
10
|
+
//# sourceMappingURL=traceContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traceContext.d.ts","sourceRoot":"","sources":["../../src/telemetry/traceContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAQ5C,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAQpE;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAElE;AAED,MAAM,WAAW,yBAAyB;IACxC,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,YAAY,CAYpF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTraceParent = parseTraceParent;
|
|
4
|
+
exports.serializeTraceParent = serializeTraceParent;
|
|
5
|
+
exports.createTraceContext = createTraceContext;
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
const TRACEPARENT_PATTERN = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;
|
|
8
|
+
function allZero(value) {
|
|
9
|
+
return /^0+$/.test(value);
|
|
10
|
+
}
|
|
11
|
+
function parseTraceParent(header) {
|
|
12
|
+
const match = TRACEPARENT_PATTERN.exec(header.trim());
|
|
13
|
+
if (!match)
|
|
14
|
+
return null;
|
|
15
|
+
const [, version, traceId, spanId, traceFlags] = match;
|
|
16
|
+
if (version !== "00" || allZero(traceId) || allZero(spanId)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return { version, traceId, spanId, traceFlags };
|
|
20
|
+
}
|
|
21
|
+
function serializeTraceParent(context) {
|
|
22
|
+
return `${context.version}-${context.traceId}-${context.spanId}-${context.traceFlags}`;
|
|
23
|
+
}
|
|
24
|
+
function createTraceContext(options) {
|
|
25
|
+
const traceId = options?.parent?.traceId ?? randomHex(16);
|
|
26
|
+
const spanId = randomHex(8);
|
|
27
|
+
const traceFlags = options?.sampled === false ? "00" : options?.parent?.traceFlags ?? "01";
|
|
28
|
+
return {
|
|
29
|
+
version: "00",
|
|
30
|
+
traceId,
|
|
31
|
+
spanId,
|
|
32
|
+
traceFlags,
|
|
33
|
+
parentSpanId: options?.parent?.spanId,
|
|
34
|
+
correlationId: options?.correlationId ?? options?.parent?.correlationId,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function randomHex(bytes) {
|
|
38
|
+
let value = (0, node_crypto_1.randomBytes)(bytes).toString("hex");
|
|
39
|
+
while (allZero(value)) {
|
|
40
|
+
value = (0, node_crypto_1.randomBytes)(bytes).toString("hex");
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|