@osfactory/otel-hook 0.6.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/cli.js CHANGED
@@ -1154,10 +1154,160 @@ var errorInfoFromThrown = (thrown, input) => {
1154
1154
  });
1155
1155
  };
1156
1156
 
1157
+ // src/config/otlp-endpoint.ts
1158
+ var OTLP_ENDPOINT_VARIABLES = Object.freeze({
1159
+ generic: "OTEL_EXPORTER_OTLP_ENDPOINT",
1160
+ traces: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
1161
+ logs: "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT"
1162
+ });
1163
+ var OTLP_TRACES_PATH = "/v1/traces";
1164
+ var OTLP_LOGS_PATH = "/v1/logs";
1165
+ var withoutTrailingSlashes = (value) => {
1166
+ let end = value.length;
1167
+ while (end > 0 && value.charCodeAt(end - 1) === 47) {
1168
+ end -= 1;
1169
+ }
1170
+ return value.slice(0, end);
1171
+ };
1172
+ var otlpSignalEndpointFromBase = (base, signal) => {
1173
+ const trimmed = withoutTrailingSlashes(base);
1174
+ if (trimmed.endsWith(OTLP_TRACES_PATH)) {
1175
+ return signal === "traces" ? trimmed : `${trimmed.slice(0, trimmed.length - OTLP_TRACES_PATH.length)}${OTLP_LOGS_PATH}`;
1176
+ }
1177
+ return `${trimmed}${signal === "traces" ? OTLP_TRACES_PATH : OTLP_LOGS_PATH}`;
1178
+ };
1179
+
1180
+ // src/config/otlp-headers.ts
1181
+ var MAX_OTLP_HEADERS = 32;
1182
+ var OTLP_HEADER_VARIABLES = Object.freeze({
1183
+ generic: "OTEL_EXPORTER_OTLP_HEADERS",
1184
+ traces: "OTEL_EXPORTER_OTLP_TRACES_HEADERS",
1185
+ logs: "OTEL_EXPORTER_OTLP_LOGS_HEADERS"
1186
+ });
1187
+ var HEADER_NAME_PATTERN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
1188
+ var isUnsafeHeaderValue = (value) => [...value].some((char) => {
1189
+ const code = char.codePointAt(0) ?? 0;
1190
+ return code < 32 && code !== 9 || code === 127 || code > 255;
1191
+ });
1192
+ var decode = (raw) => {
1193
+ try {
1194
+ return decodeURIComponent(raw);
1195
+ } catch {
1196
+ return void 0;
1197
+ }
1198
+ };
1199
+ var parseOtlpHeadersValue = (raw) => {
1200
+ const headers = {};
1201
+ const warnings = [];
1202
+ let overflowed = false;
1203
+ for (const [index, rawEntry] of raw.split(",").entries()) {
1204
+ const position = String(index + 1);
1205
+ const entry = rawEntry.trim();
1206
+ if (entry === "") {
1207
+ continue;
1208
+ }
1209
+ const equals = entry.indexOf("=");
1210
+ if (equals <= 0) {
1211
+ warnings.push(`entry ${position} is not a key=value pair; ignored`);
1212
+ continue;
1213
+ }
1214
+ const key = decode(entry.slice(0, equals).trim());
1215
+ const value = decode(entry.slice(equals + 1).trim());
1216
+ if (key === void 0 || value === void 0) {
1217
+ warnings.push(`entry ${position} has malformed percent-encoding; ignored`);
1218
+ continue;
1219
+ }
1220
+ const name = key.trim();
1221
+ const trimmedValue = value.trim();
1222
+ if (!HEADER_NAME_PATTERN.test(name)) {
1223
+ warnings.push(`entry ${position} does not name a valid HTTP header; ignored`);
1224
+ continue;
1225
+ }
1226
+ if (trimmedValue === "") {
1227
+ warnings.push(`entry ${position} has an empty value; ignored`);
1228
+ continue;
1229
+ }
1230
+ if (isUnsafeHeaderValue(trimmedValue)) {
1231
+ warnings.push(`entry ${position} has a character not allowed in an HTTP header value; ignored`);
1232
+ continue;
1233
+ }
1234
+ const existing = findHeaderName(headers, name);
1235
+ if (existing === void 0 && Object.keys(headers).length >= MAX_OTLP_HEADERS) {
1236
+ overflowed = true;
1237
+ continue;
1238
+ }
1239
+ if (existing !== void 0) {
1240
+ delete headers[existing];
1241
+ }
1242
+ headers[name] = trimmedValue;
1243
+ }
1244
+ if (overflowed) {
1245
+ warnings.push(`more than ${String(MAX_OTLP_HEADERS)} headers were supplied; the excess was ignored`);
1246
+ }
1247
+ return { headers, warnings };
1248
+ };
1249
+ var findHeaderName = (headers, name) => {
1250
+ const lower = name.toLowerCase();
1251
+ return Object.keys(headers).find((candidate) => candidate.toLowerCase() === lower);
1252
+ };
1253
+ var mergeOtlpHeaders = (...sources) => {
1254
+ const merged = {};
1255
+ for (const source of sources) {
1256
+ for (const [name, value] of Object.entries(source)) {
1257
+ const existing = findHeaderName(merged, name);
1258
+ if (existing !== void 0) {
1259
+ delete merged[existing];
1260
+ }
1261
+ merged[name] = value;
1262
+ }
1263
+ }
1264
+ return merged;
1265
+ };
1266
+ var resolveOtlpHeaders = (env, explicit = {}) => {
1267
+ const warnings = [];
1268
+ const read = (variable) => {
1269
+ const raw = env[variable];
1270
+ if (raw === void 0 || raw.trim() === "") {
1271
+ return {};
1272
+ }
1273
+ const parsed = parseOtlpHeadersValue(raw);
1274
+ for (const detail of parsed.warnings) {
1275
+ warnings.push({ variable, detail });
1276
+ }
1277
+ return parsed.headers;
1278
+ };
1279
+ const generic = read(OTLP_HEADER_VARIABLES.generic);
1280
+ const traces = read(OTLP_HEADER_VARIABLES.traces);
1281
+ const logs = read(OTLP_HEADER_VARIABLES.logs);
1282
+ return {
1283
+ traces: mergeOtlpHeaders(generic, traces, explicit),
1284
+ logs: mergeOtlpHeaders(generic, logs, explicit),
1285
+ warnings
1286
+ };
1287
+ };
1288
+ var unionOtlpHeaderNames = (...lists) => {
1289
+ const names = [];
1290
+ const seen = /* @__PURE__ */ new Set();
1291
+ for (const name of lists.flat()) {
1292
+ if (!seen.has(name.toLowerCase())) {
1293
+ seen.add(name.toLowerCase());
1294
+ names.push(name);
1295
+ }
1296
+ }
1297
+ return names.sort().slice(0, MAX_OTLP_HEADERS);
1298
+ };
1299
+ var describeOtlpHeaderNames = (...sources) => unionOtlpHeaderNames(...sources.map((source) => Object.keys(source)));
1300
+
1157
1301
  // src/config/environment.ts
1158
1302
  var ENVIRONMENT_VARIABLES = Object.freeze({
1159
1303
  exporterEnabled: "OTEL_HOOK_ENABLED",
1304
+ /** Full traces URL; otel-hook's own variable, above the standard ones. */
1160
1305
  exporterEndpoint: "OTEL_HOOK_EXPORTER_ENDPOINT",
1306
+ /**
1307
+ * Standard base URL: `/v1/traces` and `/v1/logs` are appended per signal. A
1308
+ * value already ending in `/v1/traces` is the legacy full traces URL and is
1309
+ * used as-is (see `otlpSignalEndpointFromBase`).
1310
+ */
1161
1311
  otlpEndpoint: "OTEL_EXPORTER_OTLP_ENDPOINT",
1162
1312
  exporterProtocol: "OTEL_HOOK_EXPORTER_PROTOCOL",
1163
1313
  exporterTimeoutMillis: "OTEL_HOOK_EXPORTER_TIMEOUT_MS",
@@ -1231,7 +1381,10 @@ var parseEnvironmentConfig = (env) => {
1231
1381
  return trimmed === "" ? void 0 : trimmed;
1232
1382
  };
1233
1383
  const exporterEnabled = readBoolean(ENVIRONMENT_VARIABLES.exporterEnabled);
1234
- const endpoint = readString(ENVIRONMENT_VARIABLES.exporterEndpoint) ?? readString(ENVIRONMENT_VARIABLES.otlpEndpoint);
1384
+ const hookEndpoint = readString(ENVIRONMENT_VARIABLES.exporterEndpoint);
1385
+ const otlpTracesEndpoint = readString(OTLP_ENDPOINT_VARIABLES.traces);
1386
+ const otlpBaseEndpoint = readString(ENVIRONMENT_VARIABLES.otlpEndpoint);
1387
+ const endpoint = hookEndpoint ?? otlpTracesEndpoint ?? (otlpBaseEndpoint === void 0 ? void 0 : otlpSignalEndpointFromBase(otlpBaseEndpoint, "traces"));
1235
1388
  const timeoutMillis = readInteger(ENVIRONMENT_VARIABLES.exporterTimeoutMillis);
1236
1389
  const resourceRaw = readString(ENVIRONMENT_VARIABLES.resourceAttributes);
1237
1390
  const resource = resourceRaw === void 0 ? void 0 : parseResourceAttributesValue(resourceRaw);
@@ -1317,17 +1470,23 @@ var parseEnvironmentConfig = (env) => {
1317
1470
  const maxEventsPerInvocation = readInteger(ENVIRONMENT_VARIABLES.maxEventsPerInvocation);
1318
1471
  const logsEnabled = readBoolean(ENVIRONMENT_VARIABLES.logsEnabled);
1319
1472
  const logsIncludeContent = readBoolean(ENVIRONMENT_VARIABLES.logsIncludeContent);
1320
- const logsEndpoint = readString(ENVIRONMENT_VARIABLES.logsEndpoint) ?? readString(ENVIRONMENT_VARIABLES.otlpLogsEndpoint);
1473
+ const logsEndpoint = readString(ENVIRONMENT_VARIABLES.logsEndpoint) ?? readString(ENVIRONMENT_VARIABLES.otlpLogsEndpoint) ?? (hookEndpoint === void 0 && otlpTracesEndpoint !== void 0 && otlpBaseEndpoint !== void 0 ? otlpSignalEndpointFromBase(otlpBaseEndpoint, "logs") : void 0);
1321
1474
  const logs = {
1322
1475
  ...logsEnabled === void 0 ? {} : { enabled: logsEnabled },
1323
1476
  ...logsEndpoint === void 0 ? {} : { endpoint: logsEndpoint },
1324
1477
  ...logsIncludeContent === void 0 ? {} : { includeContent: logsIncludeContent }
1325
1478
  };
1479
+ const otlpHeaders = resolveOtlpHeaders(env);
1480
+ for (const { variable, detail } of otlpHeaders.warnings) {
1481
+ warn(variable, detail);
1482
+ }
1483
+ const headerNames = describeOtlpHeaderNames(otlpHeaders.traces, otlpHeaders.logs);
1326
1484
  const exporter = {
1327
1485
  ...exporterEnabled === void 0 ? {} : { enabled: exporterEnabled },
1328
1486
  ...endpoint === void 0 ? {} : { endpoint },
1329
1487
  ...protocol === void 0 ? {} : { protocol },
1330
1488
  ...timeoutMillis === void 0 ? {} : { timeoutMillis },
1489
+ ...headerNames.length === 0 ? {} : { headerNames: [...headerNames] },
1331
1490
  ...serviceName === void 0 ? {} : { serviceName },
1332
1491
  ...serviceNamespace === void 0 ? {} : { serviceNamespace },
1333
1492
  ...Object.keys(resourceAttributes).length === 0 ? {} : { resourceAttributes },
@@ -1982,6 +2141,10 @@ var policyFlagsToPatch = (policy) => {
1982
2141
  ...Object.keys(diagnostics).length === 0 ? {} : { diagnostics }
1983
2142
  };
1984
2143
  };
2144
+ var resolveCliExporterHeaders = (policy, io) => {
2145
+ const { traces, logs } = resolveOtlpHeaders(io.env, policy.headers);
2146
+ return { traces, logs };
2147
+ };
1985
2148
  var readJsonFile = async (filePath) => {
1986
2149
  let raw;
1987
2150
  try {
@@ -2031,7 +2194,17 @@ var resolveCliConfig = async (policy, io) => {
2031
2194
  const environment = parseEnvironmentConfig(io.env);
2032
2195
  warnings.push(...environment.warnings);
2033
2196
  layers.push({ source: "environment", patch: environment.patch });
2034
- layers.push({ source: "inline-override", patch: policyFlagsToPatch(policy) });
2197
+ const inline = policyFlagsToPatch(policy);
2198
+ const environmentHeaderNames = environment.patch.exporter?.headerNames;
2199
+ const inlineHeaderNames = inline.exporter?.headerNames;
2200
+ const exporterPatch = environmentHeaderNames !== void 0 && inlineHeaderNames !== void 0 ? {
2201
+ ...inline.exporter,
2202
+ headerNames: [...unionOtlpHeaderNames(environmentHeaderNames, inlineHeaderNames)]
2203
+ } : inline.exporter;
2204
+ layers.push({
2205
+ source: "inline-override",
2206
+ patch: { ...inline, ...exporterPatch === void 0 ? {} : { exporter: exporterPatch } }
2207
+ });
2035
2208
  const resolution = resolveConfig(layers);
2036
2209
  if (resolution.status !== "ok") {
2037
2210
  warnings.push(...resolution.errors);
@@ -7594,27 +7767,8 @@ var createFileDurableSpool = (options) => createSpoolQueue({
7594
7767
 
7595
7768
  // src/telemetry/otlp-log-sink.ts
7596
7769
  import { TraceFlags as TraceFlags3 } from "@opentelemetry/api";
7597
-
7598
- // node_modules/@opentelemetry/core/build/esm/common/time.js
7599
- var NANOSECOND_DIGITS = 9;
7600
- var NANOSECOND_DIGITS_IN_MILLIS = 6;
7601
- var MILLISECONDS_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS_IN_MILLIS);
7602
- var SECOND_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS);
7603
- function millisToHrTime(epochMillis) {
7604
- const epochSeconds = epochMillis / 1e3;
7605
- const seconds = Math.trunc(epochSeconds);
7606
- const nanos = Math.round(epochMillis % 1e3 * MILLISECONDS_TO_NANOSECONDS);
7607
- return [seconds, nanos];
7608
- }
7609
-
7610
- // node_modules/@opentelemetry/core/build/esm/ExportResult.js
7611
- var ExportResultCode;
7612
- (function(ExportResultCode2) {
7613
- ExportResultCode2[ExportResultCode2["SUCCESS"] = 0] = "SUCCESS";
7614
- ExportResultCode2[ExportResultCode2["FAILED"] = 1] = "FAILED";
7615
- })(ExportResultCode || (ExportResultCode = {}));
7616
-
7617
- // src/telemetry/otlp-log-sink.ts
7770
+ import { ExportResultCode } from "@opentelemetry/core";
7771
+ import { millisToHrTime as millisToHrTime3 } from "@opentelemetry/core";
7618
7772
  import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto";
7619
7773
 
7620
7774
  // src/telemetry/exporter-resource.ts
@@ -7653,8 +7807,8 @@ var replayResource = (attributes, policy) => {
7653
7807
  };
7654
7808
 
7655
7809
  // src/telemetry/log-records.ts
7656
- import { TraceFlags as TraceFlags2 } from "@opentelemetry/api";
7657
- import { SeverityNumber } from "@opentelemetry/api-logs";
7810
+ import { SeverityNumber, TraceFlags as TraceFlags2 } from "@opentelemetry/api";
7811
+ import { millisToHrTime as millisToHrTime2 } from "@opentelemetry/core";
7658
7812
  import {
7659
7813
  ATTR_ERROR_TYPE as ATTR_ERROR_TYPE2,
7660
7814
  ATTR_GEN_AI_OPERATION_NAME as ATTR_GEN_AI_OPERATION_NAME2,
@@ -7682,7 +7836,10 @@ var ATTR_OTELHOOK_INVOCATION_ID = "otelhook.invocation.id";
7682
7836
  var ATTR_OTELHOOK_PROVIDER_ID = "otelhook.provider.id";
7683
7837
  var ATTR_OTELHOOK_PROVIDER_VERSION = "otelhook.provider.version";
7684
7838
  var ATTR_OTELHOOK_WORKSPACE_ID = "otelhook.workspace.id";
7685
- var HAR_SESSION_KEY = "har.session_key";
7839
+ var EXTERNAL_SESSION_KEY_ATTRIBUTES = Object.freeze([
7840
+ ATTR_SESSION_ID,
7841
+ "har.session_key"
7842
+ ]);
7686
7843
  var ATTR_OTELHOOK_SUBAGENT_ID = "otelhook.subagent.id";
7687
7844
  var ATTR_VCS_REF_HEAD_NAME = "vcs.ref.head.name";
7688
7845
  var ATTR_OTELHOOK_TARGET_WORKSPACE_ID = "otelhook.target.workspace.id";
@@ -7705,21 +7862,26 @@ var targetAttributes = (event3) => {
7705
7862
  };
7706
7863
  var usageTemporalityAttributes = (usage) => usage === void 0 ? {} : { [ATTR_OTELHOOK_USAGE_TEMPORALITY]: usage.temporality };
7707
7864
  var isPrimitiveAttribute = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean";
7708
- var passthroughHarAttributes = (resource) => {
7865
+ var PASSTHROUGH_RESOURCE_PREFIXES = Object.freeze(["har.", "factory.", "vcs."]);
7866
+ var LOCAL_ONLY_RESOURCE_PREFIX = "factory.local.";
7867
+ var isPassthroughKey = (key) => PASSTHROUGH_RESOURCE_PREFIXES.some((prefix) => key.startsWith(prefix)) && !key.startsWith(LOCAL_ONLY_RESOURCE_PREFIX) && key !== "factory.local";
7868
+ var passthroughResourceAttributes = (resource) => {
7709
7869
  const attributes = {};
7710
7870
  for (const [key, value] of Object.entries(resource.attributes)) {
7711
- if (key.startsWith("har.") && isPrimitiveAttribute(value)) {
7871
+ if (isPassthroughKey(key) && isPrimitiveAttribute(value)) {
7712
7872
  attributes[key] = value;
7713
7873
  }
7714
7874
  }
7715
7875
  return attributes;
7716
7876
  };
7717
7877
  var resolveExportedSessionId = (eventSessionId, resource) => {
7718
- const har = resource.attributes[HAR_SESSION_KEY];
7719
- if (typeof har === "string") {
7720
- const trimmed = har.trim();
7721
- if (trimmed.length > 0) {
7722
- return { sessionId: trimmed, providerSessionId: eventSessionId };
7878
+ for (const key of EXTERNAL_SESSION_KEY_ATTRIBUTES) {
7879
+ const supplied = resource.attributes[key];
7880
+ if (typeof supplied === "string") {
7881
+ const trimmed = supplied.trim();
7882
+ if (trimmed.length > 0) {
7883
+ return { sessionId: trimmed, providerSessionId: eventSessionId };
7884
+ }
7723
7885
  }
7724
7886
  }
7725
7887
  return { sessionId: eventSessionId, providerSessionId: eventSessionId };
@@ -7740,7 +7902,7 @@ var exportIdentityAttributes = (event3, resource, ids) => {
7740
7902
  ...event3.provenance.providerVersion === void 0 ? {} : { [ATTR_OTELHOOK_PROVIDER_VERSION]: event3.provenance.providerVersion },
7741
7903
  [ATTR_OTELHOOK_WORKSPACE_ID]: event3.workspace.workspaceId,
7742
7904
  ...event3.subagentId === void 0 ? {} : { [ATTR_OTELHOOK_SUBAGENT_ID]: event3.subagentId },
7743
- ...passthroughHarAttributes(resource),
7905
+ ...passthroughResourceAttributes(resource),
7744
7906
  ...hexTraceAttributes(ids)
7745
7907
  };
7746
7908
  };
@@ -7748,6 +7910,7 @@ var exportIdentityAttributes = (event3, resource, ids) => {
7748
7910
  // src/telemetry/semconv.ts
7749
7911
  import { createHash as createHash3 } from "crypto";
7750
7912
  import { SpanKind, SpanStatusCode, TraceFlags } from "@opentelemetry/api";
7913
+ import { millisToHrTime } from "@opentelemetry/core";
7751
7914
  import {
7752
7915
  ATTR_ERROR_TYPE,
7753
7916
  ATTR_GEN_AI_OPERATION_NAME,
@@ -7764,7 +7927,7 @@ import {
7764
7927
  } from "@opentelemetry/semantic-conventions/incubating";
7765
7928
 
7766
7929
  // src/version.ts
7767
- var VERSION = "0.6.0";
7930
+ var VERSION = "0.8.0";
7768
7931
 
7769
7932
  // src/telemetry/semconv.ts
7770
7933
  var SCOPE_NAME = "@osfactory/otel-hook";
@@ -7911,12 +8074,12 @@ var pickTarget = (attributes) => {
7911
8074
  }
7912
8075
  return picked;
7913
8076
  };
7914
- var withoutTarget = (attributes) => {
8077
+ var withoutTarget = (attributes, resource) => {
7915
8078
  const rest = { ...attributes };
7916
8079
  for (const key of TARGET_KEYS) {
7917
8080
  delete rest[key];
7918
8081
  }
7919
- return rest;
8082
+ return { ...rest, ...pickTarget(passthroughResourceAttributes(resource)) };
7920
8083
  };
7921
8084
  var rankOf = (candidate) => {
7922
8085
  const source = candidate[ATTR_OTELHOOK_TARGET_SOURCE];
@@ -8021,7 +8184,7 @@ var buildLifecycleSpan = (plan, resource, scope) => {
8021
8184
  name = "session";
8022
8185
  kind = SpanKind.INTERNAL;
8023
8186
  attributes = {
8024
- ...withoutTarget(attributes),
8187
+ ...withoutTarget(attributes, resource),
8025
8188
  ...strongestTarget([pickTarget(resolved.recovered), start === void 0 ? {} : targetAttributes(start)]),
8026
8189
  ...start?.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME]: start.agentName },
8027
8190
  ...start?.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION]: start.agentVersion },
@@ -8062,7 +8225,7 @@ var buildLifecycleSpan = (plan, resource, scope) => {
8062
8225
  kind = SpanKind.CLIENT;
8063
8226
  attributes = {
8064
8227
  // Target keys are re-chosen below as one unit, never mixed across edges.
8065
- ...withoutTarget(attributes),
8228
+ ...withoutTarget(attributes, resource),
8066
8229
  [ATTR_GEN_AI_TOOL_NAME]: toolName,
8067
8230
  [ATTR_GEN_AI_TOOL_CALL_ID]: start?.toolCallId ?? end?.toolCallId ?? group.ref.scopeKey,
8068
8231
  ...start?.toolKind === void 0 ? {} : { [ATTR_OTELHOOK_TOOL_KIND]: start.toolKind },
@@ -8548,14 +8711,14 @@ var contentAttributes = (fact, body) => ({
8548
8711
  });
8549
8712
  var buildRecord = (input) => {
8550
8713
  const severityNumber = severityFor(input.event);
8551
- const hrTime2 = millisToHrTime(input.event.occurredAt);
8714
+ const hrTime = millisToHrTime2(input.event.occurredAt);
8552
8715
  return {
8553
- hrTime: hrTime2,
8716
+ hrTime,
8554
8717
  // A hook observes an event that already happened, and this mapping is pure —
8555
8718
  // there is no clock here to read a real observation time from. Reporting the
8556
8719
  // occurrence time for both is the honest answer: it says "this is when it
8557
8720
  // happened" twice rather than inventing a second, wrong timestamp.
8558
- hrTimeObserved: hrTime2,
8721
+ hrTimeObserved: hrTime,
8559
8722
  spanContext: input.spanContext,
8560
8723
  severityNumber,
8561
8724
  severityText: SEVERITY_TEXT[severityNumber] ?? "INFO",
@@ -8645,15 +8808,6 @@ var canonicalEventsToLogRecords = (events, options) => {
8645
8808
  };
8646
8809
 
8647
8810
  // src/telemetry/otlp-log-sink.ts
8648
- var OTLP_TRACES_PATH = "/v1/traces";
8649
- var OTLP_LOGS_PATH = "/v1/logs";
8650
- var withoutTrailingSlashes = (value) => {
8651
- let end = value.length;
8652
- while (end > 0 && value.charCodeAt(end - 1) === 47) {
8653
- end -= 1;
8654
- }
8655
- return value.slice(0, end);
8656
- };
8657
8811
  var resolveLogsEndpoint = (exporter) => {
8658
8812
  if (exporter.logs.endpoint !== void 0) {
8659
8813
  return { endpoint: exporter.logs.endpoint, derived: false };
@@ -8707,8 +8861,8 @@ var deserializeRecord = (serialized, resource, scope) => {
8707
8861
  isRemote: false
8708
8862
  };
8709
8863
  return {
8710
- hrTime: millisToHrTime(serialized.timeMillis),
8711
- hrTimeObserved: millisToHrTime(serialized.observedTimeMillis),
8864
+ hrTime: millisToHrTime3(serialized.timeMillis),
8865
+ hrTimeObserved: millisToHrTime3(serialized.observedTimeMillis),
8712
8866
  ...spanContext === void 0 ? {} : { spanContext },
8713
8867
  severityNumber: serialized.severityNumber,
8714
8868
  ...serialized.severityText === void 0 ? {} : { severityText: serialized.severityText },
@@ -8923,6 +9077,7 @@ var createOtlpLogSink = (options) => {
8923
9077
  };
8924
9078
 
8925
9079
  // src/telemetry/otlp-sink.ts
9080
+ import { ExportResultCode as ExportResultCode2 } from "@opentelemetry/core";
8926
9081
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
8927
9082
  var chunk2 = (items, size) => {
8928
9083
  if (size <= 0 || items.length <= size) {
@@ -9010,7 +9165,7 @@ var createOtlpTraceSink = (options) => {
9010
9165
  const batchResource = replayResource(batch.resourceAttributes, options.exporter);
9011
9166
  const spans = batch.spans.map((span) => deserializeSpan(span, batchResource, batch.instrumentationScope));
9012
9167
  const result = await exportSpans(spans);
9013
- return result.code === ExportResultCode.SUCCESS;
9168
+ return result.code === ExportResultCode2.SUCCESS;
9014
9169
  };
9015
9170
  const resolveCorrelations = async (events) => {
9016
9171
  if (options.correlate === void 0) {
@@ -9042,9 +9197,9 @@ var createOtlpTraceSink = (options) => {
9042
9197
  try {
9043
9198
  result = await exportSpans(batch);
9044
9199
  } catch (thrown) {
9045
- result = { code: ExportResultCode.FAILED, error: thrown instanceof Error ? thrown : new Error("export threw") };
9200
+ result = { code: ExportResultCode2.FAILED, error: thrown instanceof Error ? thrown : new Error("export threw") };
9046
9201
  }
9047
- if (result.code === ExportResultCode.SUCCESS) {
9202
+ if (result.code === ExportResultCode2.SUCCESS) {
9048
9203
  accepted += batch.length;
9049
9204
  health.recordSuccess(batch.length, options.clock.now());
9050
9205
  continue;
@@ -9178,9 +9333,10 @@ var collectDoctorReport = async (command, io) => {
9178
9333
  }
9179
9334
  }
9180
9335
  }
9336
+ const traceHeaders = resolveCliExporterHeaders(command.policy, io).traces;
9181
9337
  const sink = createOtlpTraceSink({
9182
9338
  exporter: resolved.config.exporter,
9183
- ...Object.keys(command.policy.headers).length === 0 ? {} : { headers: command.policy.headers },
9339
+ ...Object.keys(traceHeaders).length === 0 ? {} : { headers: traceHeaders },
9184
9340
  providerId: DOCTOR_STATE_NAMESPACE,
9185
9341
  installationId,
9186
9342
  clock,
@@ -12793,9 +12949,10 @@ var createHookRuntime = (options) => {
12793
12949
  ...spool === void 0 ? {} : { spool },
12794
12950
  correlate
12795
12951
  });
12952
+ const logHeaders = options.logHeaders ?? options.headers;
12796
12953
  const logSink = createOtlpLogSink({
12797
12954
  exporter: options.config.exporter,
12798
- ...options.headers === void 0 ? {} : { headers: options.headers },
12955
+ ...logHeaders === void 0 ? {} : { headers: logHeaders },
12799
12956
  providerId: options.providerNamespace,
12800
12957
  installationId: options.installationId,
12801
12958
  clock,
@@ -13395,6 +13552,7 @@ var runHookCommand = async (command, io) => {
13395
13552
  const fromFlags = claimFromIdentityFlags(command.identity);
13396
13553
  logDiagnostics(logger, fromFlags.errors);
13397
13554
  identityClaims.push(...fromFlags.claims);
13555
+ const headers = resolveCliExporterHeaders(command.policy, io);
13398
13556
  const runtime = createHookRuntime({
13399
13557
  // Detection policy narrowed to the selected adapter; everything else is the
13400
13558
  // resolved configuration exactly as it stands.
@@ -13403,7 +13561,8 @@ var runHookCommand = async (command, io) => {
13403
13561
  stateRootDir: resolveStateRootDir(command.policy, io),
13404
13562
  installationId: resolveInstallationId(command.policy, io),
13405
13563
  providerNamespace: selection.namespace,
13406
- ...Object.keys(command.policy.headers).length === 0 ? {} : { headers: command.policy.headers },
13564
+ ...Object.keys(headers.traces).length === 0 ? {} : { headers: headers.traces },
13565
+ ...Object.keys(headers.logs).length === 0 ? {} : { logHeaders: headers.logs },
13407
13566
  clock,
13408
13567
  ids,
13409
13568
  logger,