@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.
package/dist/index.js CHANGED
@@ -1926,6 +1926,29 @@ var describeResolvedConfig = (config) => {
1926
1926
  };
1927
1927
  };
1928
1928
 
1929
+ // src/config/otlp-endpoint.ts
1930
+ var OTLP_ENDPOINT_VARIABLES = Object.freeze({
1931
+ generic: "OTEL_EXPORTER_OTLP_ENDPOINT",
1932
+ traces: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
1933
+ logs: "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT"
1934
+ });
1935
+ var OTLP_TRACES_PATH = "/v1/traces";
1936
+ var OTLP_LOGS_PATH = "/v1/logs";
1937
+ var withoutTrailingSlashes = (value) => {
1938
+ let end = value.length;
1939
+ while (end > 0 && value.charCodeAt(end - 1) === 47) {
1940
+ end -= 1;
1941
+ }
1942
+ return value.slice(0, end);
1943
+ };
1944
+ var otlpSignalEndpointFromBase = (base, signal) => {
1945
+ const trimmed = withoutTrailingSlashes(base);
1946
+ if (trimmed.endsWith(OTLP_TRACES_PATH)) {
1947
+ return signal === "traces" ? trimmed : `${trimmed.slice(0, trimmed.length - OTLP_TRACES_PATH.length)}${OTLP_LOGS_PATH}`;
1948
+ }
1949
+ return `${trimmed}${signal === "traces" ? OTLP_TRACES_PATH : OTLP_LOGS_PATH}`;
1950
+ };
1951
+
1929
1952
  // src/config/otlp-headers.ts
1930
1953
  var MAX_OTLP_HEADERS = 32;
1931
1954
  var OTLP_HEADER_VARIABLES = Object.freeze({
@@ -2050,7 +2073,13 @@ var describeOtlpHeaderNames = (...sources) => unionOtlpHeaderNames(...sources.ma
2050
2073
  // src/config/environment.ts
2051
2074
  var ENVIRONMENT_VARIABLES = Object.freeze({
2052
2075
  exporterEnabled: "OTEL_HOOK_ENABLED",
2076
+ /** Full traces URL; otel-hook's own variable, above the standard ones. */
2053
2077
  exporterEndpoint: "OTEL_HOOK_EXPORTER_ENDPOINT",
2078
+ /**
2079
+ * Standard base URL: `/v1/traces` and `/v1/logs` are appended per signal. A
2080
+ * value already ending in `/v1/traces` is the legacy full traces URL and is
2081
+ * used as-is (see `otlpSignalEndpointFromBase`).
2082
+ */
2054
2083
  otlpEndpoint: "OTEL_EXPORTER_OTLP_ENDPOINT",
2055
2084
  exporterProtocol: "OTEL_HOOK_EXPORTER_PROTOCOL",
2056
2085
  exporterTimeoutMillis: "OTEL_HOOK_EXPORTER_TIMEOUT_MS",
@@ -2124,7 +2153,10 @@ var parseEnvironmentConfig = (env) => {
2124
2153
  return trimmed === "" ? void 0 : trimmed;
2125
2154
  };
2126
2155
  const exporterEnabled = readBoolean(ENVIRONMENT_VARIABLES.exporterEnabled);
2127
- const endpoint = readString(ENVIRONMENT_VARIABLES.exporterEndpoint) ?? readString(ENVIRONMENT_VARIABLES.otlpEndpoint);
2156
+ const hookEndpoint = readString(ENVIRONMENT_VARIABLES.exporterEndpoint);
2157
+ const otlpTracesEndpoint = readString(OTLP_ENDPOINT_VARIABLES.traces);
2158
+ const otlpBaseEndpoint = readString(ENVIRONMENT_VARIABLES.otlpEndpoint);
2159
+ const endpoint = hookEndpoint ?? otlpTracesEndpoint ?? (otlpBaseEndpoint === void 0 ? void 0 : otlpSignalEndpointFromBase(otlpBaseEndpoint, "traces"));
2128
2160
  const timeoutMillis = readInteger(ENVIRONMENT_VARIABLES.exporterTimeoutMillis);
2129
2161
  const resourceRaw = readString(ENVIRONMENT_VARIABLES.resourceAttributes);
2130
2162
  const resource = resourceRaw === void 0 ? void 0 : parseResourceAttributesValue(resourceRaw);
@@ -2210,7 +2242,7 @@ var parseEnvironmentConfig = (env) => {
2210
2242
  const maxEventsPerInvocation = readInteger(ENVIRONMENT_VARIABLES.maxEventsPerInvocation);
2211
2243
  const logsEnabled = readBoolean(ENVIRONMENT_VARIABLES.logsEnabled);
2212
2244
  const logsIncludeContent = readBoolean(ENVIRONMENT_VARIABLES.logsIncludeContent);
2213
- const logsEndpoint = readString(ENVIRONMENT_VARIABLES.logsEndpoint) ?? readString(ENVIRONMENT_VARIABLES.otlpLogsEndpoint);
2245
+ const logsEndpoint = readString(ENVIRONMENT_VARIABLES.logsEndpoint) ?? readString(ENVIRONMENT_VARIABLES.otlpLogsEndpoint) ?? (hookEndpoint === void 0 && otlpTracesEndpoint !== void 0 && otlpBaseEndpoint !== void 0 ? otlpSignalEndpointFromBase(otlpBaseEndpoint, "logs") : void 0);
2214
2246
  const logs = {
2215
2247
  ...logsEnabled === void 0 ? {} : { enabled: logsEnabled },
2216
2248
  ...logsEndpoint === void 0 ? {} : { endpoint: logsEndpoint },
@@ -7771,27 +7803,7 @@ var createCallbackDeduplicator = (deps) => {
7771
7803
  // src/telemetry/semconv.ts
7772
7804
  import { createHash as createHash3 } from "crypto";
7773
7805
  import { SpanKind, SpanStatusCode, TraceFlags } from "@opentelemetry/api";
7774
-
7775
- // node_modules/@opentelemetry/core/build/esm/common/time.js
7776
- var NANOSECOND_DIGITS = 9;
7777
- var NANOSECOND_DIGITS_IN_MILLIS = 6;
7778
- var MILLISECONDS_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS_IN_MILLIS);
7779
- var SECOND_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS);
7780
- function millisToHrTime(epochMillis) {
7781
- const epochSeconds = epochMillis / 1e3;
7782
- const seconds = Math.trunc(epochSeconds);
7783
- const nanos = Math.round(epochMillis % 1e3 * MILLISECONDS_TO_NANOSECONDS);
7784
- return [seconds, nanos];
7785
- }
7786
-
7787
- // node_modules/@opentelemetry/core/build/esm/ExportResult.js
7788
- var ExportResultCode;
7789
- (function(ExportResultCode2) {
7790
- ExportResultCode2[ExportResultCode2["SUCCESS"] = 0] = "SUCCESS";
7791
- ExportResultCode2[ExportResultCode2["FAILED"] = 1] = "FAILED";
7792
- })(ExportResultCode || (ExportResultCode = {}));
7793
-
7794
- // src/telemetry/semconv.ts
7806
+ import { millisToHrTime } from "@opentelemetry/core";
7795
7807
  import {
7796
7808
  ATTR_ERROR_TYPE,
7797
7809
  ATTR_GEN_AI_OPERATION_NAME,
@@ -7808,7 +7820,7 @@ import {
7808
7820
  } from "@opentelemetry/semantic-conventions/incubating";
7809
7821
 
7810
7822
  // src/version.ts
7811
- var VERSION = "0.7.0";
7823
+ var VERSION = "0.8.0";
7812
7824
 
7813
7825
  // src/telemetry/export-identity.ts
7814
7826
  import { ATTR_SESSION_ID } from "@opentelemetry/semantic-conventions/incubating";
@@ -7849,10 +7861,13 @@ var targetAttributes = (event3) => {
7849
7861
  };
7850
7862
  var usageTemporalityAttributes = (usage) => usage === void 0 ? {} : { [ATTR_OTELHOOK_USAGE_TEMPORALITY]: usage.temporality };
7851
7863
  var isPrimitiveAttribute = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean";
7852
- var passthroughHarAttributes = (resource) => {
7864
+ var PASSTHROUGH_RESOURCE_PREFIXES = Object.freeze(["har.", "factory.", "vcs."]);
7865
+ var LOCAL_ONLY_RESOURCE_PREFIX = "factory.local.";
7866
+ var isPassthroughKey = (key) => PASSTHROUGH_RESOURCE_PREFIXES.some((prefix) => key.startsWith(prefix)) && !key.startsWith(LOCAL_ONLY_RESOURCE_PREFIX) && key !== "factory.local";
7867
+ var passthroughResourceAttributes = (resource) => {
7853
7868
  const attributes = {};
7854
7869
  for (const [key, value] of Object.entries(resource.attributes)) {
7855
- if (key.startsWith("har.") && isPrimitiveAttribute(value)) {
7870
+ if (isPassthroughKey(key) && isPrimitiveAttribute(value)) {
7856
7871
  attributes[key] = value;
7857
7872
  }
7858
7873
  }
@@ -7886,7 +7901,7 @@ var exportIdentityAttributes = (event3, resource, ids) => {
7886
7901
  ...event3.provenance.providerVersion === void 0 ? {} : { [ATTR_OTELHOOK_PROVIDER_VERSION]: event3.provenance.providerVersion },
7887
7902
  [ATTR_OTELHOOK_WORKSPACE_ID]: event3.workspace.workspaceId,
7888
7903
  ...event3.subagentId === void 0 ? {} : { [ATTR_OTELHOOK_SUBAGENT_ID]: event3.subagentId },
7889
- ...passthroughHarAttributes(resource),
7904
+ ...passthroughResourceAttributes(resource),
7890
7905
  ...hexTraceAttributes(ids)
7891
7906
  };
7892
7907
  };
@@ -8036,12 +8051,12 @@ var pickTarget = (attributes) => {
8036
8051
  }
8037
8052
  return picked;
8038
8053
  };
8039
- var withoutTarget = (attributes) => {
8054
+ var withoutTarget = (attributes, resource) => {
8040
8055
  const rest = { ...attributes };
8041
8056
  for (const key of TARGET_KEYS) {
8042
8057
  delete rest[key];
8043
8058
  }
8044
- return rest;
8059
+ return { ...rest, ...pickTarget(passthroughResourceAttributes(resource)) };
8045
8060
  };
8046
8061
  var rankOf = (candidate) => {
8047
8062
  const source = candidate[ATTR_OTELHOOK_TARGET_SOURCE];
@@ -8146,7 +8161,7 @@ var buildLifecycleSpan = (plan, resource, scope) => {
8146
8161
  name = "session";
8147
8162
  kind = SpanKind.INTERNAL;
8148
8163
  attributes = {
8149
- ...withoutTarget(attributes),
8164
+ ...withoutTarget(attributes, resource),
8150
8165
  ...strongestTarget([pickTarget(resolved.recovered), start === void 0 ? {} : targetAttributes(start)]),
8151
8166
  ...start?.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME]: start.agentName },
8152
8167
  ...start?.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION]: start.agentVersion },
@@ -8187,7 +8202,7 @@ var buildLifecycleSpan = (plan, resource, scope) => {
8187
8202
  kind = SpanKind.CLIENT;
8188
8203
  attributes = {
8189
8204
  // Target keys are re-chosen below as one unit, never mixed across edges.
8190
- ...withoutTarget(attributes),
8205
+ ...withoutTarget(attributes, resource),
8191
8206
  [ATTR_GEN_AI_TOOL_NAME]: toolName,
8192
8207
  [ATTR_GEN_AI_TOOL_CALL_ID]: start?.toolCallId ?? end?.toolCallId ?? group.ref.scopeKey,
8193
8208
  ...start?.toolKind === void 0 ? {} : { [ATTR_OTELHOOK_TOOL_KIND]: start.toolKind },
@@ -9535,6 +9550,7 @@ var createFileDurableSpool = (options) => createSpoolQueue({
9535
9550
  });
9536
9551
 
9537
9552
  // src/telemetry/otlp-sink.ts
9553
+ import { ExportResultCode } from "@opentelemetry/core";
9538
9554
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
9539
9555
 
9540
9556
  // src/diagnostics/health.ts
@@ -9801,8 +9817,8 @@ var createOtlpTraceSink = (options) => {
9801
9817
  };
9802
9818
 
9803
9819
  // src/telemetry/log-records.ts
9804
- import { TraceFlags as TraceFlags2 } from "@opentelemetry/api";
9805
- import { SeverityNumber } from "@opentelemetry/api-logs";
9820
+ import { SeverityNumber, TraceFlags as TraceFlags2 } from "@opentelemetry/api";
9821
+ import { millisToHrTime as millisToHrTime2 } from "@opentelemetry/core";
9806
9822
  import {
9807
9823
  ATTR_ERROR_TYPE as ATTR_ERROR_TYPE2,
9808
9824
  ATTR_GEN_AI_OPERATION_NAME as ATTR_GEN_AI_OPERATION_NAME2,
@@ -10123,14 +10139,14 @@ var contentAttributes = (fact, body) => ({
10123
10139
  });
10124
10140
  var buildRecord = (input) => {
10125
10141
  const severityNumber = severityFor(input.event);
10126
- const hrTime2 = millisToHrTime(input.event.occurredAt);
10142
+ const hrTime = millisToHrTime2(input.event.occurredAt);
10127
10143
  return {
10128
- hrTime: hrTime2,
10144
+ hrTime,
10129
10145
  // A hook observes an event that already happened, and this mapping is pure —
10130
10146
  // there is no clock here to read a real observation time from. Reporting the
10131
10147
  // occurrence time for both is the honest answer: it says "this is when it
10132
10148
  // happened" twice rather than inventing a second, wrong timestamp.
10133
- hrTimeObserved: hrTime2,
10149
+ hrTimeObserved: hrTime,
10134
10150
  spanContext: input.spanContext,
10135
10151
  severityNumber,
10136
10152
  severityText: SEVERITY_TEXT[severityNumber] ?? "INFO",
@@ -10320,16 +10336,9 @@ var createFileDurableLogSpool = (options) => createSpoolQueue({
10320
10336
 
10321
10337
  // src/telemetry/otlp-log-sink.ts
10322
10338
  import { TraceFlags as TraceFlags3 } from "@opentelemetry/api";
10339
+ import { ExportResultCode as ExportResultCode2 } from "@opentelemetry/core";
10340
+ import { millisToHrTime as millisToHrTime3 } from "@opentelemetry/core";
10323
10341
  import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto";
10324
- var OTLP_TRACES_PATH = "/v1/traces";
10325
- var OTLP_LOGS_PATH = "/v1/logs";
10326
- var withoutTrailingSlashes = (value) => {
10327
- let end = value.length;
10328
- while (end > 0 && value.charCodeAt(end - 1) === 47) {
10329
- end -= 1;
10330
- }
10331
- return value.slice(0, end);
10332
- };
10333
10342
  var resolveLogsEndpoint = (exporter) => {
10334
10343
  if (exporter.logs.endpoint !== void 0) {
10335
10344
  return { endpoint: exporter.logs.endpoint, derived: false };
@@ -10383,8 +10392,8 @@ var deserializeRecord = (serialized, resource, scope) => {
10383
10392
  isRemote: false
10384
10393
  };
10385
10394
  return {
10386
- hrTime: millisToHrTime(serialized.timeMillis),
10387
- hrTimeObserved: millisToHrTime(serialized.observedTimeMillis),
10395
+ hrTime: millisToHrTime3(serialized.timeMillis),
10396
+ hrTimeObserved: millisToHrTime3(serialized.observedTimeMillis),
10388
10397
  ...spanContext === void 0 ? {} : { spanContext },
10389
10398
  severityNumber: serialized.severityNumber,
10390
10399
  ...serialized.severityText === void 0 ? {} : { severityText: serialized.severityText },
@@ -10485,7 +10494,7 @@ var createOtlpLogSink = (options) => {
10485
10494
  (record) => deserializeRecord(record, batchResource, batch.instrumentationScope)
10486
10495
  );
10487
10496
  const result = await exportRecords(records);
10488
- return result.code === ExportResultCode.SUCCESS;
10497
+ return result.code === ExportResultCode2.SUCCESS;
10489
10498
  };
10490
10499
  const resolveCorrelations = async (events) => {
10491
10500
  if (options.correlate === void 0) {
@@ -10527,11 +10536,11 @@ var createOtlpLogSink = (options) => {
10527
10536
  result = await exportRecords(batch);
10528
10537
  } catch (thrown) {
10529
10538
  result = {
10530
- code: ExportResultCode.FAILED,
10539
+ code: ExportResultCode2.FAILED,
10531
10540
  error: thrown instanceof Error ? thrown : new Error("export threw")
10532
10541
  };
10533
10542
  }
10534
- if (result.code === ExportResultCode.SUCCESS) {
10543
+ if (result.code === ExportResultCode2.SUCCESS) {
10535
10544
  accepted += batch.length;
10536
10545
  health.recordSuccess(batch.length, options.clock.now());
10537
10546
  continue;
@@ -12616,6 +12625,7 @@ export {
12616
12625
  MAX_WORKTREE_WALK_DEPTH,
12617
12626
  MCP_TOOL_NAME_PATTERN,
12618
12627
  NO_LOG_CONTENT,
12628
+ OTLP_ENDPOINT_VARIABLES,
12619
12629
  OTLP_HEADER_VARIABLES,
12620
12630
  OtelHookError,
12621
12631
  PROVIDERS_WITHOUT_VERIFIED_LOCATION,
@@ -12784,6 +12794,7 @@ export {
12784
12794
  otelHookConfigSchema,
12785
12795
  otelHookErrorCodeSchema,
12786
12796
  otelHookErrorInfoSchema,
12797
+ otlpSignalEndpointFromBase,
12787
12798
  parentScopeRefOf,
12788
12799
  parseCanonicalEvent,
12789
12800
  parseCommonDirFile,