@osfactory/otel-hook 0.7.0 → 0.8.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.
@@ -7,7 +7,7 @@ import { P as ProviderRegistry } from './registry-CIVvRlVK.js';
7
7
  import { a as DeliveryOrigin, c as DeliveryUnavailableReason, H as HookIngestInput, e as HookIngestOutcome, U as UsageObservation, O as OtelHook } from './hook-Dh8OO4Wa.js';
8
8
  import { C as Clock, I as IdGenerator, d as Logger, W as WorktreeLocator } from './ports-n7KFOpKo.js';
9
9
  import { F as FilesystemStateStore } from './filesystem-store-r-nNA3BA.js';
10
- import { o as OtlpTelemetrySink, n as OtlpLogTelemetrySink, b as DurableSpool, D as DurableLogSpool } from './otlp-log-sink-eUEjaLhk.js';
10
+ import { o as OtlpTelemetrySink, n as OtlpLogTelemetrySink, b as DurableSpool, D as DurableLogSpool } from './otlp-log-sink-zuHojHSP.js';
11
11
  import 'zod';
12
12
  import './primitives-CJ8-rn-f.js';
13
13
  import './taxonomy-DwhTtuWd.js';
@@ -655,27 +655,7 @@ var createLifecycleJanitor = (options) => {
655
655
  // src/telemetry/semconv.ts
656
656
  import { createHash } from "crypto";
657
657
  import { SpanKind, SpanStatusCode, TraceFlags } from "@opentelemetry/api";
658
-
659
- // node_modules/@opentelemetry/core/build/esm/common/time.js
660
- var NANOSECOND_DIGITS = 9;
661
- var NANOSECOND_DIGITS_IN_MILLIS = 6;
662
- var MILLISECONDS_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS_IN_MILLIS);
663
- var SECOND_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS);
664
- function millisToHrTime(epochMillis) {
665
- const epochSeconds = epochMillis / 1e3;
666
- const seconds = Math.trunc(epochSeconds);
667
- const nanos = Math.round(epochMillis % 1e3 * MILLISECONDS_TO_NANOSECONDS);
668
- return [seconds, nanos];
669
- }
670
-
671
- // node_modules/@opentelemetry/core/build/esm/ExportResult.js
672
- var ExportResultCode;
673
- (function(ExportResultCode2) {
674
- ExportResultCode2[ExportResultCode2["SUCCESS"] = 0] = "SUCCESS";
675
- ExportResultCode2[ExportResultCode2["FAILED"] = 1] = "FAILED";
676
- })(ExportResultCode || (ExportResultCode = {}));
677
-
678
- // src/telemetry/semconv.ts
658
+ import { millisToHrTime } from "@opentelemetry/core";
679
659
  import {
680
660
  ATTR_ERROR_TYPE,
681
661
  ATTR_GEN_AI_OPERATION_NAME,
@@ -692,7 +672,7 @@ import {
692
672
  } from "@opentelemetry/semantic-conventions/incubating";
693
673
 
694
674
  // src/version.ts
695
- var VERSION = "0.7.0";
675
+ var VERSION = "0.8.0";
696
676
 
697
677
  // src/telemetry/export-identity.ts
698
678
  import { ATTR_SESSION_ID } from "@opentelemetry/semantic-conventions/incubating";
@@ -1427,10 +1407,13 @@ var targetAttributes = (event2) => {
1427
1407
  };
1428
1408
  var usageTemporalityAttributes = (usage) => usage === void 0 ? {} : { [ATTR_OTELHOOK_USAGE_TEMPORALITY]: usage.temporality };
1429
1409
  var isPrimitiveAttribute = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean";
1430
- var passthroughHarAttributes = (resource) => {
1410
+ var PASSTHROUGH_RESOURCE_PREFIXES = Object.freeze(["har.", "factory.", "vcs."]);
1411
+ var LOCAL_ONLY_RESOURCE_PREFIX = "factory.local.";
1412
+ var isPassthroughKey = (key) => PASSTHROUGH_RESOURCE_PREFIXES.some((prefix) => key.startsWith(prefix)) && !key.startsWith(LOCAL_ONLY_RESOURCE_PREFIX) && key !== "factory.local";
1413
+ var passthroughResourceAttributes = (resource) => {
1431
1414
  const attributes = {};
1432
1415
  for (const [key, value] of Object.entries(resource.attributes)) {
1433
- if (key.startsWith("har.") && isPrimitiveAttribute(value)) {
1416
+ if (isPassthroughKey(key) && isPrimitiveAttribute(value)) {
1434
1417
  attributes[key] = value;
1435
1418
  }
1436
1419
  }
@@ -1464,7 +1447,7 @@ var exportIdentityAttributes = (event2, resource, ids) => {
1464
1447
  ...event2.provenance.providerVersion === void 0 ? {} : { [ATTR_OTELHOOK_PROVIDER_VERSION]: event2.provenance.providerVersion },
1465
1448
  [ATTR_OTELHOOK_WORKSPACE_ID]: event2.workspace.workspaceId,
1466
1449
  ...event2.subagentId === void 0 ? {} : { [ATTR_OTELHOOK_SUBAGENT_ID]: event2.subagentId },
1467
- ...passthroughHarAttributes(resource),
1450
+ ...passthroughResourceAttributes(resource),
1468
1451
  ...hexTraceAttributes(ids)
1469
1452
  };
1470
1453
  };
@@ -1614,12 +1597,12 @@ var pickTarget = (attributes) => {
1614
1597
  }
1615
1598
  return picked;
1616
1599
  };
1617
- var withoutTarget = (attributes) => {
1600
+ var withoutTarget = (attributes, resource) => {
1618
1601
  const rest = { ...attributes };
1619
1602
  for (const key of TARGET_KEYS) {
1620
1603
  delete rest[key];
1621
1604
  }
1622
- return rest;
1605
+ return { ...rest, ...pickTarget(passthroughResourceAttributes(resource)) };
1623
1606
  };
1624
1607
  var rankOf = (candidate) => {
1625
1608
  const source = candidate[ATTR_OTELHOOK_TARGET_SOURCE];
@@ -1724,7 +1707,7 @@ var buildLifecycleSpan = (plan, resource, scope) => {
1724
1707
  name = "session";
1725
1708
  kind = SpanKind.INTERNAL;
1726
1709
  attributes = {
1727
- ...withoutTarget(attributes),
1710
+ ...withoutTarget(attributes, resource),
1728
1711
  ...strongestTarget([pickTarget(resolved.recovered), start === void 0 ? {} : targetAttributes(start)]),
1729
1712
  ...start?.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME]: start.agentName },
1730
1713
  ...start?.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION]: start.agentVersion },
@@ -1765,7 +1748,7 @@ var buildLifecycleSpan = (plan, resource, scope) => {
1765
1748
  kind = SpanKind.CLIENT;
1766
1749
  attributes = {
1767
1750
  // Target keys are re-chosen below as one unit, never mixed across edges.
1768
- ...withoutTarget(attributes),
1751
+ ...withoutTarget(attributes, resource),
1769
1752
  [ATTR_GEN_AI_TOOL_NAME]: toolName,
1770
1753
  [ATTR_GEN_AI_TOOL_CALL_ID]: start?.toolCallId ?? end?.toolCallId ?? group.ref.scopeKey,
1771
1754
  ...start?.toolKind === void 0 ? {} : { [ATTR_OTELHOOK_TOOL_KIND]: start.toolKind },
@@ -5165,8 +5148,26 @@ var createFileDurableSpool = (options) => createSpoolQueue({
5165
5148
 
5166
5149
  // src/telemetry/otlp-log-sink.ts
5167
5150
  import { TraceFlags as TraceFlags3 } from "@opentelemetry/api";
5151
+ import { ExportResultCode } from "@opentelemetry/core";
5152
+ import { millisToHrTime as millisToHrTime3 } from "@opentelemetry/core";
5168
5153
  import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto";
5169
5154
 
5155
+ // src/config/otlp-endpoint.ts
5156
+ var OTLP_ENDPOINT_VARIABLES = Object.freeze({
5157
+ generic: "OTEL_EXPORTER_OTLP_ENDPOINT",
5158
+ traces: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
5159
+ logs: "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT"
5160
+ });
5161
+ var OTLP_TRACES_PATH = "/v1/traces";
5162
+ var OTLP_LOGS_PATH = "/v1/logs";
5163
+ var withoutTrailingSlashes = (value) => {
5164
+ let end = value.length;
5165
+ while (end > 0 && value.charCodeAt(end - 1) === 47) {
5166
+ end -= 1;
5167
+ }
5168
+ return value.slice(0, end);
5169
+ };
5170
+
5170
5171
  // src/telemetry/exporter-resource.ts
5171
5172
  import { resourceFromAttributes } from "@opentelemetry/resources";
5172
5173
  var resourceFromExporterPolicy = (policy) => resourceFromAttributes({
@@ -5203,8 +5204,8 @@ var replayResource = (attributes, policy) => {
5203
5204
  };
5204
5205
 
5205
5206
  // src/telemetry/log-records.ts
5206
- import { TraceFlags as TraceFlags2 } from "@opentelemetry/api";
5207
- import { SeverityNumber } from "@opentelemetry/api-logs";
5207
+ import { SeverityNumber, TraceFlags as TraceFlags2 } from "@opentelemetry/api";
5208
+ import { millisToHrTime as millisToHrTime2 } from "@opentelemetry/core";
5208
5209
  import {
5209
5210
  ATTR_ERROR_TYPE as ATTR_ERROR_TYPE2,
5210
5211
  ATTR_GEN_AI_OPERATION_NAME as ATTR_GEN_AI_OPERATION_NAME2,
@@ -5472,14 +5473,14 @@ var contentAttributes = (fact, body) => ({
5472
5473
  });
5473
5474
  var buildRecord = (input) => {
5474
5475
  const severityNumber = severityFor(input.event);
5475
- const hrTime2 = millisToHrTime(input.event.occurredAt);
5476
+ const hrTime = millisToHrTime2(input.event.occurredAt);
5476
5477
  return {
5477
- hrTime: hrTime2,
5478
+ hrTime,
5478
5479
  // A hook observes an event that already happened, and this mapping is pure —
5479
5480
  // there is no clock here to read a real observation time from. Reporting the
5480
5481
  // occurrence time for both is the honest answer: it says "this is when it
5481
5482
  // happened" twice rather than inventing a second, wrong timestamp.
5482
- hrTimeObserved: hrTime2,
5483
+ hrTimeObserved: hrTime,
5483
5484
  spanContext: input.spanContext,
5484
5485
  severityNumber,
5485
5486
  severityText: SEVERITY_TEXT[severityNumber] ?? "INFO",
@@ -5569,15 +5570,6 @@ var canonicalEventsToLogRecords = (events, options) => {
5569
5570
  };
5570
5571
 
5571
5572
  // src/telemetry/otlp-log-sink.ts
5572
- var OTLP_TRACES_PATH = "/v1/traces";
5573
- var OTLP_LOGS_PATH = "/v1/logs";
5574
- var withoutTrailingSlashes = (value) => {
5575
- let end = value.length;
5576
- while (end > 0 && value.charCodeAt(end - 1) === 47) {
5577
- end -= 1;
5578
- }
5579
- return value.slice(0, end);
5580
- };
5581
5573
  var resolveLogsEndpoint = (exporter) => {
5582
5574
  if (exporter.logs.endpoint !== void 0) {
5583
5575
  return { endpoint: exporter.logs.endpoint, derived: false };
@@ -5631,8 +5623,8 @@ var deserializeRecord = (serialized, resource, scope) => {
5631
5623
  isRemote: false
5632
5624
  };
5633
5625
  return {
5634
- hrTime: millisToHrTime(serialized.timeMillis),
5635
- hrTimeObserved: millisToHrTime(serialized.observedTimeMillis),
5626
+ hrTime: millisToHrTime3(serialized.timeMillis),
5627
+ hrTimeObserved: millisToHrTime3(serialized.observedTimeMillis),
5636
5628
  ...spanContext === void 0 ? {} : { spanContext },
5637
5629
  severityNumber: serialized.severityNumber,
5638
5630
  ...serialized.severityText === void 0 ? {} : { severityText: serialized.severityText },
@@ -5847,6 +5839,7 @@ var createOtlpLogSink = (options) => {
5847
5839
  };
5848
5840
 
5849
5841
  // src/telemetry/otlp-sink.ts
5842
+ import { ExportResultCode as ExportResultCode2 } from "@opentelemetry/core";
5850
5843
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
5851
5844
  var chunk2 = (items, size) => {
5852
5845
  if (size <= 0 || items.length <= size) {
@@ -5934,7 +5927,7 @@ var createOtlpTraceSink = (options) => {
5934
5927
  const batchResource = replayResource(batch.resourceAttributes, options.exporter);
5935
5928
  const spans = batch.spans.map((span) => deserializeSpan(span, batchResource, batch.instrumentationScope));
5936
5929
  const result = await exportSpans(spans);
5937
- return result.code === ExportResultCode.SUCCESS;
5930
+ return result.code === ExportResultCode2.SUCCESS;
5938
5931
  };
5939
5932
  const resolveCorrelations = async (events) => {
5940
5933
  if (options.correlate === void 0) {
@@ -5966,9 +5959,9 @@ var createOtlpTraceSink = (options) => {
5966
5959
  try {
5967
5960
  result = await exportSpans(batch);
5968
5961
  } catch (thrown) {
5969
- result = { code: ExportResultCode.FAILED, error: thrown instanceof Error ? thrown : new Error("export threw") };
5962
+ result = { code: ExportResultCode2.FAILED, error: thrown instanceof Error ? thrown : new Error("export threw") };
5970
5963
  }
5971
- if (result.code === ExportResultCode.SUCCESS) {
5964
+ if (result.code === ExportResultCode2.SUCCESS) {
5972
5965
  accepted += batch.length;
5973
5966
  health.recordSuccess(batch.length, options.clock.now());
5974
5967
  continue;