@bleedingdev/modern-js-server-runtime-extensions 3.8.2-ultramodern.9 → 3.8.3-ultramodern.2

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 (82) hide show
  1. package/dist/cjs/backend-federation-security/index.js +415 -0
  2. package/dist/cjs/backend-federation-security/node.js +74 -0
  3. package/dist/cjs/contract-gate-snapshot-store/http-store.js +1 -1
  4. package/dist/cjs/contract-gate-snapshot-store/resolve.js +4 -4
  5. package/dist/cjs/{contractGateAutopilot.js → contractGateSnapshotObserver.js} +14 -17
  6. package/dist/cjs/index.js +45 -13
  7. package/dist/cjs/runtime-fallback-signal/resolver.js +3 -3
  8. package/dist/cjs/runtimeLifecycle.js +129 -0
  9. package/dist/cjs/telemetry/{canaryEvaluation.js → healthEvaluation.js} +11 -13
  10. package/dist/cjs/telemetry/{canary.js → healthMonitor.js} +27 -44
  11. package/dist/cjs/telemetry/{canarySetup.js → healthSetup.js} +35 -39
  12. package/dist/cjs/telemetry/lifecycle.js +14 -14
  13. package/dist/cjs/telemetry/plugin.js +9 -9
  14. package/dist/cjs/telemetry/runtimeEndpoints.js +3 -3
  15. package/dist/cjs/telemetryCore.js +4 -4
  16. package/dist/esm/backend-federation-security/index.mjs +361 -0
  17. package/dist/esm/backend-federation-security/node.mjs +30 -0
  18. package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -1
  19. package/dist/esm/contract-gate-snapshot-store/resolve.mjs +4 -4
  20. package/dist/esm/{contractGateAutopilot.mjs → contractGateSnapshotObserver.mjs} +12 -15
  21. package/dist/esm/index.mjs +4 -2
  22. package/dist/esm/runtime-fallback-signal/resolver.mjs +3 -3
  23. package/dist/esm/runtimeLifecycle.mjs +82 -0
  24. package/dist/esm/telemetry/{canaryEvaluation.mjs → healthEvaluation.mjs} +9 -11
  25. package/dist/esm/telemetry/{canary.mjs → healthMonitor.mjs} +25 -42
  26. package/dist/esm/telemetry/healthSetup.mjs +65 -0
  27. package/dist/esm/telemetry/lifecycle.mjs +14 -14
  28. package/dist/esm/telemetry/plugin.mjs +8 -8
  29. package/dist/esm/telemetry/runtimeEndpoints.mjs +3 -3
  30. package/dist/esm/telemetryCore.mjs +1 -1
  31. package/dist/esm-node/backend-federation-security/index.mjs +362 -0
  32. package/dist/esm-node/backend-federation-security/node.mjs +31 -0
  33. package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +1 -1
  34. package/dist/esm-node/contract-gate-snapshot-store/resolve.mjs +4 -4
  35. package/dist/esm-node/{contractGateAutopilot.mjs → contractGateSnapshotObserver.mjs} +12 -15
  36. package/dist/esm-node/index.mjs +4 -2
  37. package/dist/esm-node/runtime-fallback-signal/resolver.mjs +3 -3
  38. package/dist/esm-node/runtimeLifecycle.mjs +83 -0
  39. package/dist/esm-node/telemetry/{canaryEvaluation.mjs → healthEvaluation.mjs} +9 -11
  40. package/dist/esm-node/telemetry/{canary.mjs → healthMonitor.mjs} +25 -42
  41. package/dist/esm-node/telemetry/healthSetup.mjs +66 -0
  42. package/dist/esm-node/telemetry/lifecycle.mjs +14 -14
  43. package/dist/esm-node/telemetry/plugin.mjs +8 -8
  44. package/dist/esm-node/telemetry/runtimeEndpoints.mjs +3 -3
  45. package/dist/esm-node/telemetryCore.mjs +1 -1
  46. package/dist/types/backend-federation-security/index.d.ts +68 -0
  47. package/dist/types/backend-federation-security/node.d.ts +3 -0
  48. package/dist/types/{contractGateAutopilot.d.ts → contractGateSnapshotObserver.d.ts} +7 -6
  49. package/dist/types/index.d.ts +4 -2
  50. package/dist/types/runtime-fallback-signal/resolver.d.ts +2 -2
  51. package/dist/types/runtimeLifecycle.d.ts +10 -0
  52. package/dist/types/telemetry/healthEvaluation.d.ts +20 -0
  53. package/dist/types/telemetry/{canary.d.ts → healthMonitor.d.ts} +31 -28
  54. package/dist/types/telemetry/{canarySetup.d.ts → healthSetup.d.ts} +6 -6
  55. package/dist/types/telemetry/lifecycle.d.ts +4 -4
  56. package/dist/types/telemetry/plugin.d.ts +1 -1
  57. package/dist/types/telemetry/runtimeEndpoints.d.ts +3 -3
  58. package/dist/types/telemetryCore.d.ts +1 -1
  59. package/package.json +46 -8
  60. package/src/backend-federation-security/index.ts +831 -0
  61. package/src/backend-federation-security/node.ts +51 -0
  62. package/src/contract-gate-snapshot-store/http-store.ts +1 -1
  63. package/src/contract-gate-snapshot-store/resolve.ts +4 -4
  64. package/src/{contractGateAutopilot.ts → contractGateSnapshotObserver.ts} +18 -25
  65. package/src/index.ts +42 -6
  66. package/src/runtime-fallback-signal/resolver.ts +5 -5
  67. package/src/runtimeLifecycle.ts +125 -0
  68. package/src/telemetry/{canaryEvaluation.ts → healthEvaluation.ts} +14 -17
  69. package/src/telemetry/{canary.ts → healthMonitor.ts} +72 -84
  70. package/src/telemetry/{canarySetup.ts → healthSetup.ts} +50 -53
  71. package/src/telemetry/lifecycle.ts +20 -20
  72. package/src/telemetry/plugin.ts +16 -16
  73. package/src/telemetry/runtimeEndpoints.ts +6 -6
  74. package/src/telemetryCore.ts +11 -11
  75. package/tests/backendFederationSecurity.test.ts +416 -0
  76. package/tests/{contractGateAutopilot.test.ts → contractGateSnapshotObserver.test.ts} +59 -62
  77. package/tests/runtimeLifecycle.test.ts +107 -0
  78. package/tests/telemetryHealthMonitor.test.ts +187 -0
  79. package/dist/esm/telemetry/canarySetup.mjs +0 -69
  80. package/dist/esm-node/telemetry/canarySetup.mjs +0 -70
  81. package/dist/types/telemetry/canaryEvaluation.d.ts +0 -20
  82. package/tests/telemetryCanaryOrchestrator.test.ts +0 -365
@@ -1,5 +1,5 @@
1
1
  import "node:module";
2
- const evaluateCanaryHealth = (metrics, thresholds)=>{
2
+ const evaluateTelemetryHealth = (metrics, thresholds)=>{
3
3
  const failures = [];
4
4
  const { queueStats, unhealthyExporterCount } = metrics;
5
5
  if (queueStats.utilization > thresholds.maxQueueUtilization) failures.push({
@@ -19,18 +19,16 @@ const evaluateCanaryHealth = (metrics, thresholds)=>{
19
19
  });
20
20
  for (const gateName of metrics.requiredContractGates){
21
21
  const gate = metrics.contractGates.get(gateName);
22
- if (!gate) {
23
- failures.push({
24
- reason: 'contract_gate_missing',
22
+ if (gate) {
23
+ if (!gate.passed) failures.push({
24
+ reason: 'contract_gate_failed',
25
25
  gate: gateName,
26
- message: `Contract gate "${gateName}" is missing`
26
+ message: gate.reason || `Contract gate "${gateName}" is not passing`
27
27
  });
28
- continue;
29
- }
30
- if (!gate.passed) failures.push({
31
- reason: 'contract_gate_failed',
28
+ } else failures.push({
29
+ reason: 'contract_gate_missing',
32
30
  gate: gateName,
33
- message: gate.reason || `Contract gate "${gateName}" is not passing`
31
+ message: `Contract gate "${gateName}" is missing`
34
32
  });
35
33
  }
36
34
  return {
@@ -39,4 +37,4 @@ const evaluateCanaryHealth = (metrics, thresholds)=>{
39
37
  unhealthyExporterCount
40
38
  };
41
39
  };
42
- export { evaluateCanaryHealth };
40
+ export { evaluateTelemetryHealth };
@@ -1,14 +1,13 @@
1
1
  import "node:module";
2
- import { evaluateCanaryHealth } from "./canaryEvaluation.mjs";
3
2
  import { clamp } from "./envelope.mjs";
4
- class TelemetryCanaryOrchestrator {
3
+ import { evaluateTelemetryHealth } from "./healthEvaluation.mjs";
4
+ class TelemetryHealthMonitor {
5
5
  setRequiredContractGates(gates) {
6
6
  this.requiredContractGates = Array.from(new Set(gates.map((item)=>item.trim()).filter(Boolean)));
7
7
  }
8
8
  addRequiredContractGate(name) {
9
9
  const normalizedName = name.trim();
10
- if (!normalizedName) return;
11
- if (!this.requiredContractGates.includes(normalizedName)) this.requiredContractGates.push(normalizedName);
10
+ if (normalizedName && !this.requiredContractGates.includes(normalizedName)) this.requiredContractGates.push(normalizedName);
12
11
  }
13
12
  setContractGate(name, passed, reason) {
14
13
  this.contractGates.set(name, {
@@ -19,23 +18,13 @@ class TelemetryCanaryOrchestrator {
19
18
  });
20
19
  }
21
20
  setContractGates(gates) {
22
- for (const [name, value] of Object.entries(gates)){
23
- if ('boolean' == typeof value) {
24
- this.setContractGate(name, value);
25
- continue;
26
- }
27
- this.setContractGate(name, value.passed, value.reason);
28
- }
29
- }
30
- resetToCanary() {
31
- this.state = 'canary';
32
- this.consecutiveHealthy = 0;
33
- this.consecutiveFailures = 0;
21
+ for (const [name, value] of Object.entries(gates))if ('boolean' == typeof value) this.setContractGate(name, value);
22
+ else this.setContractGate(name, value.passed, value.reason);
34
23
  }
35
24
  collectFailures() {
36
25
  const queueStats = this.registry.getQueueStats();
37
26
  const unhealthyExporterCount = this.registry.getExporterHealth().filter((item)=>!item.healthy).length;
38
- return evaluateCanaryHealth({
27
+ return evaluateTelemetryHealth({
39
28
  queueStats,
40
29
  unhealthyExporterCount,
41
30
  requiredContractGates: this.requiredContractGates,
@@ -47,27 +36,26 @@ class TelemetryCanaryOrchestrator {
47
36
  });
48
37
  }
49
38
  evaluate() {
50
- const now = Date.now();
51
39
  const { failures, queueStats, unhealthyExporterCount } = this.collectFailures();
52
- let action = 'hold';
40
+ let transition = 'none';
53
41
  if (failures.length > 0) {
54
42
  this.consecutiveHealthy = 0;
55
43
  this.consecutiveFailures += 1;
56
- if ('rolled_back' !== this.state && this.consecutiveFailures >= this.rollbackConsecutiveFailures) {
57
- this.state = 'rolled_back';
58
- action = 'rollback';
44
+ if ('unhealthy' !== this.state && this.consecutiveFailures >= this.minConsecutiveFailedEvaluations) {
45
+ this.state = 'unhealthy';
46
+ transition = 'became_unhealthy';
59
47
  }
60
48
  } else {
61
49
  this.consecutiveFailures = 0;
62
50
  this.consecutiveHealthy += 1;
63
- if ('canary' === this.state && this.consecutiveHealthy >= this.minConsecutiveHealthyEvaluations) {
64
- this.state = 'promoted';
65
- action = 'promote';
51
+ if ('healthy' !== this.state && this.consecutiveHealthy >= this.minConsecutiveHealthyEvaluations) {
52
+ this.state = 'healthy';
53
+ transition = 'became_healthy';
66
54
  }
67
55
  }
68
- const decision = {
69
- timestamp: now,
70
- action,
56
+ const evaluation = {
57
+ timestamp: Date.now(),
58
+ transition,
71
59
  state: this.state,
72
60
  consecutiveHealthy: this.consecutiveHealthy,
73
61
  consecutiveFailures: this.consecutiveFailures,
@@ -79,21 +67,17 @@ class TelemetryCanaryOrchestrator {
79
67
  }))
80
68
  };
81
69
  try {
82
- this.onEvaluate?.(decision);
83
- } catch (_error) {}
84
- if ('promote' === action) try {
85
- this.onPromote?.(decision);
70
+ this.onEvaluate?.(evaluation);
86
71
  } catch (_error) {}
87
- if ('rollback' === action) try {
88
- this.onRollback?.(decision);
72
+ if ('none' !== transition) try {
73
+ this.onTransition?.(evaluation);
89
74
  } catch (_error) {}
90
- return decision;
75
+ return evaluation;
91
76
  }
92
77
  getStatusSnapshot() {
93
- const now = Date.now();
94
78
  const { failures, queueStats, unhealthyExporterCount } = this.collectFailures();
95
79
  return {
96
- timestamp: now,
80
+ timestamp: Date.now(),
97
81
  state: this.state,
98
82
  consecutiveHealthy: this.consecutiveHealthy,
99
83
  consecutiveFailures: this.consecutiveFailures,
@@ -124,20 +108,19 @@ class TelemetryCanaryOrchestrator {
124
108
  constructor(options){
125
109
  this.requiredContractGates = [];
126
110
  this.contractGates = new Map();
127
- this.state = 'canary';
111
+ this.state = 'pending';
128
112
  this.consecutiveHealthy = 0;
129
113
  this.consecutiveFailures = 0;
130
114
  this.registry = options.registry;
131
115
  this.evaluationIntervalMs = Math.max(250, options.evaluationIntervalMs ?? 15000);
132
116
  this.minConsecutiveHealthyEvaluations = Math.max(1, options.minConsecutiveHealthyEvaluations ?? 3);
133
- this.rollbackConsecutiveFailures = Math.max(1, options.rollbackConsecutiveFailures ?? 2);
117
+ this.minConsecutiveFailedEvaluations = Math.max(1, options.minConsecutiveFailedEvaluations ?? 2);
134
118
  this.maxQueueUtilization = clamp(options.maxQueueUtilization ?? 0.8, 0, 1);
135
119
  this.maxTotalDropped = Math.max(0, options.maxTotalDropped ?? 0);
136
120
  this.maxUnhealthyExporters = Math.max(0, options.maxUnhealthyExporters ?? 0);
137
121
  this.setRequiredContractGates(options.requiredContractGates || []);
138
122
  this.onEvaluate = options.onEvaluate;
139
- this.onPromote = options.onPromote;
140
- this.onRollback = options.onRollback;
123
+ this.onTransition = options.onTransition;
141
124
  }
142
125
  }
143
- export { TelemetryCanaryOrchestrator };
126
+ export { TelemetryHealthMonitor };
@@ -0,0 +1,66 @@
1
+ import "node:module";
2
+ import { DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH, resolveContractGateSnapshotPath, resolveContractGateSnapshotStore } from "../contract-gate-snapshot-store/index.mjs";
3
+ import { DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS, DEFAULT_RUNTIME_FALLBACK_GATE_NAME, DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES, createRuntimeFallbackSignalRuntimeState, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, resolveRuntimeFallbackSignalEndpoint } from "../runtimeFallbackSignal.mjs";
4
+ import { TelemetryHealthMonitor } from "../telemetryCore.mjs";
5
+ function emitHealthTransitionMetric(registry, evaluation) {
6
+ try {
7
+ registry.enqueueMetric({
8
+ name: 'telemetry.health.transition',
9
+ value: 1,
10
+ unit: 'count',
11
+ tags: {
12
+ transition: evaluation.transition,
13
+ state: evaluation.state,
14
+ failures: String(evaluation.failures.length)
15
+ }
16
+ });
17
+ } catch (_error) {}
18
+ }
19
+ const setupTelemetryHealthMonitoring = ({ registry, appDirectory, legacyHealthConfig })=>{
20
+ if (!legacyHealthConfig?.enabled) return {};
21
+ const contractGates = legacyHealthConfig.contractGates;
22
+ const healthMonitor = new TelemetryHealthMonitor({
23
+ registry,
24
+ evaluationIntervalMs: legacyHealthConfig.evaluationIntervalMs,
25
+ minConsecutiveHealthyEvaluations: legacyHealthConfig.minConsecutiveHealthyEvaluations,
26
+ minConsecutiveFailedEvaluations: legacyHealthConfig.rollbackConsecutiveFailures,
27
+ maxQueueUtilization: legacyHealthConfig.maxQueueUtilization,
28
+ maxTotalDropped: legacyHealthConfig.maxTotalDropped,
29
+ maxUnhealthyExporters: legacyHealthConfig.maxUnhealthyExporters,
30
+ requiredContractGates: Object.keys(contractGates || {}),
31
+ onTransition: (evaluation)=>{
32
+ emitHealthTransitionMetric(registry, evaluation);
33
+ }
34
+ });
35
+ if (contractGates) healthMonitor.setContractGates(contractGates);
36
+ let gateSnapshotStorePromise;
37
+ let runtimeFallbackSignalConfig;
38
+ const snapshotObservationEnabled = legacyHealthConfig.autopilot?.enabled ?? true;
39
+ if (snapshotObservationEnabled) {
40
+ const gateSnapshotPath = resolveContractGateSnapshotPath(appDirectory, legacyHealthConfig.autopilot?.gateSnapshotPath);
41
+ gateSnapshotStorePromise = resolveContractGateSnapshotStore({
42
+ appDirectory,
43
+ gateSnapshotPath: gateSnapshotPath || DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH,
44
+ stateStore: legacyHealthConfig.autopilot?.stateStore
45
+ });
46
+ const runtimeSignalConfig = legacyHealthConfig.autopilot?.runtimeFallbackSignal;
47
+ if (runtimeSignalConfig?.enabled === true) runtimeFallbackSignalConfig = {
48
+ endpoint: resolveRuntimeFallbackSignalEndpoint(runtimeSignalConfig.endpoint),
49
+ gateName: runtimeSignalConfig.gateName?.trim() || DEFAULT_RUNTIME_FALLBACK_GATE_NAME,
50
+ gateSnapshotStore: gateSnapshotStorePromise,
51
+ failureHoldMs: Math.max(1000, runtimeSignalConfig.failureHoldMs ?? DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS),
52
+ maxBodyBytes: Math.max(512, runtimeSignalConfig.maxBodyBytes ?? DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES),
53
+ auth: normalizeRequiredRuntimeFallbackSignalAuthConfig(runtimeSignalConfig.auth),
54
+ trustPolicy: normalizeRuntimeFallbackTrustPolicy(runtimeSignalConfig.trustPolicy),
55
+ runtimeState: createRuntimeFallbackSignalRuntimeState()
56
+ };
57
+ }
58
+ const runtimeStatusAuthConfig = runtimeFallbackSignalConfig?.auth ?? normalizeRuntimeFallbackSignalAuthConfig(legacyHealthConfig.autopilot?.runtimeFallbackSignal?.auth);
59
+ return {
60
+ healthMonitor,
61
+ gateSnapshotStorePromise,
62
+ runtimeFallbackSignalConfig,
63
+ runtimeStatusAuthConfig
64
+ };
65
+ };
66
+ export { setupTelemetryHealthMonitoring };
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
2
  import { resolveContractGateSnapshotPath } from "../contract-gate-snapshot-store/index.mjs";
3
- import { ContractGateAutopilot } from "../contractGateAutopilot.mjs";
3
+ import { ContractGateSnapshotObserver } from "../contractGateSnapshotObserver.mjs";
4
4
  import { createOtlpTelemetryExporter, createVictoriaMetricsTelemetryExporter, maybeWarnLegacyOtlpEndpoint } from "../telemetryCore.mjs";
5
5
  const activeTelemetryLaneClosers = new Set();
6
6
  let telemetryBeforeExitHookInstalled = false;
@@ -13,15 +13,15 @@ const ensureTelemetryBeforeExitHook = ()=>{
13
13
  ])close();
14
14
  });
15
15
  };
16
- const registerTelemetryLifecycle = ({ api, registry, telemetryConfig, canaryConfig, canaryOrchestrator, gateSnapshotStorePromise, appDirectory })=>{
17
- let contractGateAutopilot;
16
+ const registerTelemetryLifecycle = ({ api, registry, telemetryConfig, legacyHealthConfig, healthMonitor, gateSnapshotStorePromise, appDirectory })=>{
17
+ let contractGateSnapshotObserver;
18
18
  let telemetryLaneClosed = false;
19
19
  const closeTelemetryLane = async ()=>{
20
20
  if (telemetryLaneClosed) return;
21
21
  telemetryLaneClosed = true;
22
22
  activeTelemetryLaneClosers.delete(closeTelemetryLane);
23
- contractGateAutopilot?.stop();
24
- canaryOrchestrator?.stop();
23
+ contractGateSnapshotObserver?.stop();
24
+ healthMonitor?.stop();
25
25
  await registry.shutdown();
26
26
  };
27
27
  let prepared = false;
@@ -42,20 +42,20 @@ const registerTelemetryLifecycle = ({ api, registry, telemetryConfig, canaryConf
42
42
  await registry.startupHealthCheck({
43
43
  failLoud: telemetryConfig.failLoudStartup ?? true
44
44
  });
45
- if (!canaryOrchestrator) return;
46
- canaryOrchestrator.start();
45
+ if (!healthMonitor) return;
46
+ healthMonitor.start();
47
47
  if (gateSnapshotStorePromise) {
48
48
  const gateSnapshotStore = await gateSnapshotStorePromise;
49
- contractGateAutopilot = new ContractGateAutopilot({
50
- orchestrator: canaryOrchestrator,
51
- gateSnapshotPath: resolveContractGateSnapshotPath(appDirectory, canaryConfig?.autopilot?.gateSnapshotPath),
49
+ contractGateSnapshotObserver = new ContractGateSnapshotObserver({
50
+ monitor: healthMonitor,
51
+ gateSnapshotPath: resolveContractGateSnapshotPath(appDirectory, legacyHealthConfig?.autopilot?.gateSnapshotPath),
52
52
  gateSnapshotStore,
53
- pollIntervalMs: canaryConfig?.autopilot?.pollIntervalMs,
54
- gateStaleAfterMs: canaryConfig?.autopilot?.gateStaleAfterMs
53
+ pollIntervalMs: legacyHealthConfig?.autopilot?.pollIntervalMs,
54
+ gateStaleAfterMs: legacyHealthConfig?.autopilot?.gateStaleAfterMs
55
55
  });
56
56
  }
57
- if (contractGateAutopilot) await contractGateAutopilot.start();
58
- canaryOrchestrator.evaluate();
57
+ if (contractGateSnapshotObserver) await contractGateSnapshotObserver.start();
58
+ healthMonitor.evaluate();
59
59
  });
60
60
  };
61
61
  export { registerTelemetryLifecycle };
@@ -2,8 +2,8 @@ import "node:module";
2
2
  import { parseTraceparent } from "@modern-js/create-request/server";
3
3
  import { logger } from "@modern-js/utils";
4
4
  import { parseServerRuntimeExtensionsEnv } from "../env.mjs";
5
- import { TelemetryCanaryOrchestrator, TelemetryRegistry, TelemetryStartupHealthError, createOtlpTelemetryExporter, createTelemetryAwareMetrics, createVictoriaMetricsTelemetryExporter, toTelemetryEnvelope } from "../telemetryCore.mjs";
6
- import { setupTelemetryCanary } from "./canarySetup.mjs";
5
+ import { TelemetryHealthMonitor, TelemetryRegistry, TelemetryStartupHealthError, createOtlpTelemetryExporter, createTelemetryAwareMetrics, createVictoriaMetricsTelemetryExporter, toTelemetryEnvelope } from "../telemetryCore.mjs";
6
+ import { setupTelemetryHealthMonitoring } from "./healthSetup.mjs";
7
7
  import { registerTelemetryLifecycle } from "./lifecycle.mjs";
8
8
  import { createRuntimeFallbackSignalMiddleware, createRuntimeStatusMiddleware } from "./runtimeEndpoints.mjs";
9
9
  const hasEnabledTelemetryExporters = (config)=>Boolean(config?.exporters?.otlp?.enabled || config?.exporters?.victoriaMetrics?.enabled);
@@ -37,15 +37,15 @@ const injectTelemetryPlugin = ()=>({
37
37
  redactionKeys: telemetryConfig.redactionKeys,
38
38
  slo: resolveTelemetrySloOptions(telemetryConfig.slo)
39
39
  });
40
- const { canaryOrchestrator, gateSnapshotStorePromise, runtimeFallbackSignalConfig, runtimeStatusAuthConfig } = setupTelemetryCanary({
40
+ const { healthMonitor, gateSnapshotStorePromise, runtimeFallbackSignalConfig, runtimeStatusAuthConfig } = setupTelemetryHealthMonitoring({
41
41
  registry,
42
42
  appDirectory,
43
- canaryConfig: telemetryConfig.canary
43
+ legacyHealthConfig: telemetryConfig.canary
44
44
  });
45
45
  if (runtimeFallbackSignalConfig) middlewares.push(createRuntimeFallbackSignalMiddleware(runtimeFallbackSignalConfig));
46
46
  middlewares.push(createRuntimeStatusMiddleware({
47
47
  registry,
48
- canaryOrchestrator,
48
+ healthMonitor,
49
49
  runtimeFallbackSignalConfig,
50
50
  runtimeStatusAuthConfig
51
51
  }));
@@ -77,12 +77,12 @@ const injectTelemetryPlugin = ()=>({
77
77
  api,
78
78
  registry,
79
79
  telemetryConfig,
80
- canaryConfig: telemetryConfig.canary,
81
- canaryOrchestrator,
80
+ legacyHealthConfig: telemetryConfig.canary,
81
+ healthMonitor,
82
82
  gateSnapshotStorePromise,
83
83
  appDirectory
84
84
  });
85
85
  }
86
86
  });
87
87
  export { DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, DEFAULT_RUNTIME_STATUS_ENDPOINT, createRuntimeFallbackSignalRuntimeState, createRuntimeSignalError, enforceRuntimeFallbackSignalAuthToken, enforceRuntimeFallbackSignalTrustPolicy, getRuntimeSignalErrorStatusCode, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, parseRuntimeFallbackSignalPayloadFromRawBody, resolveRuntimeFallbackSignalEndpoint } from "../runtimeFallbackSignal.mjs";
88
- export { TelemetryCanaryOrchestrator, TelemetryRegistry, TelemetryStartupHealthError, createOtlpTelemetryExporter, createTelemetryAwareMetrics, createVictoriaMetricsTelemetryExporter, hasEnabledTelemetryExporters, injectTelemetryPlugin, resolveTelemetrySloOptions };
88
+ export { TelemetryHealthMonitor, TelemetryRegistry, TelemetryStartupHealthError, createOtlpTelemetryExporter, createTelemetryAwareMetrics, createVictoriaMetricsTelemetryExporter, hasEnabledTelemetryExporters, injectTelemetryPlugin, resolveTelemetrySloOptions };
@@ -35,7 +35,7 @@ const createRuntimeFallbackSignalMiddleware = (signalConfig)=>({
35
35
  }
36
36
  }
37
37
  });
38
- const createRuntimeStatusMiddleware = ({ registry, canaryOrchestrator, runtimeFallbackSignalConfig, runtimeStatusAuthConfig })=>({
38
+ const createRuntimeStatusMiddleware = ({ registry, healthMonitor, runtimeFallbackSignalConfig, runtimeStatusAuthConfig })=>({
39
39
  name: 'telemetry-runtime-status',
40
40
  path: DEFAULT_RUNTIME_STATUS_ENDPOINT,
41
41
  method: 'get',
@@ -54,9 +54,9 @@ const createRuntimeStatusMiddleware = ({ registry, canaryOrchestrator, runtimeFa
54
54
  queueStats: registry.getQueueStats(),
55
55
  exporterHealth: registry.getExporterHealth()
56
56
  },
57
- canary: canaryOrchestrator ? {
57
+ health: healthMonitor ? {
58
58
  enabled: true,
59
- ...canaryOrchestrator.getStatusSnapshot()
59
+ ...healthMonitor.getStatusSnapshot()
60
60
  } : {
61
61
  enabled: false
62
62
  },
@@ -1,7 +1,7 @@
1
1
  import "node:module";
2
- export { TelemetryCanaryOrchestrator } from "./telemetry/canary.mjs";
3
2
  export { toTelemetryEnvelope } from "./telemetry/envelope.mjs";
4
3
  export { createOtlpTelemetryExporter, createVictoriaMetricsTelemetryExporter, maybeWarnLegacyOtlpEndpoint } from "./telemetry/exporters.mjs";
4
+ export { TelemetryHealthMonitor } from "./telemetry/healthMonitor.mjs";
5
5
  export { createTelemetryAwareMetrics } from "./telemetry/metrics.mjs";
6
6
  export { TelemetryRegistry } from "./telemetry/registry.mjs";
7
7
  export { TelemetryStartupHealthError } from "./telemetry/registryTypes.mjs";
@@ -0,0 +1,68 @@
1
+ export type BackendFederationRemoteEntryErrorCode = 'aborted' | 'byte_length_mismatch' | 'entry_too_large' | 'fetch_failed' | 'identity_mismatch' | 'integrity_mismatch' | 'invalid_verification' | 'redirect_mismatch' | 'timeout' | 'unsupported_entry';
2
+ export declare class BackendFederationRemoteEntryError extends Error {
3
+ readonly code: BackendFederationRemoteEntryErrorCode;
4
+ readonly details?: Record<string, unknown>;
5
+ constructor(code: BackendFederationRemoteEntryErrorCode, message: string, options?: {
6
+ cause?: unknown;
7
+ details?: Record<string, unknown>;
8
+ });
9
+ }
10
+ export type BackendFederationEntryIntegrity = {
11
+ byteLength: number;
12
+ sha256: string;
13
+ };
14
+ export type BackendFederationRemoteEntryVerification = BackendFederationEntryIntegrity & {
15
+ buildMarker?: string;
16
+ entryUrl: string;
17
+ remoteName: string;
18
+ unitId?: string;
19
+ };
20
+ export type BackendFederationRemoteEntryExpectation = Partial<BackendFederationRemoteEntryVerification>;
21
+ export type BackendFederationRemoteEntry = {
22
+ entry: string;
23
+ name: string;
24
+ type?: string;
25
+ };
26
+ export type BackendFederationEntryExports = {
27
+ get: (id: string) => (() => Promise<unknown> | unknown) | Promise<() => Promise<unknown> | unknown>;
28
+ init?: (...args: unknown[]) => void | Promise<void>;
29
+ };
30
+ export type BackendFederationResourceResponse = {
31
+ body?: ReadableStream<Uint8Array> | null;
32
+ headers?: {
33
+ get(name: string): string | null;
34
+ };
35
+ ok: boolean;
36
+ status: number;
37
+ statusText?: string;
38
+ text?: () => Promise<string>;
39
+ url?: string;
40
+ };
41
+ export type BackendFederationResourceFetch = (url: string, init?: RequestInit) => Promise<BackendFederationResourceResponse>;
42
+ export type BackendFederationRemoteEntryFetch = BackendFederationResourceFetch;
43
+ export type BackendFederationResourcePolicy = {
44
+ allowInsecureHttp?: boolean;
45
+ fetch?: BackendFederationResourceFetch;
46
+ maxBytes?: number;
47
+ signal?: AbortSignal;
48
+ timeoutMs?: number;
49
+ };
50
+ export type BackendFederationCommonJsEvaluator = (source: string, context: {
51
+ remote: BackendFederationRemoteEntry;
52
+ }) => unknown;
53
+ export type BackendFederationRemoteEntryPolicy = BackendFederationResourcePolicy & {
54
+ evaluateCommonJs?: BackendFederationCommonJsEvaluator;
55
+ expected?: BackendFederationRemoteEntryExpectation;
56
+ };
57
+ export type LoadVerifiedBackendFederationEntryOptions = BackendFederationRemoteEntryPolicy & {
58
+ remote: BackendFederationRemoteEntry;
59
+ verification?: BackendFederationRemoteEntryVerification;
60
+ };
61
+ export type LoadBoundedBackendFederationResourceOptions = BackendFederationResourcePolicy & {
62
+ kind?: 'entry' | 'manifest';
63
+ };
64
+ export declare function resolveBackendFederationRemoteEntryVerification(manifest: unknown): BackendFederationRemoteEntryVerification | undefined;
65
+ export declare function redactBackendFederationUrl(value: string): string;
66
+ export declare function loadBoundedBackendFederationResource(resourceUrl: string, options?: LoadBoundedBackendFederationResourceOptions): Promise<Uint8Array<ArrayBuffer>>;
67
+ export declare const evaluateBackendFederationCommonJsEntry: (remote: BackendFederationRemoteEntry, bytes: Uint8Array, evaluator?: BackendFederationCommonJsEvaluator) => BackendFederationEntryExports;
68
+ export declare function loadVerifiedBackendFederationEntry(options: LoadVerifiedBackendFederationEntryOptions): Promise<BackendFederationEntryExports>;
@@ -0,0 +1,3 @@
1
+ import { type BackendFederationCommonJsEvaluator, type BackendFederationEntryIntegrity } from './index';
2
+ export declare function createBackendFederationEntryIntegrity(value: string | Uint8Array): BackendFederationEntryIntegrity;
3
+ export declare const evaluateNodeBackendFederationCommonJs: BackendFederationCommonJsEvaluator;
@@ -1,19 +1,20 @@
1
1
  import type { ContractGateSnapshotStore } from './contract-gate-snapshot-store/types';
2
- import type { TelemetryCanaryOrchestrator } from './telemetryCore';
2
+ import type { TelemetryHealthMonitor } from './telemetry/healthMonitor';
3
3
  type LoggerLike = {
4
4
  info?: (message: string) => void;
5
5
  warn?: (message: string) => void;
6
6
  };
7
- export type ContractGateAutopilotOptions = {
8
- orchestrator: TelemetryCanaryOrchestrator;
7
+ export type ContractGateSnapshotObserverOptions = {
8
+ monitor: TelemetryHealthMonitor;
9
9
  gateSnapshotPath?: string;
10
10
  gateSnapshotStore?: ContractGateSnapshotStore;
11
11
  pollIntervalMs?: number;
12
12
  gateStaleAfterMs?: number;
13
13
  logger?: LoggerLike;
14
14
  };
15
- export declare class ContractGateAutopilot {
16
- private readonly orchestrator;
15
+ /** Polls contract-gate snapshots and exposes them to telemetry health checks. */
16
+ export declare class ContractGateSnapshotObserver {
17
+ private readonly monitor;
17
18
  private readonly gateSnapshotStore;
18
19
  private readonly gateSnapshotPath?;
19
20
  private readonly pollIntervalMs;
@@ -22,7 +23,7 @@ export declare class ContractGateAutopilot {
22
23
  private poller?;
23
24
  private syncGeneration;
24
25
  private readonly appliedGateFingerprints;
25
- constructor(options: ContractGateAutopilotOptions);
26
+ constructor(options: ContractGateSnapshotObserverOptions);
26
27
  start(): Promise<void>;
27
28
  stop(): void;
28
29
  syncOnce(): Promise<number>;
@@ -1,5 +1,7 @@
1
- export { ContractGateAutopilot, type ContractGateAutopilotOptions, } from './contractGateAutopilot';
1
+ export { type BackendFederationCommonJsEvaluator, type BackendFederationEntryExports, type BackendFederationEntryIntegrity, type BackendFederationRemoteEntry, BackendFederationRemoteEntryError, type BackendFederationRemoteEntryErrorCode, type BackendFederationRemoteEntryExpectation, type BackendFederationRemoteEntryFetch, type BackendFederationRemoteEntryPolicy, type BackendFederationRemoteEntryVerification, type BackendFederationResourceFetch, type BackendFederationResourcePolicy, type BackendFederationResourceResponse, evaluateBackendFederationCommonJsEntry, type LoadBoundedBackendFederationResourceOptions, type LoadVerifiedBackendFederationEntryOptions, loadBoundedBackendFederationResource, loadVerifiedBackendFederationEntry, redactBackendFederationUrl, resolveBackendFederationRemoteEntryVerification, } from './backend-federation-security';
2
+ export { ContractGateSnapshotObserver, type ContractGateSnapshotObserverOptions, } from './contractGateSnapshotObserver';
2
3
  export { DEFAULT_ENVIRONMENT_NAME, parseServerRuntimeExtensionsEnv, type ServerRuntimeExtensionsEnv, } from './env';
3
4
  export { getRequestPathname, injectMfAssetCacheHeadersPlugin, isMfManifestAsset, isMfRemoteEntryAsset, resolveMfAssetCacheHeaders, } from './mfCache';
4
5
  export { type CollectDirectRemoteModuleFederationCssOptions, collectDirectRemoteModuleFederationCss, collectDirectRemoteModuleFederationCssWithMeta, collectModuleFederationManifestCss, createModuleFederationCssCollector, injectModuleFederationCssPlugin, type ModuleFederationCssCollectorOptions, type ModuleFederationCssPluginOptions, type ModuleFederationManifest, type RemoteModuleFederationCssCollection, } from './module-federation-css';
5
- export { createOtlpTelemetryExporter, createRuntimeFallbackSignalRuntimeState, createRuntimeSignalError, createTelemetryAwareMetrics, createVictoriaMetricsTelemetryExporter, DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, DEFAULT_RUNTIME_STATUS_ENDPOINT, enforceRuntimeFallbackSignalAuthToken, enforceRuntimeFallbackSignalTrustPolicy, getRuntimeSignalErrorStatusCode, hasEnabledTelemetryExporters, injectTelemetryPlugin, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, type OtlpExporterOptions, parseRuntimeFallbackSignalPayloadFromRawBody, type RuntimeFallbackSignalAuthConfig, type RuntimeFallbackSignalRuntimeState, type RuntimeFallbackSignalSource, type RuntimeFallbackSignalTrustContext, type RuntimeFallbackSignalTrustPolicy, type RuntimeSignalError, type RuntimeSignalErrorCode, resolveRuntimeFallbackSignalEndpoint, resolveTelemetrySloOptions, type TelemetryCanaryDecision, TelemetryCanaryOrchestrator, type TelemetryCanaryStatusSnapshot, type TelemetryEnvelope, type TelemetryExporter, type TelemetryQueueStats, TelemetryRegistry, type TelemetryRegistryOptions, type TelemetrySignalType, type TelemetrySloAlert, TelemetryStartupHealthError, type VictoriaMetricsExporterOptions, } from './telemetry';
6
+ export { createDisposableServerRuntimeHandle, type DisposableServerRuntimeHandle, disposeServerRuntime, initializeDisposableServerRuntime, registerServerRuntimeDisposer, type ServerRuntimeHandle, } from './runtimeLifecycle';
7
+ export { createOtlpTelemetryExporter, createRuntimeFallbackSignalRuntimeState, createRuntimeSignalError, createTelemetryAwareMetrics, createVictoriaMetricsTelemetryExporter, DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, DEFAULT_RUNTIME_STATUS_ENDPOINT, enforceRuntimeFallbackSignalAuthToken, enforceRuntimeFallbackSignalTrustPolicy, getRuntimeSignalErrorStatusCode, hasEnabledTelemetryExporters, injectTelemetryPlugin, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, type OtlpExporterOptions, parseRuntimeFallbackSignalPayloadFromRawBody, type RuntimeFallbackSignalAuthConfig, type RuntimeFallbackSignalRuntimeState, type RuntimeFallbackSignalSource, type RuntimeFallbackSignalTrustContext, type RuntimeFallbackSignalTrustPolicy, type RuntimeSignalError, type RuntimeSignalErrorCode, resolveRuntimeFallbackSignalEndpoint, resolveTelemetrySloOptions, type TelemetryContractGateStatus, type TelemetryEnvelope, type TelemetryExporter, type TelemetryHealthEvaluation, type TelemetryHealthFailure, type TelemetryHealthFailureReason, TelemetryHealthMonitor, type TelemetryHealthMonitorOptions, type TelemetryHealthState, type TelemetryHealthStatusSnapshot, type TelemetryHealthTransition, type TelemetryQueueStats, TelemetryRegistry, type TelemetryRegistryOptions, type TelemetrySignalType, type TelemetrySloAlert, TelemetryStartupHealthError, type VictoriaMetricsExporterOptions, } from './telemetry';
@@ -9,8 +9,8 @@ export declare function normalizeRuntimeFallbackSignalAuthConfig(configured: {
9
9
  } | undefined): RuntimeFallbackSignalAuthConfig;
10
10
  /**
11
11
  * Normalizes auth config for the runtime fallback signal endpoint when the
12
- * endpoint itself is enabled. The endpoint can persist failing contract gates
13
- * (a canary kill switch), so it always requires a token.
12
+ * endpoint itself is enabled. The endpoint records observed failing contract
13
+ * gates, so it always requires a token.
14
14
  */
15
15
  export declare function normalizeRequiredRuntimeFallbackSignalAuthConfig(configured: Parameters<typeof normalizeRuntimeFallbackSignalAuthConfig>[0]): RuntimeFallbackSignalAuthConfig;
16
16
  export declare function enforceRuntimeFallbackSignalAuthToken(token: string | undefined, authConfig: RuntimeFallbackSignalAuthConfig): void;
@@ -0,0 +1,10 @@
1
+ export type ServerRuntimeHandle = (request: Request, ...args: any[]) => Response | Promise<Response>;
2
+ export type DisposableServerRuntimeHandle = ServerRuntimeHandle & {
3
+ dispose: () => Promise<void>;
4
+ };
5
+ type RuntimeDisposer = () => void | Promise<void>;
6
+ export declare const registerServerRuntimeDisposer: (owner: object, disposer: RuntimeDisposer) => () => void;
7
+ export declare const disposeServerRuntime: (owner: object) => Promise<void>;
8
+ export declare const createDisposableServerRuntimeHandle: (owner: object, handle: ServerRuntimeHandle) => DisposableServerRuntimeHandle;
9
+ export declare const initializeDisposableServerRuntime: (owner: object, handle: ServerRuntimeHandle, initialize: () => Promise<void>) => Promise<DisposableServerRuntimeHandle>;
10
+ export {};
@@ -0,0 +1,20 @@
1
+ import type { TelemetryContractGateStatus, TelemetryHealthFailure } from './healthMonitor';
2
+ import type { TelemetryQueueStats } from './registryTypes';
3
+ interface TelemetryHealthMetrics {
4
+ queueStats: TelemetryQueueStats;
5
+ unhealthyExporterCount: number;
6
+ requiredContractGates: readonly string[];
7
+ contractGates: ReadonlyMap<string, TelemetryContractGateStatus>;
8
+ }
9
+ interface TelemetryHealthThresholds {
10
+ maxQueueUtilization: number;
11
+ maxTotalDropped: number;
12
+ maxUnhealthyExporters: number;
13
+ }
14
+ export interface TelemetryHealthEvaluationResult {
15
+ failures: TelemetryHealthFailure[];
16
+ queueStats: TelemetryQueueStats;
17
+ unhealthyExporterCount: number;
18
+ }
19
+ export declare const evaluateTelemetryHealth: (metrics: TelemetryHealthMetrics, thresholds: TelemetryHealthThresholds) => TelemetryHealthEvaluationResult;
20
+ export {};