@osfactory/otel-hook 0.14.0 → 0.14.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.
Files changed (37) hide show
  1. package/README.md +17 -3
  2. package/dist/{adapter-D5R8lhfl.d.ts → adapter-But5fFCk.d.ts} +8 -1
  3. package/dist/cli.js +210 -45
  4. package/dist/cli.js.map +1 -1
  5. package/dist/{export-destinations-DvoH4QOe.d.ts → export-destinations-8tNkIC8a.d.ts} +12 -4
  6. package/dist/{filesystem-store-B3CpiIRl.d.ts → filesystem-store-Z8XgDtFj.d.ts} +1 -1
  7. package/dist/{hook-DVK8Don-.d.ts → hook-D7XABd4f.d.ts} +17 -3
  8. package/dist/index.d.ts +10 -10
  9. package/dist/index.js +211 -45
  10. package/dist/index.js.map +1 -1
  11. package/dist/install.d.ts +3 -3
  12. package/dist/install.js.map +1 -1
  13. package/dist/integration.d.ts +6 -6
  14. package/dist/integration.js +188 -40
  15. package/dist/integration.js.map +1 -1
  16. package/dist/lifecycle.d.ts +1 -1
  17. package/dist/lifecycle.js +1 -1
  18. package/dist/lifecycle.js.map +1 -1
  19. package/dist/{memory-B3r6sZtC.d.ts → memory-gipZUiXP.d.ts} +1 -1
  20. package/dist/{payload-D4r71EL-.d.ts → payload-DWdx9yk3.d.ts} +1 -1
  21. package/dist/{ports-DhpSDIkp.d.ts → ports-qZTwK-z2.d.ts} +22 -2
  22. package/dist/providers.d.ts +7 -7
  23. package/dist/providers.js +22 -5
  24. package/dist/providers.js.map +1 -1
  25. package/dist/{registry-DOJh9mzB.d.ts → registry-D9rmMYxw.d.ts} +1 -1
  26. package/dist/runtime.d.ts +22 -7
  27. package/dist/runtime.js +154 -28
  28. package/dist/runtime.js.map +1 -1
  29. package/dist/state.d.ts +3 -3
  30. package/dist/state.js.map +1 -1
  31. package/dist/telemetry.d.ts +2 -2
  32. package/dist/telemetry.js +26 -9
  33. package/dist/telemetry.js.map +1 -1
  34. package/dist/testing.d.ts +6 -6
  35. package/dist/testing.js +57 -8
  36. package/dist/testing.js.map +1 -1
  37. package/package.json +1 -1
@@ -3,11 +3,11 @@ import { OverallHealth } from './diagnostics.js';
3
3
  import { OtelHookErrorInfo } from './errors.js';
4
4
  import { DeliveryClaimOutcome, UsageAccumulatorSnapshot, LifecycleCleanupReport, CallbackDeduplicator, UsageAccumulator, SpanCorrelator, MetricSeriesStore, LifecycleJanitor } from './lifecycle.js';
5
5
  import { P as PrivacyService } from './service-DySC7KQM.js';
6
- import { P as ProviderRegistry } from './registry-DOJh9mzB.js';
7
- import { a as DeliveryOrigin, c as DeliveryUnavailableReason, H as HookIngestInput, e as HookIngestOutcome, U as UsageObservation, O as OtelHook } from './hook-DVK8Don-.js';
8
- import { C as Clock, I as IdGenerator, d as Logger, W as WorktreeLocator, P as PayloadEnricher, S as SessionContextReader } from './ports-DhpSDIkp.js';
9
- import { F as FilesystemStateStore } from './filesystem-store-B3CpiIRl.js';
10
- import { y as OtlpTelemetrySink, v as OtlpLogTelemetrySink, f as DurableSpool, b as DurableLogSpool, E as ExportDestinationSinks, I as SkippedExportDestination } from './export-destinations-DvoH4QOe.js';
6
+ import { P as ProviderRegistry } from './registry-D9rmMYxw.js';
7
+ import { a as DeliveryOrigin, c as DeliveryUnavailableReason, H as HookIngestInput, e as HookIngestOutcome, U as UsageObservation, O as OtelHook } from './hook-D7XABd4f.js';
8
+ import { C as Clock, I as IdGenerator, d as Logger, W as WorktreeLocator, P as PayloadEnricher, S as SessionContextReader } from './ports-qZTwK-z2.js';
9
+ import { F as FilesystemStateStore } from './filesystem-store-Z8XgDtFj.js';
10
+ import { y as OtlpTelemetrySink, v as OtlpLogTelemetrySink, f as DurableSpool, b as DurableLogSpool, E as ExportDestinationSinks, I as SkippedExportDestination } from './export-destinations-8tNkIC8a.js';
11
11
  import 'zod';
12
12
  import './primitives-CJ8-rn-f.js';
13
13
  import './taxonomy-DwhTtuWd.js';
@@ -19,7 +19,7 @@ import '@opentelemetry/resources';
19
19
  import '@opentelemetry/sdk-trace';
20
20
  import './content-M9xIKG7h.js';
21
21
  import './policy-CimmCfRp.js';
22
- import './adapter-D5R8lhfl.js';
22
+ import './adapter-But5fFCk.js';
23
23
  import './identity-BrVBs901.js';
24
24
  import './keys-Dej5bN3L.js';
25
25
  import './destinations-2KrcRslo.js';
@@ -2557,7 +2557,7 @@ import {
2557
2557
  } from "@opentelemetry/semantic-conventions/incubating";
2558
2558
 
2559
2559
  // src/version.ts
2560
- var VERSION = "0.14.0";
2560
+ var VERSION = "0.14.1";
2561
2561
 
2562
2562
  // src/telemetry/semconv.ts
2563
2563
  var SCOPE_NAME = "@osfactory/otel-hook";
@@ -5856,6 +5856,28 @@ var classifyDurability = (input) => {
5856
5856
  };
5857
5857
  var isCommittable = (durability) => durability !== "lost";
5858
5858
  var MAX_ERROR_EVENTS = 8;
5859
+ var resolveWorkspaceRepositoryKey = async (locator, directory, budgetMillis) => {
5860
+ if (locator?.originRepositoryKey === void 0) {
5861
+ return void 0;
5862
+ }
5863
+ let timer;
5864
+ const deadline = new Promise((resolve3) => {
5865
+ timer = setTimeout(() => resolve3(void 0), Math.max(0, budgetMillis));
5866
+ timer.unref?.();
5867
+ });
5868
+ try {
5869
+ return await Promise.race([
5870
+ locator.originRepositoryKey(directory).catch(() => void 0),
5871
+ deadline
5872
+ ]);
5873
+ } catch {
5874
+ return void 0;
5875
+ } finally {
5876
+ if (timer !== void 0) {
5877
+ clearTimeout(timer);
5878
+ }
5879
+ }
5880
+ };
5859
5881
  var collectContentFacts = (event2) => {
5860
5882
  const facts = [];
5861
5883
  const push = (fact) => {
@@ -6499,7 +6521,8 @@ var createOtelHook = (deps) => {
6499
6521
  kind: "ready",
6500
6522
  batch: batch2,
6501
6523
  dropped: screened.dropped,
6502
- ...parsed.targetHints === void 0 ? {} : { targetHints: parsed.targetHints }
6524
+ ...parsed.targetHints === void 0 ? {} : { targetHints: parsed.targetHints },
6525
+ ...parsed.workspaceDirectory === void 0 ? {} : { workspaceDirectory: parsed.workspaceDirectory }
6503
6526
  };
6504
6527
  };
6505
6528
  let prepared;
@@ -6567,11 +6590,19 @@ var createOtelHook = (deps) => {
6567
6590
  batch,
6568
6591
  !suppress && batch.length > 0 && deps.sessionContext !== void 0 ? await readSessionContext(deps.sessionContext, detection.providerId, identity.sessionId) : void 0
6569
6592
  );
6593
+ const workspaceRepositoryKey = !suppress && batch.length > 0 && deps.routeByWorkspaceRepository === true && prepared.workspaceDirectory !== void 0 ? await resolveWorkspaceRepositoryKey(
6594
+ deps.worktreeLocator,
6595
+ prepared.workspaceDirectory,
6596
+ deps.targetResolutionBudgetMillis ?? DEFAULT_TARGET_RESOLUTION_BUDGET_MILLIS
6597
+ ) : void 0;
6570
6598
  let emitted = 0;
6571
6599
  let exportRejected = 0;
6572
6600
  if (!suppress && batch.length > 0) {
6573
6601
  try {
6574
- const result = await deps.sink.emit(batch);
6602
+ const result = await deps.sink.emit(
6603
+ batch,
6604
+ workspaceRepositoryKey === void 0 ? void 0 : { workspaceRepositoryKey }
6605
+ );
6575
6606
  emitted = result.accepted;
6576
6607
  exportRejected = result.rejected;
6577
6608
  diagnostics.push(...result.errors);
@@ -6630,7 +6661,8 @@ var createOtelHook = (deps) => {
6630
6661
  durability,
6631
6662
  dropped,
6632
6663
  hookResponse: hookResponseFor(adapter, detection, "attributed", void 0, emitted, diagnostics),
6633
- diagnostics
6664
+ diagnostics,
6665
+ ...workspaceRepositoryKey === void 0 ? {} : { workspaceRepositoryKey }
6634
6666
  };
6635
6667
  } catch (thrown) {
6636
6668
  const info = errorInfoFromThrown(thrown, { code: "internal-error", phase: "parsing" });
@@ -6729,15 +6761,16 @@ var MAX_WORKTREE_WALK_DEPTH = 128;
6729
6761
  var MAX_GIT_FILE_BYTES = 4096;
6730
6762
  var MAX_CACHE_ENTRIES = 1024;
6731
6763
  var DEFAULT_WORKTREE_CACHE_TTL_MILLIS = 5e3;
6764
+ var MAX_GIT_CONFIG_BYTES = 64 * 1024;
6732
6765
  var MAX_BRANCH_NAME_LENGTH = 255;
6733
6766
  var ABSENT = Object.freeze({ kind: "absent" });
6734
6767
  var INVALID = Object.freeze({ kind: "invalid" });
6735
- var readBounded2 = async (filePath) => {
6768
+ var readBounded2 = async (filePath, maxBytes = MAX_GIT_FILE_BYTES) => {
6736
6769
  let handle;
6737
6770
  try {
6738
6771
  handle = await open4(filePath, "r");
6739
- const buffer = Buffer.alloc(MAX_GIT_FILE_BYTES);
6740
- const { bytesRead } = await handle.read(buffer, 0, MAX_GIT_FILE_BYTES, 0);
6772
+ const buffer = Buffer.alloc(maxBytes);
6773
+ const { bytesRead } = await handle.read(buffer, 0, maxBytes, 0);
6741
6774
  return buffer.subarray(0, bytesRead).toString("utf8");
6742
6775
  } catch {
6743
6776
  return void 0;
@@ -6765,6 +6798,60 @@ var parseGitDirFile = (content, worktreeRoot) => {
6765
6798
  );
6766
6799
  };
6767
6800
  var parseCommonDirFile = (content, gitDir) => resolveGitPath(firstLine(content), gitDir);
6801
+ var unquoteConfigValue = (raw) => {
6802
+ let value = "";
6803
+ let quoted = false;
6804
+ for (let index = 0; index < raw.length; index += 1) {
6805
+ const char = raw[index];
6806
+ if (char === "\\") {
6807
+ const next = raw[index + 1];
6808
+ if (next === void 0) {
6809
+ return void 0;
6810
+ }
6811
+ value += next === "n" ? "\n" : next === "t" ? " " : next;
6812
+ index += 1;
6813
+ } else if (char === '"') {
6814
+ quoted = !quoted;
6815
+ } else if (!quoted && (char === "#" || char === ";")) {
6816
+ break;
6817
+ } else {
6818
+ value += char;
6819
+ }
6820
+ }
6821
+ return quoted ? void 0 : value.trim();
6822
+ };
6823
+ var parseOriginRemoteUrl = (content) => {
6824
+ const lines = content.split(/\r?\n/);
6825
+ if (!content.endsWith("\n")) {
6826
+ lines.pop();
6827
+ }
6828
+ let inOrigin = false;
6829
+ for (const rawLine of lines) {
6830
+ const line = rawLine.trim();
6831
+ if (line.startsWith("[")) {
6832
+ const close = line.indexOf("]");
6833
+ const header = close === -1 ? "" : line.slice(1, close).trim();
6834
+ const rest = close === -1 ? "" : line.slice(close + 1).trim();
6835
+ inOrigin = /^remote\s+"origin"$/i.test(header) && header.endsWith('"origin"') || header.toLowerCase() === "remote.origin";
6836
+ if (!inOrigin || rest.length === 0 || rest.startsWith("#") || rest.startsWith(";")) {
6837
+ continue;
6838
+ }
6839
+ const entry2 = /^url\s*=(.*)$/i.exec(rest);
6840
+ if (entry2 !== null) {
6841
+ return unquoteConfigValue(entry2[1] ?? "");
6842
+ }
6843
+ continue;
6844
+ }
6845
+ if (!inOrigin) {
6846
+ continue;
6847
+ }
6848
+ const entry = /^url\s*=(.*)$/i.exec(line);
6849
+ if (entry !== null) {
6850
+ return unquoteConfigValue(entry[1] ?? "");
6851
+ }
6852
+ }
6853
+ return void 0;
6854
+ };
6768
6855
  var isMissing = async (filePath) => {
6769
6856
  try {
6770
6857
  await lstat(filePath);
@@ -6785,11 +6872,15 @@ var repositoryOf = async (worktreeRoot, gitDir) => {
6785
6872
  const commonDirFile = path5.join(gitDir, "commondir");
6786
6873
  const content = await readBounded2(commonDirFile);
6787
6874
  if (content === void 0) {
6788
- return await isMissing(commonDirFile) ? { kind: "main", mainRoot: worktreeRoot } : { kind: "linked" };
6875
+ return await isMissing(commonDirFile) ? { kind: "main", mainRoot: worktreeRoot, configDir: gitDir } : { kind: "linked" };
6789
6876
  }
6790
6877
  const commonDir = parseCommonDirFile(content, gitDir);
6791
6878
  const mainRoot = commonDir !== void 0 && path5.basename(commonDir) === ".git" && await isDirectory(commonDir) ? path5.dirname(commonDir) : void 0;
6792
- return { kind: "linked", ...mainRoot === void 0 ? {} : { mainRoot } };
6879
+ return {
6880
+ kind: "linked",
6881
+ ...mainRoot === void 0 ? {} : { mainRoot },
6882
+ ...commonDir === void 0 ? {} : { configDir: commonDir }
6883
+ };
6793
6884
  };
6794
6885
  var probeDirectory = async (directory) => {
6795
6886
  const dotGit = path5.join(directory, ".git");
@@ -6814,12 +6905,21 @@ var probeDirectory = async (directory) => {
6814
6905
  return INVALID;
6815
6906
  }
6816
6907
  const branch = parseHeadBranch(head);
6817
- const repository = info.isDirectory() ? { kind: "main", mainRoot: directory } : await repositoryOf(directory, gitDir);
6908
+ const { configDir, ...repository } = info.isDirectory() ? { kind: "main", mainRoot: directory, configDir: gitDir } : await repositoryOf(directory, gitDir);
6818
6909
  return {
6819
6910
  kind: "worktree",
6820
- located: { root: directory, ...branch === void 0 ? {} : { branch }, ...repository }
6911
+ located: { root: directory, ...branch === void 0 ? {} : { branch }, ...repository },
6912
+ configDir: configDir ?? ""
6821
6913
  };
6822
6914
  };
6915
+ var readOriginRepositoryKey = async (configDir) => {
6916
+ if (configDir.length === 0) {
6917
+ return void 0;
6918
+ }
6919
+ const content = await readBounded2(path5.join(configDir, "config"), MAX_GIT_CONFIG_BYTES);
6920
+ const url = content === void 0 ? void 0 : parseOriginRemoteUrl(content);
6921
+ return url === void 0 ? void 0 : normalizeRepositoryKey(url);
6922
+ };
6823
6923
  var createFilesystemWorktreeLocator = (options = {}) => {
6824
6924
  const now = options.monotonicMillis ?? (() => performance.now());
6825
6925
  const ttl = options.cacheTtlMillis ?? DEFAULT_WORKTREE_CACHE_TTL_MILLIS;
@@ -6837,32 +6937,57 @@ var createFilesystemWorktreeLocator = (options = {}) => {
6837
6937
  cache.set(directory, { at, probe });
6838
6938
  return probe;
6839
6939
  };
6840
- const locate = async (absolutePath) => {
6841
- try {
6842
- if (!path5.isAbsolute(absolutePath) || absolutePath.includes("\0")) {
6940
+ const remoteCache = /* @__PURE__ */ new Map();
6941
+ const cachedOriginKey = (configDir) => {
6942
+ const hit = remoteCache.get(configDir);
6943
+ const at = now();
6944
+ if (hit !== void 0 && at - hit.at <= ttl) {
6945
+ return hit.key;
6946
+ }
6947
+ if (remoteCache.size >= MAX_CACHE_ENTRIES) {
6948
+ remoteCache.clear();
6949
+ }
6950
+ const key = readOriginRepositoryKey(configDir).catch(() => void 0);
6951
+ remoteCache.set(configDir, { at, key });
6952
+ return key;
6953
+ };
6954
+ const findWorktree = async (absolutePath) => {
6955
+ if (!path5.isAbsolute(absolutePath) || absolutePath.includes("\0")) {
6956
+ return void 0;
6957
+ }
6958
+ let directory = path5.resolve(absolutePath);
6959
+ for (let depth = 0; depth < MAX_WORKTREE_WALK_DEPTH; depth += 1) {
6960
+ const probe = await cachedProbe(directory);
6961
+ if (probe.kind === "worktree") {
6962
+ return probe;
6963
+ }
6964
+ if (probe.kind === "invalid") {
6843
6965
  return void 0;
6844
6966
  }
6845
- let directory = path5.resolve(absolutePath);
6846
- for (let depth = 0; depth < MAX_WORKTREE_WALK_DEPTH; depth += 1) {
6847
- const probe = await cachedProbe(directory);
6848
- if (probe.kind === "worktree") {
6849
- return probe.located;
6850
- }
6851
- if (probe.kind === "invalid") {
6852
- return void 0;
6853
- }
6854
- const parent = path5.dirname(directory);
6855
- if (parent === directory) {
6856
- return void 0;
6857
- }
6858
- directory = parent;
6967
+ const parent = path5.dirname(directory);
6968
+ if (parent === directory) {
6969
+ return void 0;
6859
6970
  }
6971
+ directory = parent;
6972
+ }
6973
+ return void 0;
6974
+ };
6975
+ const locate = async (absolutePath) => {
6976
+ try {
6977
+ return (await findWorktree(absolutePath))?.located;
6978
+ } catch {
6860
6979
  return void 0;
6980
+ }
6981
+ };
6982
+ const originRepositoryKey = async (absolutePath) => {
6983
+ try {
6984
+ const probe = await findWorktree(absolutePath);
6985
+ return probe === void 0 ? void 0 : await cachedOriginKey(probe.configDir);
6861
6986
  } catch {
6862
6987
  return void 0;
6863
6988
  }
6864
6989
  };
6865
- return { locate };
6990
+ return { locate, originRepositoryKey };
6866
6991
  };
6867
6992
 
6868
6993
  // src/state/filesystem-store.ts
@@ -9355,6 +9480,12 @@ var omitRestrictedContent = (fact, mode) => {
9355
9480
  };
9356
9481
  var keyOfValue = (value) => typeof value === "string" ? normalizeRepositoryKey(value) : void 0;
9357
9482
  var resourceRepositoryKey = (attributes) => keyOfValue(attributes[ATTR_VCS_REPOSITORY_URL_FULL]);
9483
+ var repositoryUrlForKey = (key) => `https://${key}`;
9484
+ var hasOwnStamp = (attributes) => attributes?.[ATTR_VCS_REPOSITORY_URL_FULL] !== void 0;
9485
+ var withRoutedRepository = (event2, key) => hasOwnStamp(event2.contextAttributes) ? event2 : {
9486
+ ...event2,
9487
+ contextAttributes: { ...event2.contextAttributes, [ATTR_VCS_REPOSITORY_URL_FULL]: repositoryUrlForKey(key) }
9488
+ };
9358
9489
  var eventRepositoryKey = (event2, fallbackKey) => {
9359
9490
  const stamped = event2.contextAttributes?.[ATTR_VCS_REPOSITORY_URL_FULL];
9360
9491
  return stamped === void 0 ? fallbackKey : keyOfValue(stamped);
@@ -9388,19 +9519,21 @@ var restrictEventContent = (event2, mode, restrict) => {
9388
9519
  };
9389
9520
  var routeEventsToScopes = (events, scopes, options) => {
9390
9521
  const ends = spanEndEdgesOf(events);
9522
+ const fallbackKey = options.workspaceRepositoryKey ?? options.resourceRepositoryKey;
9391
9523
  const traces = [];
9392
9524
  const logs = [];
9393
9525
  let unchanged = true;
9394
9526
  for (const event2 of events) {
9395
9527
  const anchor = ends.get(event2.eventId) ?? event2;
9396
- const scope = matchDestinationScope(scopes, eventRepositoryKey(anchor, options.resourceRepositoryKey));
9528
+ const scope = matchDestinationScope(scopes, eventRepositoryKey(anchor, fallbackKey));
9397
9529
  if (scope === void 0 || !scope.signals.traces || !scope.signals.logs) {
9398
9530
  unchanged = false;
9399
9531
  }
9400
9532
  if (scope === void 0) {
9401
9533
  continue;
9402
9534
  }
9403
- const restricted = scope.contentMode === void 0 ? event2 : restrictEventContent(event2, scope.contentMode, options.restrict);
9535
+ const lowered = scope.contentMode === void 0 ? event2 : restrictEventContent(event2, scope.contentMode, options.restrict);
9536
+ const restricted = hasOwnStamp(anchor.contextAttributes) || fallbackKey === void 0 ? lowered : withRoutedRepository(lowered, fallbackKey);
9404
9537
  if (restricted !== event2) {
9405
9538
  unchanged = false;
9406
9539
  }
@@ -9423,7 +9556,15 @@ var routePointsToScopes = (scopes, pointsFor, options) => {
9423
9556
  for (const point of pointsFor(variant) ?? []) {
9424
9557
  const scope = matchDestinationScope(scopes, pointRepositoryKey(point, options.fallbackKey));
9425
9558
  if (scope?.signals.metrics === true && effective(scope) === variant) {
9426
- kept.push(point);
9559
+ kept.push(
9560
+ hasOwnStamp(point.attributes) || options.fallbackKey === void 0 ? point : {
9561
+ ...point,
9562
+ attributes: {
9563
+ ...point.attributes,
9564
+ [ATTR_VCS_REPOSITORY_URL_FULL]: repositoryUrlForKey(options.fallbackKey)
9565
+ }
9566
+ }
9567
+ );
9427
9568
  }
9428
9569
  }
9429
9570
  }
@@ -9641,8 +9782,9 @@ var createExportDestinationSinks = (options) => {
9641
9782
  ...metricSpool === void 0 ? {} : { metricSpool },
9642
9783
  ...destination.scopes === void 0 ? {} : {
9643
9784
  scopes: destination.scopes,
9644
- route: (events) => routeEventsToScopes(events, destination.scopes ?? [], {
9785
+ route: (events, workspaceRepositoryKey) => routeEventsToScopes(events, destination.scopes ?? [], {
9645
9786
  ...scopedResourceKey === void 0 ? {} : { resourceRepositoryKey: scopedResourceKey },
9787
+ ...workspaceRepositoryKey === void 0 ? {} : { workspaceRepositoryKey },
9646
9788
  restrict
9647
9789
  })
9648
9790
  }
@@ -9659,8 +9801,8 @@ var createScopedFanout = (destination, correlate) => {
9659
9801
  const none = { accepted: 0, rejected: 0, errors: [] };
9660
9802
  return {
9661
9803
  ...unscoped,
9662
- emit: async (events) => {
9663
- const batch = route(events);
9804
+ emit: async (events, emitOptions) => {
9805
+ const batch = route(events, emitOptions?.workspaceRepositoryKey);
9664
9806
  if (correlate !== void 0 && (batch.traces.length > 0 || batch.logs.length > 0)) {
9665
9807
  await correlate(events);
9666
9808
  correlate.alias(batch.traces, events);
@@ -9686,10 +9828,10 @@ var createDestinationFanout = (destinations, options = {}) => {
9686
9828
  if (only !== void 0) {
9687
9829
  return only.sink;
9688
9830
  }
9689
- const emit = async (events) => {
9831
+ const emit = async (events, emitOptions) => {
9690
9832
  const results = await Promise.all(
9691
9833
  fanouts.map(
9692
- (fanout) => fanout.sink.emit(events).catch(
9834
+ (fanout) => fanout.sink.emit(events, emitOptions).catch(
9693
9835
  (thrown) => ({
9694
9836
  accepted: 0,
9695
9837
  rejected: events.length,
@@ -9851,7 +9993,12 @@ var createHookRuntime = (options) => {
9851
9993
  })(),
9852
9994
  ...options.worktreeLocator === null ? {} : {
9853
9995
  worktreeLocator: options.worktreeLocator ?? createFilesystemWorktreeLocator({ monotonicMillis: () => clock.monotonicMillis() })
9854
- }
9996
+ },
9997
+ // Only a scoped destination routes by repository, so only then is the session
9998
+ // directory's remote read at all.
9999
+ routeByWorkspaceRepository: exportDestinations.destinations.some(
10000
+ (destination) => destination.scopes !== void 0
10001
+ )
9855
10002
  };
9856
10003
  const hook = createOtelHook({ ...hookDeps, sink });
9857
10004
  const deduplicator = createCallbackDeduplicator({ stateStore, clock });
@@ -9929,9 +10076,10 @@ var createHookRuntime = (options) => {
9929
10076
  turnStarts.set(event2.sessionId, await metricSeries.readTurnStart(event2.sessionId));
9930
10077
  }
9931
10078
  }
9932
- const scopedRepositoryFallback = scopedMetricDestinations.length === 0 ? void 0 : resourceRepositoryKey(metricResource.attributes);
10079
+ const resourceFallback = scopedMetricDestinations.length === 0 ? void 0 : resourceRepositoryKey(metricResource.attributes);
10080
+ const scopedRepositoryFallback = scopedMetricDestinations.length === 0 ? void 0 : ingest.workspaceRepositoryKey ?? resourceFallback;
9933
10081
  const resourceRepository = metricResource.attributes[ATTR_VCS_REPOSITORY_URL_FULL];
9934
- const metricEvents = scopedRepositoryFallback === void 0 || typeof resourceRepository !== "string" ? ingest.events : ingest.events.map(
10082
+ const metricEvents = resourceFallback === void 0 || ingest.workspaceRepositoryKey !== void 0 || typeof resourceRepository !== "string" ? ingest.events : ingest.events.map(
9935
10083
  (event2) => event2.contextAttributes?.[ATTR_VCS_REPOSITORY_URL_FULL] === void 0 ? {
9936
10084
  ...event2,
9937
10085
  contextAttributes: {