@osfactory/otel-hook 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist/{adapter-DQiPu8xF.d.ts → adapter-DyCb7y1N.d.ts} +1 -1
- package/dist/cli.js +260 -74
- package/dist/cli.js.map +1 -1
- package/dist/{export-destinations-CI7z4n3i.d.ts → export-destinations-DUeQKr_C.d.ts} +2 -2
- package/dist/{filesystem-store-CmnUlj1O.d.ts → filesystem-store-B3CpiIRl.d.ts} +1 -1
- package/dist/{hook-vM_cgqS2.d.ts → hook-D5imE0Qc.d.ts} +3 -3
- package/dist/index.d.ts +10 -10
- package/dist/index.js +252 -66
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +3 -3
- package/dist/install.js +14 -2
- package/dist/install.js.map +1 -1
- package/dist/integration.d.ts +7 -7
- package/dist/integration.js +211 -58
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.d.ts +9 -2
- package/dist/lifecycle.js +10 -3
- package/dist/lifecycle.js.map +1 -1
- package/dist/{memory-DdU1U91y.d.ts → memory-B3r6sZtC.d.ts} +1 -1
- package/dist/{metric-model-C9lLqqpI.d.ts → metric-model-B4lIuk6i.d.ts} +10 -1
- package/dist/{payload-BT19hiVZ.d.ts → payload-CdDKeRpH.d.ts} +1 -1
- package/dist/{ports-C3k_5eOQ.d.ts → ports-DhpSDIkp.d.ts} +8 -1
- package/dist/providers.d.ts +27 -11
- package/dist/providers.js +132 -43
- package/dist/providers.js.map +1 -1
- package/dist/{registry-gyJqaWmp.d.ts → registry-BKQhhIO3.d.ts} +1 -1
- package/dist/runtime.d.ts +6 -6
- package/dist/runtime.js +12 -2
- package/dist/runtime.js.map +1 -1
- package/dist/state.d.ts +3 -3
- package/dist/state.js +20 -6
- package/dist/state.js.map +1 -1
- package/dist/telemetry.d.ts +3 -3
- package/dist/telemetry.js +72 -6
- package/dist/telemetry.js.map +1 -1
- package/dist/testing.d.ts +6 -6
- package/dist/testing.js +63 -8
- package/dist/testing.js.map +1 -1
- package/package.json +2 -1
package/dist/telemetry.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { D as DEFAULT_INSTRUMENTATION_SCOPE, a as DeriveMetricObservationsInput, E as EventTraceIdentity, M as MAX_RECOVERED_START_ATTRIBUTES, b as METRIC_COST_USAGE, c as METRIC_INSTRUMENTS, d as METRIC_OPERATION_DURATION, e as METRIC_SESSIONS, f as METRIC_TOKEN_USAGE, g as METRIC_TOOL_CALLS, h as MetricInstrument, i as MetricInstrumentName, j as MetricObservation, k as MetricPoint, l as MetricsTemporality, O as OPERATION_DURATION_BUCKETS, S as SemanticMappingOptions, m as SpanCorrelation, n as SpanCorrelationResolver, o as SpanDisposition, p as SpanFamily, q as SpanOrphanClassification, r as SpanPairing, s as SpanScopeRef, T as TOKEN_USAGE_BUCKETS, t as TokenType, u as aggregateDeltaPoints, v as canonicalEventTraceIdentities, w as canonicalEventsToReadableSpans, x as deriveMetricObservations, y as parentScopeRefOf, z as spanScopeRefOf, A as startOnlySpanAttributes } from './metric-model-
|
|
2
|
-
export { C as ContentWithholdingReason, D as DurableLogSpool, a as DurableLogSpoolOptions, b as DurableMetricSpool, c as DurableMetricSpoolOptions, d as DurableSpool, e as DurableSpoolOptions, E as ExportDestinationSinks, f as ExportDestinationsOptions, L as LOG_MAPPING_VERSION, g as LOG_SIGNALS, h as LogContentPolicy, i as LogMappingOptions, j as LogMappingResult, k as LogSignal, l as LogSpoolBatch, m as LogsDeliverability, M as MAX_LOG_BODY_CHARACTERS, n as MAX_LOG_RECORDS_PER_BATCH, o as MAX_LOG_RECORDS_PER_EVENT, p as MCP_TOOL_NAME_PATTERN, q as MetricExportResult, r as MetricSpoolBatch, s as MetricsDeliverability, N as NO_LOG_CONTENT, O as OtlpLogSinkOptions, t as OtlpLogTelemetrySink, u as OtlpMetricSinkOptions, v as OtlpMetricTelemetrySink, w as OtlpTelemetrySink, x as OtlpTraceSinkOptions, S as SerializedLogRecord, y as SerializedSpan, z as SignalFanoutOptions, A as SignalFanoutSink, B as SkippedExportDestination, F as SpoolBatch, G as SpoolDrainResult, H as SpoolDropCounts, I as SpoolDropReason, J as SpoolEnqueueResult, K as SpoolOverflowPolicy, P as SpoolSendOutcome, Q as SpoolStats, R as canonicalEventsToLogRecords, T as createDestinationFanout, U as createExportDestinationSinks, V as createFileDurableLogSpool, W as createFileDurableMetricSpool, X as createFileDurableSpool, Y as createOtlpLogSink, Z as createOtlpMetricSink, _ as createOtlpTraceSink, $ as createSignalFanout, a0 as describeLogsDeliverability, a1 as describeMetricsDeliverability, a2 as exporterPolicyForDestination, a3 as logSignalOf, a4 as logSignalsForLifecycleEvents, a5 as resolveLogsEndpoint, a6 as resolveMetricsEndpoint, a7 as shareCorrelationPerBatch, a8 as spoolQueueNamesFor, a9 as validateMetricSpoolBatch } from './export-destinations-
|
|
1
|
+
export { D as DEFAULT_INSTRUMENTATION_SCOPE, a as DeriveMetricObservationsInput, E as EventTraceIdentity, M as MAX_RECOVERED_START_ATTRIBUTES, b as METRIC_COST_USAGE, c as METRIC_INSTRUMENTS, d as METRIC_OPERATION_DURATION, e as METRIC_SESSIONS, f as METRIC_TOKEN_USAGE, g as METRIC_TOOL_CALLS, h as MetricInstrument, i as MetricInstrumentName, j as MetricObservation, k as MetricPoint, l as MetricsTemporality, O as OPERATION_DURATION_BUCKETS, S as SemanticMappingOptions, m as SpanCorrelation, n as SpanCorrelationResolver, o as SpanDisposition, p as SpanFamily, q as SpanOrphanClassification, r as SpanPairing, s as SpanScopeRef, T as TOKEN_USAGE_BUCKETS, t as TokenType, u as aggregateDeltaPoints, v as canonicalEventTraceIdentities, w as canonicalEventsToReadableSpans, x as deriveMetricObservations, y as parentScopeRefOf, z as spanScopeRefOf, A as startOnlySpanAttributes } from './metric-model-B4lIuk6i.js';
|
|
2
|
+
export { C as ContentWithholdingReason, D as DurableLogSpool, a as DurableLogSpoolOptions, b as DurableMetricSpool, c as DurableMetricSpoolOptions, d as DurableSpool, e as DurableSpoolOptions, E as ExportDestinationSinks, f as ExportDestinationsOptions, L as LOG_MAPPING_VERSION, g as LOG_SIGNALS, h as LogContentPolicy, i as LogMappingOptions, j as LogMappingResult, k as LogSignal, l as LogSpoolBatch, m as LogsDeliverability, M as MAX_LOG_BODY_CHARACTERS, n as MAX_LOG_RECORDS_PER_BATCH, o as MAX_LOG_RECORDS_PER_EVENT, p as MCP_TOOL_NAME_PATTERN, q as MetricExportResult, r as MetricSpoolBatch, s as MetricsDeliverability, N as NO_LOG_CONTENT, O as OtlpLogSinkOptions, t as OtlpLogTelemetrySink, u as OtlpMetricSinkOptions, v as OtlpMetricTelemetrySink, w as OtlpTelemetrySink, x as OtlpTraceSinkOptions, S as SerializedLogRecord, y as SerializedSpan, z as SignalFanoutOptions, A as SignalFanoutSink, B as SkippedExportDestination, F as SpoolBatch, G as SpoolDrainResult, H as SpoolDropCounts, I as SpoolDropReason, J as SpoolEnqueueResult, K as SpoolOverflowPolicy, P as SpoolSendOutcome, Q as SpoolStats, R as canonicalEventsToLogRecords, T as createDestinationFanout, U as createExportDestinationSinks, V as createFileDurableLogSpool, W as createFileDurableMetricSpool, X as createFileDurableSpool, Y as createOtlpLogSink, Z as createOtlpMetricSink, _ as createOtlpTraceSink, $ as createSignalFanout, a0 as describeLogsDeliverability, a1 as describeMetricsDeliverability, a2 as exporterPolicyForDestination, a3 as logSignalOf, a4 as logSignalsForLifecycleEvents, a5 as resolveLogsEndpoint, a6 as resolveMetricsEndpoint, a7 as shareCorrelationPerBatch, a8 as spoolQueueNamesFor, a9 as validateMetricSpoolBatch } from './export-destinations-DUeQKr_C.js';
|
|
3
3
|
import { ExportResult } from '@opentelemetry/core';
|
|
4
4
|
import '@opentelemetry/api';
|
|
5
5
|
import '@opentelemetry/resources';
|
|
@@ -8,7 +8,7 @@ import './events-fcomX6d5.js';
|
|
|
8
8
|
import 'zod';
|
|
9
9
|
import './destinations-DvqsPulb.js';
|
|
10
10
|
import './schema-SpFM6YQY.js';
|
|
11
|
-
import './ports-
|
|
11
|
+
import './ports-DhpSDIkp.js';
|
|
12
12
|
import './errors.js';
|
|
13
13
|
import './primitives-CJ8-rn-f.js';
|
|
14
14
|
import './taxonomy-DwhTtuWd.js';
|
package/dist/telemetry.js
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from "@opentelemetry/semantic-conventions/incubating";
|
|
19
19
|
|
|
20
20
|
// src/version.ts
|
|
21
|
-
var VERSION = "0.
|
|
21
|
+
var VERSION = "0.13.1";
|
|
22
22
|
|
|
23
23
|
// src/telemetry/export-identity.ts
|
|
24
24
|
import { ATTR_SESSION_ID } from "@opentelemetry/semantic-conventions/incubating";
|
|
@@ -1131,7 +1131,8 @@ var buildLifecycleSpan = (plan, resource, scope) => {
|
|
|
1131
1131
|
const resolved = resolvePairing(group, anchor, correlation);
|
|
1132
1132
|
const traceId = plan.traceId;
|
|
1133
1133
|
const spanId = plan.spanId;
|
|
1134
|
-
const
|
|
1134
|
+
const parentRef = resolved.parent ?? resumedSessionParent(group.ref, correlation);
|
|
1135
|
+
const parentSpanId = parentRef === void 0 ? void 0 : deriveSpanId(providerId, sessionId, parentRef);
|
|
1135
1136
|
let name = group.ref.family;
|
|
1136
1137
|
let kind = SpanKind.INTERNAL;
|
|
1137
1138
|
let status = { code: SpanStatusCode.UNSET };
|
|
@@ -1355,7 +1356,7 @@ var planGroup = (group, correlation, correlationAvailable) => {
|
|
|
1355
1356
|
// persist something that should have been persisted.
|
|
1356
1357
|
correlation === void 0 && correlationAvailable === void 0);
|
|
1357
1358
|
const effective = durablyRecorded ? correlation : effectiveCorrelation(group, correlation);
|
|
1358
|
-
const discriminator = durablyRecorded ?
|
|
1359
|
+
const discriminator = durablyRecorded ? runDiscriminatorOf(correlation) : effective?.spanIdDiscriminator ?? runDiscriminatorOf(effective);
|
|
1359
1360
|
return {
|
|
1360
1361
|
group,
|
|
1361
1362
|
anchor,
|
|
@@ -1375,6 +1376,8 @@ var planGroup = (group, correlation, correlationAvailable) => {
|
|
|
1375
1376
|
)
|
|
1376
1377
|
};
|
|
1377
1378
|
};
|
|
1379
|
+
var runDiscriminatorOf = (correlation) => correlation?.runSpanIdDiscriminator === void 0 ? void 0 : `run:${correlation.runSpanIdDiscriminator}`;
|
|
1380
|
+
var resumedSessionParent = (ref, correlation) => ref.family === "session" && correlation?.runSpanIdDiscriminator !== void 0 ? ref : void 0;
|
|
1378
1381
|
var canonicalEventTraceIdentities = (events, options = {}) => {
|
|
1379
1382
|
const layout = layoutBatch(events);
|
|
1380
1383
|
const correlations = indexCorrelations(options.correlations);
|
|
@@ -1399,7 +1402,7 @@ var canonicalEventTraceIdentities = (events, options = {}) => {
|
|
|
1399
1402
|
});
|
|
1400
1403
|
continue;
|
|
1401
1404
|
}
|
|
1402
|
-
const parent = plan.correlation?.parent ?? parentScopeRefOf(event2);
|
|
1405
|
+
const parent = plan.correlation?.parent ?? parentScopeRefOf(event2) ?? resumedSessionParent(plan.group.ref, plan.correlation);
|
|
1403
1406
|
identities.set(event2.eventId, {
|
|
1404
1407
|
traceId: plan.traceId,
|
|
1405
1408
|
spanId: plan.spanId,
|
|
@@ -1504,6 +1507,22 @@ var readSpoolQueueStats = async (queueDir) => {
|
|
|
1504
1507
|
};
|
|
1505
1508
|
};
|
|
1506
1509
|
var DEFAULT_DRAIN_MAX_BATCHES = 20;
|
|
1510
|
+
var SPOOL_CLAIM_STALE_MILLIS = 5 * 60 * 1e3;
|
|
1511
|
+
var CLAIM_MARKER = ".claimed-";
|
|
1512
|
+
var isClaimOwnerAlive = (pid) => {
|
|
1513
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) {
|
|
1514
|
+
return true;
|
|
1515
|
+
}
|
|
1516
|
+
if (pid === process.pid) {
|
|
1517
|
+
return true;
|
|
1518
|
+
}
|
|
1519
|
+
try {
|
|
1520
|
+
process.kill(pid, 0);
|
|
1521
|
+
return true;
|
|
1522
|
+
} catch (thrown) {
|
|
1523
|
+
return thrown?.code !== "ESRCH";
|
|
1524
|
+
}
|
|
1525
|
+
};
|
|
1507
1526
|
var isErrnoException = (thrown, code) => thrown instanceof Error && thrown.code === code;
|
|
1508
1527
|
var createSpoolQueue = (options) => {
|
|
1509
1528
|
const [providerSegment, installationSegment] = namespaceSegments(options);
|
|
@@ -1653,9 +1672,33 @@ var createSpoolQueue = (options) => {
|
|
|
1653
1672
|
await rename(tmp, target);
|
|
1654
1673
|
return { spooled: true };
|
|
1655
1674
|
};
|
|
1675
|
+
const releaseStaleClaims = async () => {
|
|
1676
|
+
let entries;
|
|
1677
|
+
try {
|
|
1678
|
+
entries = await readdir(queueDir);
|
|
1679
|
+
} catch {
|
|
1680
|
+
return;
|
|
1681
|
+
}
|
|
1682
|
+
const now = Date.now();
|
|
1683
|
+
for (const entry of entries) {
|
|
1684
|
+
const marker = entry.lastIndexOf(CLAIM_MARKER);
|
|
1685
|
+
if (marker <= 0) {
|
|
1686
|
+
continue;
|
|
1687
|
+
}
|
|
1688
|
+
const claimPath = path.join(queueDir, entry);
|
|
1689
|
+
const owner = Number.parseInt(entry.slice(marker + CLAIM_MARKER.length), 10);
|
|
1690
|
+
try {
|
|
1691
|
+
if (!isClaimOwnerAlive(owner) || now - (await stat(claimPath)).ctimeMs > (options.claimStaleMillis ?? SPOOL_CLAIM_STALE_MILLIS)) {
|
|
1692
|
+
await rename(claimPath, path.join(queueDir, entry.slice(0, marker)));
|
|
1693
|
+
}
|
|
1694
|
+
} catch {
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1656
1698
|
const drain = async (send, drainOptions) => {
|
|
1657
1699
|
await ensureDirs();
|
|
1658
1700
|
const cap = drainOptions?.maxBatches ?? DEFAULT_DRAIN_MAX_BATCHES;
|
|
1701
|
+
await releaseStaleClaims();
|
|
1659
1702
|
let files = await listSorted();
|
|
1660
1703
|
if (options.maxAgeMillis !== void 0) {
|
|
1661
1704
|
const now = options.clock.now();
|
|
@@ -1678,7 +1721,16 @@ var createSpoolQueue = (options) => {
|
|
|
1678
1721
|
if (fileName === void 0) {
|
|
1679
1722
|
break;
|
|
1680
1723
|
}
|
|
1681
|
-
const
|
|
1724
|
+
const queuedPath = path.join(queueDir, fileName);
|
|
1725
|
+
const filePath = path.join(
|
|
1726
|
+
queueDir,
|
|
1727
|
+
`${fileName}${CLAIM_MARKER}${String(process.pid)}-${randomBytes(4).toString("hex")}`
|
|
1728
|
+
);
|
|
1729
|
+
try {
|
|
1730
|
+
await rename(queuedPath, filePath);
|
|
1731
|
+
} catch {
|
|
1732
|
+
continue;
|
|
1733
|
+
}
|
|
1682
1734
|
const quarantine = async (rejection) => {
|
|
1683
1735
|
quarantined += 1;
|
|
1684
1736
|
options.logger?.error("durable spool quarantined an unusable batch", {
|
|
@@ -1692,9 +1744,19 @@ var createSpoolQueue = (options) => {
|
|
|
1692
1744
|
await unlink(filePath).catch(() => void 0);
|
|
1693
1745
|
}
|
|
1694
1746
|
};
|
|
1747
|
+
let text;
|
|
1748
|
+
try {
|
|
1749
|
+
text = await readFile(filePath, "utf8");
|
|
1750
|
+
} catch (thrown) {
|
|
1751
|
+
if (thrown?.code === "ENOENT") {
|
|
1752
|
+
continue;
|
|
1753
|
+
}
|
|
1754
|
+
await quarantine("unreadable");
|
|
1755
|
+
continue;
|
|
1756
|
+
}
|
|
1695
1757
|
let parsed;
|
|
1696
1758
|
try {
|
|
1697
|
-
parsed = JSON.parse(
|
|
1759
|
+
parsed = JSON.parse(text);
|
|
1698
1760
|
} catch {
|
|
1699
1761
|
await quarantine("unparseable-json");
|
|
1700
1762
|
continue;
|
|
@@ -1723,6 +1785,7 @@ var createSpoolQueue = (options) => {
|
|
|
1723
1785
|
await unlink(filePath).catch(() => void 0);
|
|
1724
1786
|
drained += 1;
|
|
1725
1787
|
} else {
|
|
1788
|
+
await rename(filePath, queuedPath).catch(() => void 0);
|
|
1726
1789
|
failed += 1;
|
|
1727
1790
|
break;
|
|
1728
1791
|
}
|
|
@@ -3759,6 +3822,9 @@ var deriveMetricObservations = (input) => {
|
|
|
3759
3822
|
if (recovered !== void 0) {
|
|
3760
3823
|
return end.occurredAt - recovered.startMillis;
|
|
3761
3824
|
}
|
|
3825
|
+
if (end.subagentId !== void 0) {
|
|
3826
|
+
return void 0;
|
|
3827
|
+
}
|
|
3762
3828
|
const turn = lastPromptInBatch?.get(end.sessionId) ?? input.turnStart?.(end.sessionId);
|
|
3763
3829
|
return turn === void 0 || turn > end.occurredAt ? void 0 : end.occurredAt - turn;
|
|
3764
3830
|
};
|