@smithers-orchestrator/observability 0.16.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 (202) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +44 -0
  3. package/src/MetricName.ts +1 -0
  4. package/src/MetricsServiceLive.js +9 -0
  5. package/src/ResolvedSmithersObservabilityOptions.ts +10 -0
  6. package/src/SmithersEvent.ts +603 -0
  7. package/src/SmithersLogFormat.ts +1 -0
  8. package/src/SmithersMetricDefinition.ts +15 -0
  9. package/src/SmithersMetricType.ts +1 -0
  10. package/src/SmithersMetricUnit.ts +8 -0
  11. package/src/SmithersObservability.js +6 -0
  12. package/src/SmithersObservabilityOptions.ts +10 -0
  13. package/src/SmithersObservabilityService.ts +15 -0
  14. package/src/_coreCorrelation/CorrelationContext.ts +10 -0
  15. package/src/_coreCorrelation/CorrelationContextLive.js +11 -0
  16. package/src/_coreCorrelation/CorrelationContextService.js +6 -0
  17. package/src/_coreCorrelation/CorrelationContextServiceShape.ts +14 -0
  18. package/src/_coreCorrelation/CorrelationPatch.ts +3 -0
  19. package/src/_coreCorrelation/_correlationStorage.js +4 -0
  20. package/src/_coreCorrelation/correlationContextFiberRef.js +2 -0
  21. package/src/_coreCorrelation/correlationContextToLogAnnotations.js +28 -0
  22. package/src/_coreCorrelation/getCurrentCorrelationContext.js +9 -0
  23. package/src/_coreCorrelation/getCurrentCorrelationContextEffect.js +11 -0
  24. package/src/_coreCorrelation/index.js +14 -0
  25. package/src/_coreCorrelation/mergeCorrelationContext.js +61 -0
  26. package/src/_coreCorrelation/runWithCorrelationContext.js +14 -0
  27. package/src/_coreCorrelation/updateCurrentCorrelationContext.js +19 -0
  28. package/src/_coreCorrelation/withCorrelationContext.js +15 -0
  29. package/src/_coreCorrelation/withCurrentCorrelationContext.js +13 -0
  30. package/src/_coreMetrics.js +510 -0
  31. package/src/_coreMetricsShape.ts +55 -0
  32. package/src/_corePrometheus.js +93 -0
  33. package/src/_corePrometheusShape.ts +11 -0
  34. package/src/_coreTracing.js +142 -0
  35. package/src/_coreTracingShape.ts +17 -0
  36. package/src/_smithersSpanAttributeAliases.js +19 -0
  37. package/src/_smithersTraceSpanStorage.js +3 -0
  38. package/src/annotateSmithersTrace.js +11 -0
  39. package/src/correlation.js +20 -0
  40. package/src/createSmithersObservabilityLayer.js +49 -0
  41. package/src/createSmithersOtelLayer.js +21 -0
  42. package/src/createSmithersRuntimeLayer.js +2 -0
  43. package/src/getCurrentSmithersTraceAnnotations.js +14 -0
  44. package/src/getCurrentSmithersTraceSpan.js +7 -0
  45. package/src/index.d.ts +1032 -0
  46. package/src/index.js +35 -0
  47. package/src/logging.js +91 -0
  48. package/src/makeSmithersSpanAttributes.js +20 -0
  49. package/src/metrics/SmithersMetricDefinition.ts +17 -0
  50. package/src/metrics/SmithersMetricType.ts +1 -0
  51. package/src/metrics/SmithersMetricUnit.ts +8 -0
  52. package/src/metrics/_asyncExternalWaitCounts.js +4 -0
  53. package/src/metrics/_buckets.js +43 -0
  54. package/src/metrics/_processStartMs.js +1 -0
  55. package/src/metrics/activeNodes.js +2 -0
  56. package/src/metrics/activeRuns.js +2 -0
  57. package/src/metrics/agentActionsTotal.js +2 -0
  58. package/src/metrics/agentDurationMs.js +3 -0
  59. package/src/metrics/agentErrorsTotal.js +2 -0
  60. package/src/metrics/agentEventsTotal.js +2 -0
  61. package/src/metrics/agentInvocationsTotal.js +2 -0
  62. package/src/metrics/agentRetriesTotal.js +2 -0
  63. package/src/metrics/agentSessionsTotal.js +2 -0
  64. package/src/metrics/agentTokensTotal.js +2 -0
  65. package/src/metrics/alertDeliveriesAttempted.js +2 -0
  66. package/src/metrics/alertDeliveriesSuppressed.js +2 -0
  67. package/src/metrics/alertsAcknowledgedTotal.js +2 -0
  68. package/src/metrics/alertsActive.js +2 -0
  69. package/src/metrics/alertsEscalatedTotal.js +2 -0
  70. package/src/metrics/alertsFiredTotal.js +2 -0
  71. package/src/metrics/alertsReopenedTotal.js +2 -0
  72. package/src/metrics/alertsResolvedTotal.js +2 -0
  73. package/src/metrics/alertsSilencedTotal.js +2 -0
  74. package/src/metrics/approvalPending.js +2 -0
  75. package/src/metrics/approvalWaitDuration.js +3 -0
  76. package/src/metrics/approvalsDenied.js +2 -0
  77. package/src/metrics/approvalsGranted.js +2 -0
  78. package/src/metrics/approvalsRequested.js +2 -0
  79. package/src/metrics/attemptDuration.js +3 -0
  80. package/src/metrics/attentionBacklog.js +2 -0
  81. package/src/metrics/cacheHits.js +2 -0
  82. package/src/metrics/cacheMisses.js +2 -0
  83. package/src/metrics/dbQueryDuration.js +3 -0
  84. package/src/metrics/dbRetries.js +2 -0
  85. package/src/metrics/dbTransactionDuration.js +3 -0
  86. package/src/metrics/dbTransactionRetries.js +2 -0
  87. package/src/metrics/dbTransactionRollbacks.js +2 -0
  88. package/src/metrics/devtoolsActiveSubscribers.js +2 -0
  89. package/src/metrics/devtoolsBackpressureDisconnectTotal.js +2 -0
  90. package/src/metrics/devtoolsDeltaBuildMs.js +3 -0
  91. package/src/metrics/devtoolsEventBytes.js +3 -0
  92. package/src/metrics/devtoolsEventTotal.js +2 -0
  93. package/src/metrics/devtoolsSnapshotBuildMs.js +3 -0
  94. package/src/metrics/devtoolsSubscribeTotal.js +2 -0
  95. package/src/metrics/errorsTotal.js +2 -0
  96. package/src/metrics/eventsEmittedTotal.js +2 -0
  97. package/src/metrics/externalWaitAsyncPending.js +2 -0
  98. package/src/metrics/gatewayApprovalDecisionsTotal.js +2 -0
  99. package/src/metrics/gatewayAuthEventsTotal.js +2 -0
  100. package/src/metrics/gatewayConnectionsActive.js +2 -0
  101. package/src/metrics/gatewayConnectionsClosedTotal.js +2 -0
  102. package/src/metrics/gatewayConnectionsTotal.js +2 -0
  103. package/src/metrics/gatewayCronTriggersTotal.js +2 -0
  104. package/src/metrics/gatewayErrorsTotal.js +2 -0
  105. package/src/metrics/gatewayHeartbeatTicksTotal.js +2 -0
  106. package/src/metrics/gatewayMessagesReceivedTotal.js +2 -0
  107. package/src/metrics/gatewayMessagesSentTotal.js +2 -0
  108. package/src/metrics/gatewayRpcCallsTotal.js +2 -0
  109. package/src/metrics/gatewayRpcDuration.js +3 -0
  110. package/src/metrics/gatewayRunsCompletedTotal.js +2 -0
  111. package/src/metrics/gatewayRunsStartedTotal.js +2 -0
  112. package/src/metrics/gatewaySignalsTotal.js +2 -0
  113. package/src/metrics/gatewayWebhooksReceivedTotal.js +2 -0
  114. package/src/metrics/gatewayWebhooksRejectedTotal.js +2 -0
  115. package/src/metrics/gatewayWebhooksVerifiedTotal.js +2 -0
  116. package/src/metrics/heartbeatDataSizeBytes.js +3 -0
  117. package/src/metrics/heartbeatIntervalMs.js +3 -0
  118. package/src/metrics/hotReloadDuration.js +3 -0
  119. package/src/metrics/hotReloadFailures.js +2 -0
  120. package/src/metrics/hotReloads.js +2 -0
  121. package/src/metrics/httpRequestDuration.js +3 -0
  122. package/src/metrics/httpRequests.js +2 -0
  123. package/src/metrics/index.js +151 -0
  124. package/src/metrics/metricsServiceAdapter.js +188 -0
  125. package/src/metrics/nodeDuration.js +3 -0
  126. package/src/metrics/nodeRetriesTotal.js +2 -0
  127. package/src/metrics/nodesFailed.js +2 -0
  128. package/src/metrics/nodesFinished.js +2 -0
  129. package/src/metrics/nodesStarted.js +2 -0
  130. package/src/metrics/processHeapUsedBytes.js +2 -0
  131. package/src/metrics/processMemoryRssBytes.js +2 -0
  132. package/src/metrics/processUptimeSeconds.js +2 -0
  133. package/src/metrics/promptSizeBytes.js +3 -0
  134. package/src/metrics/responseSizeBytes.js +3 -0
  135. package/src/metrics/rewindDurationMs.js +3 -0
  136. package/src/metrics/rewindFramesDeleted.js +3 -0
  137. package/src/metrics/rewindRollbackTotal.js +2 -0
  138. package/src/metrics/rewindSandboxesReverted.js +3 -0
  139. package/src/metrics/rewindTotal.js +2 -0
  140. package/src/metrics/runDuration.js +3 -0
  141. package/src/metrics/runsAncestryDepth.js +3 -0
  142. package/src/metrics/runsCancelledTotal.js +2 -0
  143. package/src/metrics/runsCarriedStateBytes.js +3 -0
  144. package/src/metrics/runsContinuedTotal.js +2 -0
  145. package/src/metrics/runsFailedTotal.js +2 -0
  146. package/src/metrics/runsFinishedTotal.js +2 -0
  147. package/src/metrics/runsResumedTotal.js +2 -0
  148. package/src/metrics/runsTotal.js +2 -0
  149. package/src/metrics/sandboxActive.js +2 -0
  150. package/src/metrics/sandboxBundleSizeBytes.js +3 -0
  151. package/src/metrics/sandboxCompletedTotal.js +2 -0
  152. package/src/metrics/sandboxCreatedTotal.js +2 -0
  153. package/src/metrics/sandboxDurationMs.js +3 -0
  154. package/src/metrics/sandboxPatchCount.js +3 -0
  155. package/src/metrics/sandboxTransportDurationMs.js +3 -0
  156. package/src/metrics/schedulerConcurrencyUtilization.js +2 -0
  157. package/src/metrics/schedulerQueueDepth.js +2 -0
  158. package/src/metrics/schedulerWaitDuration.js +3 -0
  159. package/src/metrics/scorerEventsFailed.js +2 -0
  160. package/src/metrics/scorerEventsFinished.js +2 -0
  161. package/src/metrics/scorerEventsStarted.js +2 -0
  162. package/src/metrics/smithersMetricCatalog.js +484 -0
  163. package/src/metrics/smithersMetricCatalogByKey.js +2 -0
  164. package/src/metrics/smithersMetricCatalogByName.js +2 -0
  165. package/src/metrics/smithersMetricCatalogByPrometheusName.js +2 -0
  166. package/src/metrics/supervisorPollDuration.js +3 -0
  167. package/src/metrics/supervisorPollsTotal.js +2 -0
  168. package/src/metrics/supervisorResumeLag.js +3 -0
  169. package/src/metrics/supervisorResumedTotal.js +2 -0
  170. package/src/metrics/supervisorSkippedTotal.js +2 -0
  171. package/src/metrics/supervisorStaleDetected.js +2 -0
  172. package/src/metrics/taskHeartbeatTimeoutTotal.js +2 -0
  173. package/src/metrics/taskHeartbeatsTotal.js +2 -0
  174. package/src/metrics/timerDelayDuration.js +3 -0
  175. package/src/metrics/timersCancelled.js +2 -0
  176. package/src/metrics/timersCreated.js +2 -0
  177. package/src/metrics/timersFired.js +2 -0
  178. package/src/metrics/timersPending.js +2 -0
  179. package/src/metrics/toPrometheusMetricName.js +8 -0
  180. package/src/metrics/tokensCacheReadTotal.js +2 -0
  181. package/src/metrics/tokensCacheWriteTotal.js +2 -0
  182. package/src/metrics/tokensContextWindowBucketTotal.js +2 -0
  183. package/src/metrics/tokensContextWindowPerCall.js +3 -0
  184. package/src/metrics/tokensInputPerCall.js +3 -0
  185. package/src/metrics/tokensInputTotal.js +2 -0
  186. package/src/metrics/tokensOutputPerCall.js +3 -0
  187. package/src/metrics/tokensOutputTotal.js +2 -0
  188. package/src/metrics/tokensReasoningTotal.js +2 -0
  189. package/src/metrics/toolCallErrorsTotal.js +2 -0
  190. package/src/metrics/toolCallsTotal.js +2 -0
  191. package/src/metrics/toolDuration.js +3 -0
  192. package/src/metrics/toolOutputTruncatedTotal.js +2 -0
  193. package/src/metrics/trackEvent.js +604 -0
  194. package/src/metrics/updateAsyncExternalWaitPending.js +14 -0
  195. package/src/metrics/updateProcessMetrics.js +17 -0
  196. package/src/metrics/vcsDuration.js +3 -0
  197. package/src/prometheusContentType.js +1 -0
  198. package/src/renderPrometheusMetrics.js +205 -0
  199. package/src/resolveSmithersObservabilityOptions.js +79 -0
  200. package/src/smithersMetrics.js +2 -0
  201. package/src/smithersSpanNames.js +6 -0
  202. package/src/withSmithersSpan.js +15 -0
@@ -0,0 +1,151 @@
1
+ /** @typedef {import("../SmithersMetricDefinition.ts").SmithersMetricDefinition} SmithersMetricDefinition */
2
+ /** @typedef {import("../SmithersMetricType.ts").SmithersMetricType} SmithersMetricType */
3
+ /** @typedef {import("../SmithersMetricUnit.ts").SmithersMetricUnit} SmithersMetricUnit */
4
+
5
+ // Functions
6
+ export { toPrometheusMetricName } from "./toPrometheusMetricName.js";
7
+ export { updateProcessMetrics } from "./updateProcessMetrics.js";
8
+ export { updateAsyncExternalWaitPending } from "./updateAsyncExternalWaitPending.js";
9
+ export { trackEvent } from "./trackEvent.js";
10
+ // Catalog
11
+ export { smithersMetricCatalog } from "./smithersMetricCatalog.js";
12
+ export { smithersMetricCatalogByKey } from "./smithersMetricCatalogByKey.js";
13
+ export { smithersMetricCatalogByName } from "./smithersMetricCatalogByName.js";
14
+ export { smithersMetricCatalogByPrometheusName } from "./smithersMetricCatalogByPrometheusName.js";
15
+ // Service adapter
16
+ export { metricsServiceAdapter } from "./metricsServiceAdapter.js";
17
+ // Counters
18
+ export { runsTotal } from "./runsTotal.js";
19
+ export { nodesStarted } from "./nodesStarted.js";
20
+ export { nodesFinished } from "./nodesFinished.js";
21
+ export { nodesFailed } from "./nodesFailed.js";
22
+ export { toolCallsTotal } from "./toolCallsTotal.js";
23
+ export { cacheHits } from "./cacheHits.js";
24
+ export { cacheMisses } from "./cacheMisses.js";
25
+ export { dbRetries } from "./dbRetries.js";
26
+ export { dbTransactionRollbacks } from "./dbTransactionRollbacks.js";
27
+ export { dbTransactionRetries } from "./dbTransactionRetries.js";
28
+ export { hotReloads } from "./hotReloads.js";
29
+ export { hotReloadFailures } from "./hotReloadFailures.js";
30
+ export { httpRequests } from "./httpRequests.js";
31
+ export { approvalsRequested } from "./approvalsRequested.js";
32
+ export { approvalsGranted } from "./approvalsGranted.js";
33
+ export { approvalsDenied } from "./approvalsDenied.js";
34
+ export { timersCreated } from "./timersCreated.js";
35
+ export { timersFired } from "./timersFired.js";
36
+ export { timersCancelled } from "./timersCancelled.js";
37
+ export { sandboxCreatedTotal } from "./sandboxCreatedTotal.js";
38
+ export { sandboxCompletedTotal } from "./sandboxCompletedTotal.js";
39
+ export { alertsFiredTotal } from "./alertsFiredTotal.js";
40
+ export { alertsAcknowledgedTotal } from "./alertsAcknowledgedTotal.js";
41
+ export { alertsResolvedTotal } from "./alertsResolvedTotal.js";
42
+ export { alertsSilencedTotal } from "./alertsSilencedTotal.js";
43
+ export { alertsReopenedTotal } from "./alertsReopenedTotal.js";
44
+ export { alertsEscalatedTotal } from "./alertsEscalatedTotal.js";
45
+ export { alertDeliveriesAttempted } from "./alertDeliveriesAttempted.js";
46
+ export { alertDeliveriesSuppressed } from "./alertDeliveriesSuppressed.js";
47
+ export { scorerEventsStarted } from "./scorerEventsStarted.js";
48
+ export { scorerEventsFinished } from "./scorerEventsFinished.js";
49
+ export { scorerEventsFailed } from "./scorerEventsFailed.js";
50
+ export { tokensInputTotal } from "./tokensInputTotal.js";
51
+ export { tokensOutputTotal } from "./tokensOutputTotal.js";
52
+ export { tokensCacheReadTotal } from "./tokensCacheReadTotal.js";
53
+ export { tokensCacheWriteTotal } from "./tokensCacheWriteTotal.js";
54
+ export { tokensReasoningTotal } from "./tokensReasoningTotal.js";
55
+ export { tokensContextWindowBucketTotal } from "./tokensContextWindowBucketTotal.js";
56
+ export { runsFinishedTotal } from "./runsFinishedTotal.js";
57
+ export { runsFailedTotal } from "./runsFailedTotal.js";
58
+ export { runsCancelledTotal } from "./runsCancelledTotal.js";
59
+ export { runsResumedTotal } from "./runsResumedTotal.js";
60
+ export { runsContinuedTotal } from "./runsContinuedTotal.js";
61
+ export { supervisorPollsTotal } from "./supervisorPollsTotal.js";
62
+ export { supervisorStaleDetected } from "./supervisorStaleDetected.js";
63
+ export { supervisorResumedTotal } from "./supervisorResumedTotal.js";
64
+ export { supervisorSkippedTotal } from "./supervisorSkippedTotal.js";
65
+ export { errorsTotal } from "./errorsTotal.js";
66
+ export { nodeRetriesTotal } from "./nodeRetriesTotal.js";
67
+ export { toolCallErrorsTotal } from "./toolCallErrorsTotal.js";
68
+ export { toolOutputTruncatedTotal } from "./toolOutputTruncatedTotal.js";
69
+ export { agentInvocationsTotal } from "./agentInvocationsTotal.js";
70
+ export { agentTokensTotal } from "./agentTokensTotal.js";
71
+ export { agentErrorsTotal } from "./agentErrorsTotal.js";
72
+ export { agentRetriesTotal } from "./agentRetriesTotal.js";
73
+ export { agentEventsTotal } from "./agentEventsTotal.js";
74
+ export { agentSessionsTotal } from "./agentSessionsTotal.js";
75
+ export { agentActionsTotal } from "./agentActionsTotal.js";
76
+ export { gatewayConnectionsTotal } from "./gatewayConnectionsTotal.js";
77
+ export { gatewayConnectionsClosedTotal } from "./gatewayConnectionsClosedTotal.js";
78
+ export { gatewayMessagesReceivedTotal } from "./gatewayMessagesReceivedTotal.js";
79
+ export { gatewayMessagesSentTotal } from "./gatewayMessagesSentTotal.js";
80
+ export { gatewayRpcCallsTotal } from "./gatewayRpcCallsTotal.js";
81
+ export { gatewayErrorsTotal } from "./gatewayErrorsTotal.js";
82
+ export { gatewayRunsStartedTotal } from "./gatewayRunsStartedTotal.js";
83
+ export { gatewayRunsCompletedTotal } from "./gatewayRunsCompletedTotal.js";
84
+ export { gatewayApprovalDecisionsTotal } from "./gatewayApprovalDecisionsTotal.js";
85
+ export { gatewaySignalsTotal } from "./gatewaySignalsTotal.js";
86
+ export { gatewayAuthEventsTotal } from "./gatewayAuthEventsTotal.js";
87
+ export { gatewayHeartbeatTicksTotal } from "./gatewayHeartbeatTicksTotal.js";
88
+ export { gatewayCronTriggersTotal } from "./gatewayCronTriggersTotal.js";
89
+ export { gatewayWebhooksReceivedTotal } from "./gatewayWebhooksReceivedTotal.js";
90
+ export { gatewayWebhooksVerifiedTotal } from "./gatewayWebhooksVerifiedTotal.js";
91
+ export { gatewayWebhooksRejectedTotal } from "./gatewayWebhooksRejectedTotal.js";
92
+ export { devtoolsSubscribeTotal } from "./devtoolsSubscribeTotal.js";
93
+ export { devtoolsEventTotal } from "./devtoolsEventTotal.js";
94
+ export { devtoolsBackpressureDisconnectTotal } from "./devtoolsBackpressureDisconnectTotal.js";
95
+ export { eventsEmittedTotal } from "./eventsEmittedTotal.js";
96
+ export { taskHeartbeatsTotal } from "./taskHeartbeatsTotal.js";
97
+ export { taskHeartbeatTimeoutTotal } from "./taskHeartbeatTimeoutTotal.js";
98
+ // Gauges
99
+ export { activeRuns } from "./activeRuns.js";
100
+ export { activeNodes } from "./activeNodes.js";
101
+ export { schedulerQueueDepth } from "./schedulerQueueDepth.js";
102
+ export { sandboxActive } from "./sandboxActive.js";
103
+ export { alertsActive } from "./alertsActive.js";
104
+ export { attentionBacklog } from "./attentionBacklog.js";
105
+ export { gatewayConnectionsActive } from "./gatewayConnectionsActive.js";
106
+ export { approvalPending } from "./approvalPending.js";
107
+ export { externalWaitAsyncPending } from "./externalWaitAsyncPending.js";
108
+ export { timersPending } from "./timersPending.js";
109
+ export { schedulerConcurrencyUtilization } from "./schedulerConcurrencyUtilization.js";
110
+ export { processUptimeSeconds } from "./processUptimeSeconds.js";
111
+ export { processMemoryRssBytes } from "./processMemoryRssBytes.js";
112
+ export { processHeapUsedBytes } from "./processHeapUsedBytes.js";
113
+ export { devtoolsActiveSubscribers } from "./devtoolsActiveSubscribers.js";
114
+ // Histograms
115
+ export { nodeDuration } from "./nodeDuration.js";
116
+ export { attemptDuration } from "./attemptDuration.js";
117
+ export { toolDuration } from "./toolDuration.js";
118
+ export { dbQueryDuration } from "./dbQueryDuration.js";
119
+ export { dbTransactionDuration } from "./dbTransactionDuration.js";
120
+ export { httpRequestDuration } from "./httpRequestDuration.js";
121
+ export { hotReloadDuration } from "./hotReloadDuration.js";
122
+ export { vcsDuration } from "./vcsDuration.js";
123
+ export { agentDurationMs } from "./agentDurationMs.js";
124
+ export { tokensInputPerCall } from "./tokensInputPerCall.js";
125
+ export { tokensOutputPerCall } from "./tokensOutputPerCall.js";
126
+ export { tokensContextWindowPerCall } from "./tokensContextWindowPerCall.js";
127
+ export { runDuration } from "./runDuration.js";
128
+ export { promptSizeBytes } from "./promptSizeBytes.js";
129
+ export { responseSizeBytes } from "./responseSizeBytes.js";
130
+ export { approvalWaitDuration } from "./approvalWaitDuration.js";
131
+ export { timerDelayDuration } from "./timerDelayDuration.js";
132
+ export { gatewayRpcDuration } from "./gatewayRpcDuration.js";
133
+ export { schedulerWaitDuration } from "./schedulerWaitDuration.js";
134
+ export { supervisorPollDuration } from "./supervisorPollDuration.js";
135
+ export { supervisorResumeLag } from "./supervisorResumeLag.js";
136
+ export { runsAncestryDepth } from "./runsAncestryDepth.js";
137
+ export { runsCarriedStateBytes } from "./runsCarriedStateBytes.js";
138
+ export { sandboxDurationMs } from "./sandboxDurationMs.js";
139
+ export { sandboxBundleSizeBytes } from "./sandboxBundleSizeBytes.js";
140
+ export { sandboxTransportDurationMs } from "./sandboxTransportDurationMs.js";
141
+ export { sandboxPatchCount } from "./sandboxPatchCount.js";
142
+ export { heartbeatDataSizeBytes } from "./heartbeatDataSizeBytes.js";
143
+ export { heartbeatIntervalMs } from "./heartbeatIntervalMs.js";
144
+ export { devtoolsSnapshotBuildMs } from "./devtoolsSnapshotBuildMs.js";
145
+ export { devtoolsDeltaBuildMs } from "./devtoolsDeltaBuildMs.js";
146
+ export { devtoolsEventBytes } from "./devtoolsEventBytes.js";
147
+ export { rewindTotal } from "./rewindTotal.js";
148
+ export { rewindRollbackTotal } from "./rewindRollbackTotal.js";
149
+ export { rewindDurationMs } from "./rewindDurationMs.js";
150
+ export { rewindFramesDeleted } from "./rewindFramesDeleted.js";
151
+ export { rewindSandboxesReverted } from "./rewindSandboxesReverted.js";
@@ -0,0 +1,188 @@
1
+ import {} from "../_coreMetrics.js";
2
+ import { renderPrometheusSamples, } from "../_corePrometheus.js";
3
+ import { Effect, Metric, MetricState } from "effect";
4
+ import { toPrometheusMetricName } from "./toPrometheusMetricName.js";
5
+ import { durationBuckets } from "./_buckets.js";
6
+ import { smithersMetricCatalogByName } from "./smithersMetricCatalogByName.js";
7
+ import { smithersMetricCatalogByPrometheusName } from "./smithersMetricCatalogByPrometheusName.js";
8
+ import { trackEvent } from "./trackEvent.js";
9
+ import { updateProcessMetrics } from "./updateProcessMetrics.js";
10
+ import { updateAsyncExternalWaitPending } from "./updateAsyncExternalWaitPending.js";
11
+ /** @typedef {import("./SmithersMetricDefinition.ts").SmithersMetricDefinition} SmithersMetricDefinition */
12
+ /** @typedef {import("../_coreMetricsShape.ts").MetricsServiceShape} MetricsServiceShape */
13
+ /** @typedef {import("../_corePrometheusShape.ts").MetricLabels} MetricLabels */
14
+ /** @typedef {import("../_corePrometheusShape.ts").PrometheusSample} PrometheusSample */
15
+ /** @typedef {import("../_coreMetricsShape.ts").MetricsSnapshot} MetricsSnapshot */
16
+
17
+ /**
18
+ * @param {string} name
19
+ * @returns {SmithersMetricDefinition | undefined}
20
+ */
21
+ function resolveMetricDefinition(name) {
22
+ return (smithersMetricCatalogByName.get(name) ??
23
+ smithersMetricCatalogByPrometheusName.get(toPrometheusMetricName(name)));
24
+ }
25
+ /**
26
+ * @template A
27
+ * @param {A} metric
28
+ * @param {MetricLabels} [labels]
29
+ * @returns {A}
30
+ */
31
+ function tagMetricWithLabels(metric, labels) {
32
+ let tagged = metric;
33
+ for (const [key, value] of Object.entries(labels ?? {})) {
34
+ tagged = Metric.tagged(tagged, key, String(value));
35
+ }
36
+ return tagged;
37
+ }
38
+ /**
39
+ * @param {string} name
40
+ * @param {MetricLabels} [labels]
41
+ * @returns {Metric.Metric<any, number, any>}
42
+ */
43
+ function counterOrGaugeMetric(name, labels) {
44
+ const definition = resolveMetricDefinition(name);
45
+ const metric = definition?.type === "counter" || definition?.type === "gauge"
46
+ ? definition.metric
47
+ : Metric.counter(name);
48
+ return tagMetricWithLabels(metric, labels);
49
+ }
50
+ /**
51
+ * @param {string} name
52
+ * @param {MetricLabels} [labels]
53
+ * @returns {Metric.Metric<any, number, any>}
54
+ */
55
+ function gaugeMetric(name, labels) {
56
+ const definition = resolveMetricDefinition(name);
57
+ const metric = definition?.type === "gauge" ? definition.metric : Metric.gauge(name);
58
+ return tagMetricWithLabels(metric, labels);
59
+ }
60
+ /**
61
+ * @param {string} name
62
+ * @param {MetricLabels} [labels]
63
+ * @returns {Metric.Metric<any, number, any>}
64
+ */
65
+ function histogramMetric(name, labels) {
66
+ const definition = resolveMetricDefinition(name);
67
+ const metric = definition?.type === "histogram"
68
+ ? definition.metric
69
+ : Metric.histogram(name, durationBuckets);
70
+ return tagMetricWithLabels(metric, labels);
71
+ }
72
+ /**
73
+ * @param {number | bigint | undefined} value
74
+ * @returns {number}
75
+ */
76
+ function metricValueAsNumber(value) {
77
+ if (typeof value === "bigint")
78
+ return Number(value);
79
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
80
+ }
81
+ /**
82
+ * @param {any} metricKey
83
+ * @returns {MetricLabels}
84
+ */
85
+ function metricsServiceLabels(metricKey) {
86
+ const tags = Array.isArray(metricKey?.tags) ? metricKey.tags : [];
87
+ return Object.freeze(Object.fromEntries(tags
88
+ .map((tag) => [String(tag.key), String(tag.value)])
89
+ .sort(([left], [right]) => left.localeCompare(right))));
90
+ }
91
+ /**
92
+ * @param {MetricLabels} labels
93
+ * @returns {string}
94
+ */
95
+ function metricsServiceLabelsKey(labels) {
96
+ return JSON.stringify(Object.entries(labels).sort(([left], [right]) => left.localeCompare(right)));
97
+ }
98
+ /**
99
+ * @param {string} name
100
+ * @param {MetricLabels} labels
101
+ * @returns {string}
102
+ */
103
+ function metricsServiceSnapshotKey(name, labels) {
104
+ return `${name}|${metricsServiceLabelsKey(labels)}`;
105
+ }
106
+ /**
107
+ * @returns {PrometheusSample[]}
108
+ */
109
+ function metricsServicePrometheusSamples() {
110
+ const samples = [];
111
+ for (const snapshot of Metric.unsafeSnapshot()) {
112
+ const metricKey = snapshot.metricKey;
113
+ const metricState = snapshot.metricState;
114
+ const name = String(metricKey.name ?? "");
115
+ if (!name)
116
+ continue;
117
+ const labels = metricsServiceLabels(metricKey);
118
+ if (MetricState.isCounterState(metricState)) {
119
+ samples.push({
120
+ name,
121
+ type: "counter",
122
+ labels,
123
+ value: metricValueAsNumber(metricState.count),
124
+ });
125
+ continue;
126
+ }
127
+ if (MetricState.isGaugeState(metricState)) {
128
+ samples.push({
129
+ name,
130
+ type: "gauge",
131
+ labels,
132
+ value: metricValueAsNumber(metricState.value),
133
+ });
134
+ continue;
135
+ }
136
+ if (MetricState.isHistogramState(metricState)) {
137
+ samples.push({
138
+ name,
139
+ type: "histogram",
140
+ labels,
141
+ buckets: new Map([...metricState.buckets].map(([boundary, count]) => [
142
+ boundary,
143
+ metricValueAsNumber(count),
144
+ ])),
145
+ sum: metricValueAsNumber(metricState.sum),
146
+ count: metricValueAsNumber(metricState.count),
147
+ });
148
+ }
149
+ }
150
+ return samples;
151
+ }
152
+ /**
153
+ * @returns {MetricsSnapshot}
154
+ */
155
+ function metricsServiceSnapshot() {
156
+ const result = new Map();
157
+ for (const sample of metricsServicePrometheusSamples()) {
158
+ const key = metricsServiceSnapshotKey(sample.name, sample.labels);
159
+ if (sample.type === "histogram") {
160
+ result.set(key, {
161
+ type: "histogram",
162
+ sum: sample.sum ?? 0,
163
+ count: sample.count ?? 0,
164
+ labels: sample.labels,
165
+ buckets: new Map(sample.buckets ?? []),
166
+ });
167
+ continue;
168
+ }
169
+ result.set(key, {
170
+ type: sample.type,
171
+ value: sample.value ?? 0,
172
+ labels: sample.labels,
173
+ });
174
+ }
175
+ return result;
176
+ }
177
+ /** @type {MetricsServiceShape} */
178
+ export const metricsServiceAdapter = {
179
+ increment: (name, labels) => Metric.incrementBy(counterOrGaugeMetric(name, labels), 1),
180
+ incrementBy: (name, value, labels) => Metric.incrementBy(counterOrGaugeMetric(name, labels), value),
181
+ gauge: (name, value, labels) => Metric.set(gaugeMetric(name, labels), value),
182
+ histogram: (name, value, labels) => Metric.update(histogramMetric(name, labels), value),
183
+ recordEvent: (event) => trackEvent(event),
184
+ updateProcessMetrics: () => updateProcessMetrics(),
185
+ updateAsyncExternalWaitPending: (kind, delta) => updateAsyncExternalWaitPending(kind, delta),
186
+ renderPrometheus: () => Effect.sync(() => renderPrometheusSamples(metricsServicePrometheusSamples())),
187
+ snapshot: () => Effect.sync(metricsServiceSnapshot),
188
+ };
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const nodeDuration = Metric.histogram("smithers.node.duration_ms", durationBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const nodeRetriesTotal = Metric.counter("smithers.node.retries_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const nodesFailed = Metric.counter("smithers.nodes.failed");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const nodesFinished = Metric.counter("smithers.nodes.finished");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const nodesStarted = Metric.counter("smithers.nodes.started");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const processHeapUsedBytes = Metric.gauge("smithers.process.heap_used_bytes");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const processMemoryRssBytes = Metric.gauge("smithers.process.memory_rss_bytes");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const processUptimeSeconds = Metric.gauge("smithers.process.uptime_seconds");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { sizeBuckets } from "./_buckets.js";
3
+ export const promptSizeBytes = Metric.histogram("smithers.prompt.size_bytes", sizeBuckets);
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { sizeBuckets } from "./_buckets.js";
3
+ export const responseSizeBytes = Metric.histogram("smithers.response.size_bytes", sizeBuckets);
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const rewindDurationMs = Metric.histogram("smithers_rewind_duration_ms", durationBuckets);
@@ -0,0 +1,3 @@
1
+ import { MetricBoundaries, Metric } from "effect";
2
+ const buckets = MetricBoundaries.exponential({ start: 1, factor: 2, count: 18 });
3
+ export const rewindFramesDeleted = Metric.histogram("smithers_rewind_frames_deleted", buckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const rewindRollbackTotal = Metric.counter("smithers_rewind_rollback_total");
@@ -0,0 +1,3 @@
1
+ import { MetricBoundaries, Metric } from "effect";
2
+ const buckets = MetricBoundaries.fromIterable([0, 1, 2, 4, 8, 16, 32, 64]);
3
+ export const rewindSandboxesReverted = Metric.histogram("smithers_rewind_sandboxes_reverted", buckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const rewindTotal = Metric.counter("smithers_rewind_total");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const runDuration = Metric.histogram("smithers.run.duration_ms", durationBuckets);
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { ancestryDepthBuckets } from "./_buckets.js";
3
+ export const runsAncestryDepth = Metric.histogram("smithers.runs.ancestry_depth", ancestryDepthBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const runsCancelledTotal = Metric.counter("smithers.runs.cancelled_total");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { carriedStateSizeBuckets } from "./_buckets.js";
3
+ export const runsCarriedStateBytes = Metric.histogram("smithers.runs.carried_state_bytes", carriedStateSizeBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const runsContinuedTotal = Metric.counter("smithers.runs.continued_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const runsFailedTotal = Metric.counter("smithers.runs.failed_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const runsFinishedTotal = Metric.counter("smithers.runs.finished_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const runsResumedTotal = Metric.counter("smithers.runs.resumed_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const runsTotal = Metric.counter("smithers.runs.total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const sandboxActive = Metric.gauge("smithers.sandbox.active");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { sizeBuckets } from "./_buckets.js";
3
+ export const sandboxBundleSizeBytes = Metric.histogram("smithers.sandbox.bundle_size_bytes", sizeBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const sandboxCompletedTotal = Metric.counter("smithers.sandbox.completed_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const sandboxCreatedTotal = Metric.counter("smithers.sandbox.created_total");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const sandboxDurationMs = Metric.histogram("smithers.sandbox.duration_ms", durationBuckets);
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { tokenBuckets } from "./_buckets.js";
3
+ export const sandboxPatchCount = Metric.histogram("smithers.sandbox.patch_count", tokenBuckets);
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const sandboxTransportDurationMs = Metric.histogram("smithers.sandbox.transport_duration_ms", durationBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const schedulerConcurrencyUtilization = Metric.gauge("smithers.scheduler.concurrency_utilization");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const schedulerQueueDepth = Metric.gauge("smithers.scheduler.queue_depth");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const schedulerWaitDuration = Metric.histogram("smithers.scheduler.wait_duration_ms", durationBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const scorerEventsFailed = Metric.counter("smithers.scorer_events.failed");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const scorerEventsFinished = Metric.counter("smithers.scorer_events.finished");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const scorerEventsStarted = Metric.counter("smithers.scorer_events.started");