@osfactory/otel-hook 0.13.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.
@@ -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-CFIeUwqd.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-Bey2djRk.js';
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';
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.13.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 parentSpanId = resolved.parent === void 0 ? void 0 : deriveSpanId(providerId, sessionId, resolved.parent);
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 ? void 0 : effective?.spanIdDiscriminator;
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 filePath = path.join(queueDir, fileName);
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(await readFile(filePath, "utf8"));
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
  }