@osfactory/otel-hook 0.13.1 → 0.14.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.
Files changed (41) hide show
  1. package/README.md +94 -3
  2. package/dist/{adapter-DyCb7y1N.d.ts → adapter-D5R8lhfl.d.ts} +1 -1
  3. package/dist/cli.js +1240 -200
  4. package/dist/cli.js.map +1 -1
  5. package/dist/config.d.ts +32 -4
  6. package/dist/config.js +200 -14
  7. package/dist/config.js.map +1 -1
  8. package/dist/{destinations-DvqsPulb.d.ts → destinations-2KrcRslo.d.ts} +92 -2
  9. package/dist/{export-destinations-DUeQKr_C.d.ts → export-destinations-DvoH4QOe.d.ts} +135 -11
  10. package/dist/{hook-D5imE0Qc.d.ts → hook-DVK8Don-.d.ts} +4 -4
  11. package/dist/index.d.ts +11 -11
  12. package/dist/index.js +1262 -228
  13. package/dist/index.js.map +1 -1
  14. package/dist/install.d.ts +3 -3
  15. package/dist/install.js +1 -0
  16. package/dist/install.js.map +1 -1
  17. package/dist/integration.d.ts +16 -9
  18. package/dist/integration.js +1298 -205
  19. package/dist/integration.js.map +1 -1
  20. package/dist/lifecycle.js +1 -1
  21. package/dist/lifecycle.js.map +1 -1
  22. package/dist/{payload-CdDKeRpH.d.ts → payload-D4r71EL-.d.ts} +18 -2
  23. package/dist/privacy.d.ts +2 -2
  24. package/dist/privacy.js +42 -1
  25. package/dist/privacy.js.map +1 -1
  26. package/dist/providers.d.ts +94 -9
  27. package/dist/providers.js +300 -2
  28. package/dist/providers.js.map +1 -1
  29. package/dist/{registry-BKQhhIO3.d.ts → registry-DOJh9mzB.d.ts} +2 -2
  30. package/dist/runtime.d.ts +5 -5
  31. package/dist/runtime.js +151 -5
  32. package/dist/runtime.js.map +1 -1
  33. package/dist/{schema-SpFM6YQY.d.ts → schema-oRsbo7WO.d.ts} +77 -3
  34. package/dist/{service-CbI9CObT.d.ts → service-DySC7KQM.d.ts} +6 -1
  35. package/dist/telemetry.d.ts +5 -4
  36. package/dist/telemetry.js +1076 -476
  37. package/dist/telemetry.js.map +1 -1
  38. package/dist/testing.d.ts +5 -5
  39. package/dist/testing.js +178 -21
  40. package/dist/testing.js.map +1 -1
  41. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
- import { g as DetectionPolicy } from './schema-SpFM6YQY.js';
1
+ import { i as DetectionPolicy } from './schema-oRsbo7WO.js';
2
2
  import { OtelHookErrorInfo } from './errors.js';
3
- import { P as ProviderAdapter, h as ProviderDetection, i as ProviderDetectionInput, e as ProviderContext } from './adapter-DyCb7y1N.js';
3
+ import { P as ProviderAdapter, h as ProviderDetection, i as ProviderDetectionInput, e as ProviderContext } from './adapter-D5R8lhfl.js';
4
4
 
5
5
  type DetectionCandidate = {
6
6
  readonly adapter: ProviderAdapter;
package/dist/runtime.d.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  import { c as LogLevel, d as Logger, W as WorktreeLocator, S as SessionContextReader, h as SessionContextSegment } from './ports-DhpSDIkp.js';
2
2
  export { A as AppliedDelivery, C as Clock, E as EventIdSeed, I as IdGenerator, a as InvocationIdSeed, L as LOG_LEVEL_RANK, b as LocatedWorktree, P as PayloadEnricher, e as PayloadEnrichment, f as PayloadEnrichmentInput, R as ReadCursor, g as SessionContextRequest, i as StateRecord, j as StateStore, k as StateValue, T as TelemetryEmitResult, l as TelemetrySink, m as appliedDeliverySchema, n as logLevelSchema, s as stateRecordSchema, o as stateValueSchema } from './ports-DhpSDIkp.js';
3
3
  export { D as DeterministicIdOptions, F as FixedClock, a as FixedClockOptions, I as InMemoryStateStore, b as InMemoryStateStoreOptions, L as LogRecord, R as RecordingLogger, c as RecordingTelemetrySink, d as RecordingTelemetrySinkOptions, e as createDeterministicIdGenerator, f as createFixedClock, g as createInMemoryStateStore, h as createNullTelemetrySink, i as createRandomIdGenerator, j as createRecordingLogger, k as createRecordingTelemetrySink, l as createSystemClock } from './memory-B3r6sZtC.js';
4
- export { C as CumulativeUsageSeries, D as DeliveryDurability, a as DeliveryOrigin, b as DeliveryResolution, c as DeliveryUnavailableReason, H as HookIngestInput, d as HookIngestOptions, e as HookIngestOutcome, O as OtelHook, f as OtelHookDependencies, R as ResolvedDeliveryIdentity, U as UsageObservation, g as UsageScope, h as classifyDurability, i as createOtelHook, j as hostDeliveryIdentity, k as isCommittable, r as resolveDeliveryIdentity, u as usageScopeSchema } from './hook-D5imE0Qc.js';
4
+ export { C as CumulativeUsageSeries, D as DeliveryDurability, a as DeliveryOrigin, b as DeliveryResolution, c as DeliveryUnavailableReason, H as HookIngestInput, d as HookIngestOptions, e as HookIngestOutcome, O as OtelHook, f as OtelHookDependencies, R as ResolvedDeliveryIdentity, U as UsageObservation, g as UsageScope, h as classifyDurability, i as createOtelHook, j as hostDeliveryIdentity, k as isCommittable, r as resolveDeliveryIdentity, u as usageScopeSchema } from './hook-DVK8Don-.js';
5
5
  import { b as CanonicalEvent, u as TargetHint } from './events-fcomX6d5.js';
6
6
  import { d as EventId } from './primitives-CJ8-rn-f.js';
7
- import { P as PrivacyService } from './service-CbI9CObT.js';
7
+ import { P as PrivacyService } from './service-DySC7KQM.js';
8
8
  import 'zod';
9
9
  import './errors.js';
10
10
  import './taxonomy-DwhTtuWd.js';
11
- import './schema-SpFM6YQY.js';
11
+ import './schema-oRsbo7WO.js';
12
12
  import './identity-BrVBs901.js';
13
- import './adapter-DyCb7y1N.js';
13
+ import './adapter-D5R8lhfl.js';
14
14
  import './policy-CimmCfRp.js';
15
15
  import './content-M9xIKG7h.js';
16
- import './registry-BKQhhIO3.js';
16
+ import './registry-DOJh9mzB.js';
17
17
 
18
18
  declare const createNullLogger: () => Logger;
19
19
  type StderrLoggerOptions = {
package/dist/runtime.js CHANGED
@@ -1471,6 +1471,59 @@ var OTLP_HEADER_VARIABLES = Object.freeze({
1471
1471
  logs: "OTEL_EXPORTER_OTLP_LOGS_HEADERS"
1472
1472
  });
1473
1473
 
1474
+ // src/config/repository-key.ts
1475
+ var MAX_REPOSITORY_REFERENCE_LENGTH = 2048;
1476
+ var SCHEME_PATTERN = /^[a-z][a-z0-9+.-]*:\/\//i;
1477
+ var SCP_LIKE_PATTERN = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/\/)(.+)$/;
1478
+ var trimTrailingSlashes = (value) => {
1479
+ let end = value.length;
1480
+ while (end > 0 && value.charCodeAt(end - 1) === 47) end -= 1;
1481
+ return value.slice(0, end);
1482
+ };
1483
+ var keyOf = (host, pathname) => {
1484
+ const withoutSlashes = trimTrailingSlashes(pathname);
1485
+ const cleanedPath = trimTrailingSlashes(
1486
+ withoutSlashes.toLowerCase().endsWith(".git") ? withoutSlashes.slice(0, -4) : withoutSlashes
1487
+ );
1488
+ if (host.length === 0 || cleanedPath.length === 0 || cleanedPath === "/") {
1489
+ return void 0;
1490
+ }
1491
+ const withSlash = cleanedPath.startsWith("/") ? cleanedPath : `/${cleanedPath}`;
1492
+ return `${host}${withSlash}`.toLowerCase();
1493
+ };
1494
+ var normalizeRepositoryKey = (reference) => {
1495
+ const trimmed = reference.trim();
1496
+ if (trimmed.length === 0 || trimmed.length > MAX_REPOSITORY_REFERENCE_LENGTH) {
1497
+ return void 0;
1498
+ }
1499
+ if (SCHEME_PATTERN.test(trimmed)) {
1500
+ let url;
1501
+ try {
1502
+ url = new URL(trimmed);
1503
+ } catch {
1504
+ return void 0;
1505
+ }
1506
+ if (url.protocol === "file:") {
1507
+ return void 0;
1508
+ }
1509
+ return keyOf(url.hostname, url.pathname);
1510
+ }
1511
+ if (trimmed.startsWith("/") || trimmed.startsWith(".") || trimmed.includes("\\")) {
1512
+ return void 0;
1513
+ }
1514
+ const scp = SCP_LIKE_PATTERN.exec(trimmed);
1515
+ if (scp !== null && !trimmed.split(":")[0]?.includes("/")) {
1516
+ const [, host, pathPart] = scp;
1517
+ return host === void 0 || pathPart === void 0 ? void 0 : keyOf(host, pathPart);
1518
+ }
1519
+ try {
1520
+ const url = new URL(`https://${trimmed}`);
1521
+ return keyOf(url.hostname, url.pathname);
1522
+ } catch {
1523
+ return void 0;
1524
+ }
1525
+ };
1526
+
1474
1527
  // src/config/destinations.ts
1475
1528
  var DEFAULT_DESTINATION_NAME = "default";
1476
1529
  var DESTINATION_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,62}$/;
@@ -1489,6 +1542,30 @@ var headerValueSchema = z13.string().min(1).max(MAX_HEADER_VALUE_LENGTH).refine(
1489
1542
  "an env: header reference must name an environment variable, e.g. env:COLLECTOR_TOKEN"
1490
1543
  );
1491
1544
  var endpointSchema = z13.string().url().max(2048);
1545
+ var MAX_DESTINATION_SCOPES = 64;
1546
+ var MAX_SCOPE_REPOSITORIES = 256;
1547
+ var ALL_REPOSITORIES = "*";
1548
+ var repositoryReferenceSchema = z13.string().min(1).max(MAX_REPOSITORY_REFERENCE_LENGTH).refine(
1549
+ (value) => normalizeRepositoryKey(value) !== void 0,
1550
+ "not a repository URL: use https://host/owner/repo, git@host:owner/repo.git, or host/owner/repo"
1551
+ );
1552
+ var destinationScopeSchema = z13.strictObject({
1553
+ /**
1554
+ * Repository URLs (any spelling of the remote; compared by host and path,
1555
+ * case-insensitively, without `.git`), or `"*"` for every record that names
1556
+ * a repository. A record that names none never matches a scope.
1557
+ */
1558
+ repositories: z13.union([
1559
+ z13.literal(ALL_REPOSITORIES),
1560
+ z13.array(repositoryReferenceSchema).min(1).max(MAX_SCOPE_REPOSITORIES).readonly()
1561
+ ]),
1562
+ /** Signals sent for these repositories. Default: every signal the destination takes. */
1563
+ signals: z13.array(exportSignalSchema).min(1).max(3).readonly().optional(),
1564
+ /** Content disclosure for these repositories, never above `privacy.contentMode`. Default: unchanged. */
1565
+ contentMode: contentModeSchema.optional(),
1566
+ /** False leaves `session.id` off metric data points for these repositories. Default true. */
1567
+ includeSessionId: z13.boolean().optional()
1568
+ });
1492
1569
  var exportDestinationSchema = z13.strictObject({
1493
1570
  /** Unique, lowercase, filesystem-safe. `default` is reserved for the single-endpoint settings. */
1494
1571
  name: z13.string().regex(DESTINATION_NAME_PATTERN, "destination names are lowercase letters, digits, _ and -"),
@@ -1522,7 +1599,15 @@ var exportDestinationSchema = z13.strictObject({
1522
1599
  * opt-in for content-bearing records leaving the host. `metrics` is never on by
1523
1600
  * default: a destination receives hook-derived metrics only when it lists them.
1524
1601
  */
1525
- signals: z13.array(exportSignalSchema).min(1).max(3).readonly().optional()
1602
+ signals: z13.array(exportSignalSchema).min(1).max(3).readonly().optional(),
1603
+ /**
1604
+ * Per-repository filter. Absent: every record goes to this destination, as
1605
+ * before scopes existed. Present: a record goes only when its repository
1606
+ * (`vcs.repository.url.full`) matches a scope — the first matching scope
1607
+ * decides its signals, content mode, and session id — and a record that
1608
+ * names no repository is not sent here at all.
1609
+ */
1610
+ scopes: z13.array(destinationScopeSchema).min(1).max(MAX_DESTINATION_SCOPES).readonly().optional()
1526
1611
  }).refine(
1527
1612
  (destination) => destination.endpoint !== void 0 || destination.tracesEndpoint !== void 0 || destination.logsEndpoint !== void 0 || destination.metricsEndpoint !== void 0,
1528
1613
  "a destination needs an endpoint, or a tracesEndpoint / logsEndpoint / metricsEndpoint"
@@ -1715,7 +1800,22 @@ var exporterPolicySchema = z15.strictObject({
1715
1800
  * Per-destination retry spool bounds, each optional and merged per leaf; any
1716
1801
  * bound left unset takes its value from `DEFAULT_SPOOL_POLICY`.
1717
1802
  */
1718
- spool: spoolPolicySchema.partial().optional()
1803
+ spool: spoolPolicySchema.partial().optional(),
1804
+ /**
1805
+ * The most time one hook invocation spends trying to reach one endpoint, in
1806
+ * milliseconds: caps `timeoutMillis` for every OTLP request (connection setup
1807
+ * included) and the exporter's own retries inside it. A batch that does not
1808
+ * get through in time is spooled. Default {@link DEFAULT_EXPORT_BUDGET_MILLIS}:
1809
+ * the host agent waits for its hooks, so a down collector must not stall it.
1810
+ */
1811
+ exportBudgetMillis: z15.number().int().min(50).max(6e5).optional(),
1812
+ /**
1813
+ * After an endpoint was unreachable (refused, timed out, or answered a
1814
+ * retryable status), every hook spools for it without trying for this long,
1815
+ * in milliseconds; then one hook probes it again. 0 disables the window.
1816
+ * Default {@link DEFAULT_ENDPOINT_DOWN_MILLIS}.
1817
+ */
1818
+ endpointDownMillis: z15.number().int().min(0).max(36e5).optional()
1719
1819
  });
1720
1820
  var detectionPolicySchema = z15.strictObject({
1721
1821
  /** Detections below this confidence resolve to the unknown provider. */
@@ -1733,6 +1833,9 @@ var diagnosticsPolicySchema = z15.strictObject({
1733
1833
  var providersPolicySchema = z15.strictObject({
1734
1834
  claudeCode: z15.strictObject({
1735
1835
  readTranscriptUsage: z15.boolean()
1836
+ }).optional(),
1837
+ codex: z15.strictObject({
1838
+ readRolloutUsage: z15.boolean()
1736
1839
  }).optional()
1737
1840
  });
1738
1841
  var sessionContextPolicySchema = z15.strictObject({
@@ -1762,7 +1865,8 @@ var otelHookConfigPatchSchema = z15.strictObject({
1762
1865
  detection: detectionPolicySchema.partial().optional(),
1763
1866
  diagnostics: diagnosticsPolicySchema.partial().optional(),
1764
1867
  providers: z15.strictObject({
1765
- claudeCode: z15.strictObject({ readTranscriptUsage: z15.boolean() }).partial().optional()
1868
+ claudeCode: z15.strictObject({ readTranscriptUsage: z15.boolean() }).partial().optional(),
1869
+ codex: z15.strictObject({ readRolloutUsage: z15.boolean() }).partial().optional()
1766
1870
  }).partial().optional(),
1767
1871
  sessionContext: sessionContextPolicySchema.partial().optional()
1768
1872
  });
@@ -1789,7 +1893,8 @@ var DEFAULT_DIAGNOSTICS_POLICY = Object.freeze({
1789
1893
  emitErrorEvents: true
1790
1894
  });
1791
1895
  var DEFAULT_PROVIDERS_POLICY = Object.freeze({
1792
- claudeCode: Object.freeze({ readTranscriptUsage: false })
1896
+ claudeCode: Object.freeze({ readTranscriptUsage: false }),
1897
+ codex: Object.freeze({ readRolloutUsage: false })
1793
1898
  });
1794
1899
  var DEFAULT_CONFIG = Object.freeze({
1795
1900
  exporter: DEFAULT_EXPORTER_POLICY,
@@ -1801,6 +1906,23 @@ var DEFAULT_CONFIG = Object.freeze({
1801
1906
 
1802
1907
  // src/privacy/service.ts
1803
1908
  import { createHash as createHash2 } from "crypto";
1909
+ var DISCLOSURE_RANK = Object.freeze({
1910
+ omitted: 0,
1911
+ masked: 1,
1912
+ redacted: 2,
1913
+ raw: 3
1914
+ });
1915
+ var WHITESPACE = /\s/u;
1916
+ var withoutTrailingToken = (text) => {
1917
+ let end = text.length;
1918
+ while (end > 0) {
1919
+ const low = text.charCodeAt(end - 1);
1920
+ const width = end >= 2 && low >= 56320 && low <= 57343 ? 2 : 1;
1921
+ if (WHITESPACE.test(text.slice(end - width, end))) break;
1922
+ end -= width;
1923
+ }
1924
+ return text.slice(0, end);
1925
+ };
1804
1926
  var compilePatterns = (sources, flags) => {
1805
1927
  const compiled = [];
1806
1928
  for (const source of sources) {
@@ -2138,7 +2260,31 @@ var createPrivacyService = (policyInput) => {
2138
2260
  flattenToAttributes,
2139
2261
  sanitizeAttributes,
2140
2262
  sanitizeExtensions,
2141
- boundString
2263
+ boundString,
2264
+ restrictContent: (fact, mode) => {
2265
+ const target = CONTENT_MODE_DISCLOSURE[mode];
2266
+ if (fact.text === void 0 || DISCLOSURE_RANK[fact.disclosure] <= DISCLOSURE_RANK[target]) {
2267
+ return fact;
2268
+ }
2269
+ const { text, ...rest } = fact;
2270
+ switch (target) {
2271
+ case "omitted":
2272
+ return { ...rest, disclosure: "omitted", truncated: false };
2273
+ case "masked":
2274
+ return { ...rest, disclosure: "masked", text: maskText(text) };
2275
+ case "redacted": {
2276
+ const redacted = redactSecretSpans(fact.truncated ? withoutTrailingToken(text) : text);
2277
+ return {
2278
+ ...rest,
2279
+ disclosure: "redacted",
2280
+ text: redacted.text,
2281
+ secretsRedacted: fact.secretsRedacted + redacted.count
2282
+ };
2283
+ }
2284
+ case "raw":
2285
+ return fact;
2286
+ }
2287
+ }
2142
2288
  };
2143
2289
  };
2144
2290