@smthrs/observability 0.33.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 (247) hide show
  1. package/LICENSE +21 -0
  2. package/docker-compose.otel.yml +104 -0
  3. package/grafana/dashboards/smithers-dashboard.json +453 -0
  4. package/grafana/provisioning/dashboards/dashboards.yml +12 -0
  5. package/grafana/provisioning/datasources/datasources.yml +49 -0
  6. package/loki/loki-config.yaml +35 -0
  7. package/otel-collector-config.yml +38 -0
  8. package/package.json +47 -0
  9. package/prometheus/prometheus.yml +8 -0
  10. package/src/MetricName.ts +1 -0
  11. package/src/MetricsServiceLive.js +9 -0
  12. package/src/README.md +28 -0
  13. package/src/ResolvedSmithersObservabilityOptions.ts +12 -0
  14. package/src/SmithersEvent.ts +773 -0
  15. package/src/SmithersLogFormat.ts +1 -0
  16. package/src/SmithersMetricDefinition.ts +15 -0
  17. package/src/SmithersMetricType.ts +1 -0
  18. package/src/SmithersMetricUnit.ts +1 -0
  19. package/src/SmithersObservability.js +15 -0
  20. package/src/SmithersObservabilityOptions.ts +12 -0
  21. package/src/SmithersObservabilityService.ts +13 -0
  22. package/src/_coreCorrelation/CorrelationContext.ts +10 -0
  23. package/src/_coreCorrelation/CorrelationContextLive.js +11 -0
  24. package/src/_coreCorrelation/CorrelationContextService.js +15 -0
  25. package/src/_coreCorrelation/CorrelationContextServiceShape.ts +12 -0
  26. package/src/_coreCorrelation/CorrelationPatch.ts +3 -0
  27. package/src/_coreCorrelation/README.md +20 -0
  28. package/src/_coreCorrelation/_correlationStorage.js +4 -0
  29. package/src/_coreCorrelation/correlationContextFiberRef.js +5 -0
  30. package/src/_coreCorrelation/correlationContextToLogAnnotations.js +18 -0
  31. package/src/_coreCorrelation/getCurrentCorrelationContext.js +9 -0
  32. package/src/_coreCorrelation/getCurrentCorrelationContextEffect.js +11 -0
  33. package/src/_coreCorrelation/index.js +14 -0
  34. package/src/_coreCorrelation/mergeCorrelationContext.js +51 -0
  35. package/src/_coreCorrelation/runWithCorrelationContext.js +14 -0
  36. package/src/_coreCorrelation/updateCurrentCorrelationContext.js +17 -0
  37. package/src/_coreCorrelation/withCorrelationContext.js +38 -0
  38. package/src/_coreCorrelation/withCurrentCorrelationContext.js +11 -0
  39. package/src/_coreMetrics.js +14 -0
  40. package/src/_coreMetricsShape.ts +44 -0
  41. package/src/_corePrometheus.js +91 -0
  42. package/src/_corePrometheusShape.ts +11 -0
  43. package/src/_coreTracing.js +132 -0
  44. package/src/_coreTracingShape.ts +17 -0
  45. package/src/_otelLogBuilders.js +102 -0
  46. package/src/_sessionFileResolvers.js +164 -0
  47. package/src/_smithersSpanAttributeAliases.js +19 -0
  48. package/src/_smithersTraceSpanStorage.js +3 -0
  49. package/src/_traceEventNormalizers.js +499 -0
  50. package/src/_traceRedaction.js +162 -0
  51. package/src/agentSessionEventToOtelLogRecord.js +55 -0
  52. package/src/agentTrace.ts +144 -0
  53. package/src/agentTraceCapabilities.js +151 -0
  54. package/src/annotateSmithersTrace.js +11 -0
  55. package/src/canonicalTraceEventToOtelLogRecord.js +55 -0
  56. package/src/correlation.js +56 -0
  57. package/src/createSmithersObservabilityLayer.js +59 -0
  58. package/src/createSmithersOtelLayer.js +23 -0
  59. package/src/createSmithersRuntimeLayer.js +2 -0
  60. package/src/detectAgentFamily.js +26 -0
  61. package/src/detectCaptureMode.js +24 -0
  62. package/src/emitOtelLogRecord.js +19 -0
  63. package/src/getCurrentSmithersTraceAnnotations.js +14 -0
  64. package/src/getCurrentSmithersTraceSpan.js +7 -0
  65. package/src/index.d.ts +1321 -0
  66. package/src/index.js +136 -0
  67. package/src/kindPhase.js +17 -0
  68. package/src/logging.js +248 -0
  69. package/src/makeSmithersSpanAttributes.js +20 -0
  70. package/src/metrics/README.md +22 -0
  71. package/src/metrics/SmithersMetricDefinition.ts +17 -0
  72. package/src/metrics/SmithersMetricType.ts +1 -0
  73. package/src/metrics/SmithersMetricUnit.ts +1 -0
  74. package/src/metrics/_asyncExternalWaitCounts.js +4 -0
  75. package/src/metrics/_buckets.js +37 -0
  76. package/src/metrics/_incrementGauge.js +11 -0
  77. package/src/metrics/_processStartMs.js +1 -0
  78. package/src/metrics/activeNodes.js +2 -0
  79. package/src/metrics/activeRuns.js +2 -0
  80. package/src/metrics/agentActionsTotal.js +2 -0
  81. package/src/metrics/agentDurationMs.js +3 -0
  82. package/src/metrics/agentErrorsTotal.js +2 -0
  83. package/src/metrics/agentEventsTotal.js +2 -0
  84. package/src/metrics/agentInvocationsTotal.js +2 -0
  85. package/src/metrics/agentRetriesTotal.js +2 -0
  86. package/src/metrics/agentSessionsTotal.js +2 -0
  87. package/src/metrics/agentTokensTotal.js +2 -0
  88. package/src/metrics/alertDeliveriesAttempted.js +2 -0
  89. package/src/metrics/alertDeliveriesSuppressed.js +2 -0
  90. package/src/metrics/alertsAcknowledgedTotal.js +2 -0
  91. package/src/metrics/alertsActive.js +2 -0
  92. package/src/metrics/alertsEscalatedTotal.js +2 -0
  93. package/src/metrics/alertsFiredTotal.js +2 -0
  94. package/src/metrics/alertsReopenedTotal.js +2 -0
  95. package/src/metrics/alertsResolvedTotal.js +2 -0
  96. package/src/metrics/alertsSilencedTotal.js +2 -0
  97. package/src/metrics/approvalPending.js +2 -0
  98. package/src/metrics/approvalWaitDuration.js +5 -0
  99. package/src/metrics/approvalsDenied.js +2 -0
  100. package/src/metrics/approvalsGranted.js +2 -0
  101. package/src/metrics/approvalsRequested.js +2 -0
  102. package/src/metrics/attemptDuration.js +3 -0
  103. package/src/metrics/attentionBacklog.js +2 -0
  104. package/src/metrics/cacheHits.js +2 -0
  105. package/src/metrics/cacheMisses.js +2 -0
  106. package/src/metrics/dbQueryDuration.js +3 -0
  107. package/src/metrics/dbRetries.js +2 -0
  108. package/src/metrics/dbTransactionDuration.js +3 -0
  109. package/src/metrics/dbTransactionRetries.js +2 -0
  110. package/src/metrics/dbTransactionRollbacks.js +2 -0
  111. package/src/metrics/devtoolsActiveSubscribers.js +2 -0
  112. package/src/metrics/devtoolsBackpressureDisconnectTotal.js +2 -0
  113. package/src/metrics/devtoolsDeltaBuildMs.js +3 -0
  114. package/src/metrics/devtoolsEventBytes.js +3 -0
  115. package/src/metrics/devtoolsEventTotal.js +2 -0
  116. package/src/metrics/devtoolsSnapshotBuildMs.js +5 -0
  117. package/src/metrics/devtoolsSubscribeTotal.js +2 -0
  118. package/src/metrics/errorsTotal.js +2 -0
  119. package/src/metrics/eventsEmittedTotal.js +2 -0
  120. package/src/metrics/externalWaitAsyncPending.js +2 -0
  121. package/src/metrics/gatewayApprovalDecisionsTotal.js +2 -0
  122. package/src/metrics/gatewayAuthEventsTotal.js +2 -0
  123. package/src/metrics/gatewayConnectionsActive.js +2 -0
  124. package/src/metrics/gatewayConnectionsClosedTotal.js +2 -0
  125. package/src/metrics/gatewayConnectionsTotal.js +2 -0
  126. package/src/metrics/gatewayCronTriggersTotal.js +2 -0
  127. package/src/metrics/gatewayErrorsTotal.js +2 -0
  128. package/src/metrics/gatewayHeartbeatTicksTotal.js +2 -0
  129. package/src/metrics/gatewayMessagesReceivedTotal.js +2 -0
  130. package/src/metrics/gatewayMessagesSentTotal.js +2 -0
  131. package/src/metrics/gatewayRpcCallsTotal.js +2 -0
  132. package/src/metrics/gatewayRpcDuration.js +3 -0
  133. package/src/metrics/gatewayRunEventBackpressureDisconnectTotal.js +4 -0
  134. package/src/metrics/gatewayRunsCompletedTotal.js +2 -0
  135. package/src/metrics/gatewayRunsStartedTotal.js +2 -0
  136. package/src/metrics/gatewaySignalsTotal.js +2 -0
  137. package/src/metrics/gatewayWebhooksReceivedTotal.js +2 -0
  138. package/src/metrics/gatewayWebhooksRejectedTotal.js +2 -0
  139. package/src/metrics/gatewayWebhooksVerifiedTotal.js +2 -0
  140. package/src/metrics/heartbeatDataSizeBytes.js +5 -0
  141. package/src/metrics/heartbeatIntervalMs.js +3 -0
  142. package/src/metrics/hotReloadDuration.js +3 -0
  143. package/src/metrics/hotReloadFailures.js +2 -0
  144. package/src/metrics/hotReloads.js +2 -0
  145. package/src/metrics/httpRequestDuration.js +3 -0
  146. package/src/metrics/httpRequests.js +2 -0
  147. package/src/metrics/index.d.ts +1163 -0
  148. package/src/metrics/index.js +168 -0
  149. package/src/metrics/memoryFactReads.js +3 -0
  150. package/src/metrics/memoryFactWrites.js +3 -0
  151. package/src/metrics/memoryMessageSaves.js +3 -0
  152. package/src/metrics/memoryRecallDuration.js +11 -0
  153. package/src/metrics/memoryRecallQueries.js +3 -0
  154. package/src/metrics/metricsServiceAdapter.js +181 -0
  155. package/src/metrics/nodeDuration.js +3 -0
  156. package/src/metrics/nodeRetriesTotal.js +2 -0
  157. package/src/metrics/nodesFailed.js +2 -0
  158. package/src/metrics/nodesFinished.js +2 -0
  159. package/src/metrics/nodesStarted.js +2 -0
  160. package/src/metrics/openApiToolCallErrorsTotal.js +3 -0
  161. package/src/metrics/openApiToolCallsTotal.js +3 -0
  162. package/src/metrics/openApiToolDuration.js +9 -0
  163. package/src/metrics/processHeapUsedBytes.js +2 -0
  164. package/src/metrics/processMemoryRssBytes.js +2 -0
  165. package/src/metrics/processUptimeSeconds.js +2 -0
  166. package/src/metrics/promptSizeBytes.js +3 -0
  167. package/src/metrics/replaysStarted.js +3 -0
  168. package/src/metrics/responseSizeBytes.js +3 -0
  169. package/src/metrics/rewindDurationMs.js +3 -0
  170. package/src/metrics/rewindFramesDeleted.js +3 -0
  171. package/src/metrics/rewindRollbackTotal.js +2 -0
  172. package/src/metrics/rewindSandboxesReverted.js +3 -0
  173. package/src/metrics/rewindTotal.js +2 -0
  174. package/src/metrics/runDuration.js +3 -0
  175. package/src/metrics/runForksCreated.js +3 -0
  176. package/src/metrics/runsAncestryDepth.js +3 -0
  177. package/src/metrics/runsCancelledTotal.js +2 -0
  178. package/src/metrics/runsCarriedStateBytes.js +5 -0
  179. package/src/metrics/runsContinuedTotal.js +2 -0
  180. package/src/metrics/runsFailedTotal.js +2 -0
  181. package/src/metrics/runsFinishedTotal.js +2 -0
  182. package/src/metrics/runsResumedTotal.js +2 -0
  183. package/src/metrics/runsTotal.js +2 -0
  184. package/src/metrics/sandboxActive.js +2 -0
  185. package/src/metrics/sandboxBundleSizeBytes.js +5 -0
  186. package/src/metrics/sandboxCompletedTotal.js +2 -0
  187. package/src/metrics/sandboxCreatedTotal.js +2 -0
  188. package/src/metrics/sandboxDurationMs.js +3 -0
  189. package/src/metrics/sandboxPatchCount.js +3 -0
  190. package/src/metrics/sandboxTransportDurationMs.js +5 -0
  191. package/src/metrics/schedulerConcurrencyUtilization.js +2 -0
  192. package/src/metrics/schedulerQueueDepth.js +2 -0
  193. package/src/metrics/schedulerWaitDuration.js +5 -0
  194. package/src/metrics/scorerDuration.js +9 -0
  195. package/src/metrics/scorerEventsFailed.js +2 -0
  196. package/src/metrics/scorerEventsFinished.js +2 -0
  197. package/src/metrics/scorerEventsStarted.js +2 -0
  198. package/src/metrics/scorersFailed.js +3 -0
  199. package/src/metrics/scorersFinished.js +3 -0
  200. package/src/metrics/scorersStarted.js +3 -0
  201. package/src/metrics/smithersMetricCatalog.js +893 -0
  202. package/src/metrics/smithersMetricCatalogByKey.js +2 -0
  203. package/src/metrics/smithersMetricCatalogByName.js +2 -0
  204. package/src/metrics/smithersMetricCatalogByPrometheusName.js +4 -0
  205. package/src/metrics/snapshotDuration.js +9 -0
  206. package/src/metrics/snapshotsCaptured.js +3 -0
  207. package/src/metrics/supervisorPollDuration.js +5 -0
  208. package/src/metrics/supervisorPollsTotal.js +2 -0
  209. package/src/metrics/supervisorResumeLag.js +5 -0
  210. package/src/metrics/supervisorResumedTotal.js +2 -0
  211. package/src/metrics/supervisorSkippedTotal.js +2 -0
  212. package/src/metrics/supervisorStaleDetected.js +2 -0
  213. package/src/metrics/taskHeartbeatTimeoutTotal.js +2 -0
  214. package/src/metrics/taskHeartbeatsTotal.js +2 -0
  215. package/src/metrics/timerDelayDuration.js +3 -0
  216. package/src/metrics/timersCancelled.js +2 -0
  217. package/src/metrics/timersCreated.js +2 -0
  218. package/src/metrics/timersFired.js +2 -0
  219. package/src/metrics/timersPending.js +2 -0
  220. package/src/metrics/toPrometheusMetricName.js +8 -0
  221. package/src/metrics/tokensCacheReadTotal.js +2 -0
  222. package/src/metrics/tokensCacheWriteTotal.js +2 -0
  223. package/src/metrics/tokensContextWindowBucketTotal.js +2 -0
  224. package/src/metrics/tokensContextWindowPerCall.js +5 -0
  225. package/src/metrics/tokensInputPerCall.js +3 -0
  226. package/src/metrics/tokensInputTotal.js +2 -0
  227. package/src/metrics/tokensOutputPerCall.js +3 -0
  228. package/src/metrics/tokensOutputTotal.js +2 -0
  229. package/src/metrics/tokensReasoningTotal.js +2 -0
  230. package/src/metrics/toolCallErrorsTotal.js +2 -0
  231. package/src/metrics/toolCallsTotal.js +2 -0
  232. package/src/metrics/toolDuration.js +3 -0
  233. package/src/metrics/toolOutputTruncatedTotal.js +2 -0
  234. package/src/metrics/trackEvent.js +608 -0
  235. package/src/metrics/updateAsyncExternalWaitPending.js +18 -0
  236. package/src/metrics/updateProcessMetrics.js +20 -0
  237. package/src/metrics/vcsDuration.js +3 -0
  238. package/src/normalizeStructuredEvent.js +15 -0
  239. package/src/prometheusContentType.js +1 -0
  240. package/src/renderPrometheusMetrics.js +212 -0
  241. package/src/resolveAgentTraceCapabilities.js +59 -0
  242. package/src/resolveSmithersObservabilityOptions.js +109 -0
  243. package/src/smithersMetrics.js +2 -0
  244. package/src/smithersSpanNames.js +6 -0
  245. package/src/unsupportedKindsForCapabilities.js +32 -0
  246. package/src/withSmithersSpan.js +17 -0
  247. package/tempo/tempo.yml +17 -0
@@ -0,0 +1,168 @@
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 { gatewayRunEventBackpressureDisconnectTotal } from "./gatewayRunEventBackpressureDisconnectTotal.js";
96
+ export { eventsEmittedTotal } from "./eventsEmittedTotal.js";
97
+ export { taskHeartbeatsTotal } from "./taskHeartbeatsTotal.js";
98
+ export { taskHeartbeatTimeoutTotal } from "./taskHeartbeatTimeoutTotal.js";
99
+ export { memoryFactReads } from "./memoryFactReads.js";
100
+ export { memoryFactWrites } from "./memoryFactWrites.js";
101
+ export { memoryRecallQueries } from "./memoryRecallQueries.js";
102
+ export { memoryMessageSaves } from "./memoryMessageSaves.js";
103
+ export { openApiToolCallsTotal } from "./openApiToolCallsTotal.js";
104
+ export { openApiToolCallErrorsTotal } from "./openApiToolCallErrorsTotal.js";
105
+ export { scorersStarted } from "./scorersStarted.js";
106
+ export { scorersFinished } from "./scorersFinished.js";
107
+ export { scorersFailed } from "./scorersFailed.js";
108
+ export { snapshotsCaptured } from "./snapshotsCaptured.js";
109
+ export { runForksCreated } from "./runForksCreated.js";
110
+ export { replaysStarted } from "./replaysStarted.js";
111
+ // Gauges
112
+ export { activeRuns } from "./activeRuns.js";
113
+ export { activeNodes } from "./activeNodes.js";
114
+ export { schedulerQueueDepth } from "./schedulerQueueDepth.js";
115
+ export { sandboxActive } from "./sandboxActive.js";
116
+ export { alertsActive } from "./alertsActive.js";
117
+ export { attentionBacklog } from "./attentionBacklog.js";
118
+ export { gatewayConnectionsActive } from "./gatewayConnectionsActive.js";
119
+ export { approvalPending } from "./approvalPending.js";
120
+ export { externalWaitAsyncPending } from "./externalWaitAsyncPending.js";
121
+ export { timersPending } from "./timersPending.js";
122
+ export { schedulerConcurrencyUtilization } from "./schedulerConcurrencyUtilization.js";
123
+ export { processUptimeSeconds } from "./processUptimeSeconds.js";
124
+ export { processMemoryRssBytes } from "./processMemoryRssBytes.js";
125
+ export { processHeapUsedBytes } from "./processHeapUsedBytes.js";
126
+ export { devtoolsActiveSubscribers } from "./devtoolsActiveSubscribers.js";
127
+ // Histograms
128
+ export { nodeDuration } from "./nodeDuration.js";
129
+ export { attemptDuration } from "./attemptDuration.js";
130
+ export { toolDuration } from "./toolDuration.js";
131
+ export { dbQueryDuration } from "./dbQueryDuration.js";
132
+ export { dbTransactionDuration } from "./dbTransactionDuration.js";
133
+ export { httpRequestDuration } from "./httpRequestDuration.js";
134
+ export { hotReloadDuration } from "./hotReloadDuration.js";
135
+ export { vcsDuration } from "./vcsDuration.js";
136
+ export { agentDurationMs } from "./agentDurationMs.js";
137
+ export { tokensInputPerCall } from "./tokensInputPerCall.js";
138
+ export { tokensOutputPerCall } from "./tokensOutputPerCall.js";
139
+ export { tokensContextWindowPerCall } from "./tokensContextWindowPerCall.js";
140
+ export { runDuration } from "./runDuration.js";
141
+ export { promptSizeBytes } from "./promptSizeBytes.js";
142
+ export { responseSizeBytes } from "./responseSizeBytes.js";
143
+ export { approvalWaitDuration } from "./approvalWaitDuration.js";
144
+ export { timerDelayDuration } from "./timerDelayDuration.js";
145
+ export { gatewayRpcDuration } from "./gatewayRpcDuration.js";
146
+ export { schedulerWaitDuration } from "./schedulerWaitDuration.js";
147
+ export { supervisorPollDuration } from "./supervisorPollDuration.js";
148
+ export { supervisorResumeLag } from "./supervisorResumeLag.js";
149
+ export { runsAncestryDepth } from "./runsAncestryDepth.js";
150
+ export { runsCarriedStateBytes } from "./runsCarriedStateBytes.js";
151
+ export { sandboxDurationMs } from "./sandboxDurationMs.js";
152
+ export { sandboxBundleSizeBytes } from "./sandboxBundleSizeBytes.js";
153
+ export { sandboxTransportDurationMs } from "./sandboxTransportDurationMs.js";
154
+ export { sandboxPatchCount } from "./sandboxPatchCount.js";
155
+ export { heartbeatDataSizeBytes } from "./heartbeatDataSizeBytes.js";
156
+ export { heartbeatIntervalMs } from "./heartbeatIntervalMs.js";
157
+ export { memoryRecallDuration } from "./memoryRecallDuration.js";
158
+ export { openApiToolDuration } from "./openApiToolDuration.js";
159
+ export { scorerDuration } from "./scorerDuration.js";
160
+ export { snapshotDuration } from "./snapshotDuration.js";
161
+ export { devtoolsSnapshotBuildMs } from "./devtoolsSnapshotBuildMs.js";
162
+ export { devtoolsDeltaBuildMs } from "./devtoolsDeltaBuildMs.js";
163
+ export { devtoolsEventBytes } from "./devtoolsEventBytes.js";
164
+ export { rewindTotal } from "./rewindTotal.js";
165
+ export { rewindRollbackTotal } from "./rewindRollbackTotal.js";
166
+ export { rewindDurationMs } from "./rewindDurationMs.js";
167
+ export { rewindFramesDeleted } from "./rewindFramesDeleted.js";
168
+ export { rewindSandboxesReverted } from "./rewindSandboxesReverted.js";
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+
3
+ export const memoryFactReads = Metric.counter("smithers.memory.fact_reads");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+
3
+ export const memoryFactWrites = Metric.counter("smithers.memory.fact_writes");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+
3
+ export const memoryMessageSaves = Metric.counter("smithers.memory.message_saves");
@@ -0,0 +1,11 @@
1
+ import { Metric } from "effect";
2
+
3
+ const durationBuckets = Metric.exponentialBoundaries({
4
+ start: 1,
5
+ factor: 2,
6
+ count: 14,
7
+ }); // ~1ms to ~8s
8
+
9
+ export const memoryRecallDuration = Metric.histogram("smithers.memory.recall_duration_ms", {
10
+ boundaries: durationBuckets,
11
+ });
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+
3
+ export const memoryRecallQueries = Metric.counter("smithers.memory.recall_queries");
@@ -0,0 +1,181 @@
1
+ import { renderPrometheusSamples } from "../_corePrometheus.js";
2
+ import { Effect, Metric } from "effect";
3
+ import { toPrometheusMetricName } from "./toPrometheusMetricName.js";
4
+ import { durationBuckets } from "./_buckets.js";
5
+ import { smithersMetricCatalogByName } from "./smithersMetricCatalogByName.js";
6
+ import { smithersMetricCatalogByPrometheusName } from "./smithersMetricCatalogByPrometheusName.js";
7
+ import { trackEvent } from "./trackEvent.js";
8
+ import { updateProcessMetrics } from "./updateProcessMetrics.js";
9
+ import { updateAsyncExternalWaitPending } from "./updateAsyncExternalWaitPending.js";
10
+ import { incrementGauge } from "./_incrementGauge.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 (
23
+ smithersMetricCatalogByName.get(name) ?? smithersMetricCatalogByPrometheusName.get(toPrometheusMetricName(name))
24
+ );
25
+ }
26
+ /**
27
+ * @template A
28
+ * @param {A} metric
29
+ * @param {MetricLabels} [labels]
30
+ * @returns {A}
31
+ */
32
+ function tagMetricWithLabels(metric, labels) {
33
+ let tagged = metric;
34
+ for (const [key, value] of Object.entries(labels ?? {})) {
35
+ tagged = Metric.withAttributes(tagged, { [key]: String(value) });
36
+ }
37
+ return tagged;
38
+ }
39
+ /**
40
+ * @param {string} name
41
+ * @param {MetricLabels} [labels]
42
+ * @returns {Metric.Metric<any, number, any>}
43
+ */
44
+ function counterOrGaugeMetric(name, labels) {
45
+ const definition = resolveMetricDefinition(name);
46
+ const metric =
47
+ definition?.type === "counter" || definition?.type === "gauge" ? definition.metric : 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 =
68
+ definition?.type === "histogram" ? definition.metric : Metric.histogram(name, { boundaries: durationBuckets });
69
+ return tagMetricWithLabels(metric, labels);
70
+ }
71
+ /**
72
+ * @param {number | bigint | undefined} value
73
+ * @returns {number}
74
+ */
75
+ function metricValueAsNumber(value) {
76
+ if (typeof value === "bigint") return Number(value);
77
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
78
+ }
79
+ /**
80
+ * @param {Record<string, string> | undefined} attributes
81
+ * @returns {MetricLabels}
82
+ */
83
+ function metricsServiceLabels(attributes) {
84
+ return Object.freeze(
85
+ Object.fromEntries(Object.entries(attributes ?? {}).sort(([left], [right]) => left.localeCompare(right))),
86
+ );
87
+ }
88
+ /**
89
+ * @param {string} name
90
+ * @param {MetricLabels} labels
91
+ * @returns {string}
92
+ */
93
+ function metricsServiceSnapshotKey(name, labels) {
94
+ return `${name}|${JSON.stringify(Object.entries(labels).sort(([left], [right]) => left.localeCompare(right)))}`;
95
+ }
96
+ /**
97
+ * @returns {PrometheusSample[]}
98
+ */
99
+ function metricsServicePrometheusSamples() {
100
+ const samples = [];
101
+ for (const snapshot of Effect.runSync(Metric.snapshot)) {
102
+ const metricState = snapshot.state;
103
+ const name = snapshot.id;
104
+ if (!name) continue;
105
+ const labels = metricsServiceLabels(snapshot.attributes);
106
+ if (snapshot.type === "Counter") {
107
+ samples.push({
108
+ name,
109
+ type: "counter",
110
+ labels,
111
+ value: metricValueAsNumber(metricState.count),
112
+ });
113
+ continue;
114
+ }
115
+ if (snapshot.type === "Gauge") {
116
+ samples.push({
117
+ name,
118
+ type: "gauge",
119
+ labels,
120
+ value: metricValueAsNumber(metricState.value),
121
+ });
122
+ continue;
123
+ }
124
+ if (snapshot.type === "Histogram") {
125
+ samples.push({
126
+ name,
127
+ type: "histogram",
128
+ labels,
129
+ buckets: new Map([...metricState.buckets].map(([boundary, count]) => [boundary, metricValueAsNumber(count)])),
130
+ sum: metricValueAsNumber(metricState.sum),
131
+ count: metricValueAsNumber(metricState.count),
132
+ });
133
+ }
134
+ }
135
+ return samples;
136
+ }
137
+ /**
138
+ * @returns {MetricsSnapshot}
139
+ */
140
+ function metricsServiceSnapshot() {
141
+ const result = new Map();
142
+ for (const sample of metricsServicePrometheusSamples()) {
143
+ const key = metricsServiceSnapshotKey(sample.name, sample.labels);
144
+ if (sample.type === "histogram") {
145
+ result.set(key, {
146
+ type: "histogram",
147
+ sum: sample.sum ?? 0,
148
+ count: sample.count ?? 0,
149
+ labels: sample.labels,
150
+ buckets: new Map(sample.buckets ?? []),
151
+ });
152
+ continue;
153
+ }
154
+ result.set(key, {
155
+ type: sample.type,
156
+ value: sample.value ?? 0,
157
+ labels: sample.labels,
158
+ });
159
+ }
160
+ return result;
161
+ }
162
+ /** @type {MetricsServiceShape} */
163
+ export const metricsServiceAdapter = {
164
+ increment: (name, labels) => {
165
+ const metric = counterOrGaugeMetric(name, labels);
166
+ return resolveMetricDefinition(name)?.type === "gauge" ? incrementGauge(metric, 1) : Metric.update(metric, 1);
167
+ },
168
+ incrementBy: (name, value, labels) => {
169
+ const metric = counterOrGaugeMetric(name, labels);
170
+ return resolveMetricDefinition(name)?.type === "gauge"
171
+ ? incrementGauge(metric, value)
172
+ : Metric.update(metric, value);
173
+ },
174
+ gauge: (name, value, labels) => Metric.update(gaugeMetric(name, labels), value),
175
+ histogram: (name, value, labels) => Metric.update(histogramMetric(name, labels), value),
176
+ recordEvent: (event) => trackEvent(event),
177
+ updateProcessMetrics: () => updateProcessMetrics(),
178
+ updateAsyncExternalWaitPending: (kind, delta) => updateAsyncExternalWaitPending(kind, delta),
179
+ renderPrometheus: () => Effect.sync(() => renderPrometheusSamples(metricsServicePrometheusSamples())),
180
+ snapshot: () => Effect.sync(metricsServiceSnapshot),
181
+ };
@@ -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", { boundaries: 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,3 @@
1
+ import { Metric } from "effect";
2
+
3
+ export const openApiToolCallErrorsTotal = Metric.counter("smithers.openapi.tool_call_errors");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+
3
+ export const openApiToolCallsTotal = Metric.counter("smithers.openapi.tool_calls");
@@ -0,0 +1,9 @@
1
+ import { Metric } from "effect";
2
+
3
+ const toolBuckets = Metric.exponentialBoundaries({
4
+ start: 10,
5
+ factor: 2,
6
+ count: 14,
7
+ }); // ~10ms to ~80s
8
+
9
+ export const openApiToolDuration = Metric.histogram("smithers.openapi.tool_duration_ms", { boundaries: toolBuckets });
@@ -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", { boundaries: sizeBuckets });
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+
3
+ export const replaysStarted = Metric.counter("smithers.replays.started");
@@ -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", { boundaries: 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", { boundaries: durationBuckets });
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ const buckets = Metric.exponentialBoundaries({ start: 1, factor: 2, count: 18 });
3
+ export const rewindFramesDeleted = Metric.histogram("smithers_rewind_frames_deleted", { boundaries: 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 { Metric } from "effect";
2
+ const buckets = Metric.boundariesFromIterable([0, 1, 2, 4, 8, 16, 32, 64]);
3
+ export const rewindSandboxesReverted = Metric.histogram("smithers_rewind_sandboxes_reverted", { boundaries: 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", { boundaries: durationBuckets });
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+
3
+ export const runForksCreated = Metric.counter("smithers.forks.created");
@@ -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", { boundaries: ancestryDepthBuckets });
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const runsCancelledTotal = Metric.counter("smithers.runs.cancelled_total");
@@ -0,0 +1,5 @@
1
+ import { Metric } from "effect";
2
+ import { carriedStateSizeBuckets } from "./_buckets.js";
3
+ export const runsCarriedStateBytes = Metric.histogram("smithers.runs.carried_state_bytes", {
4
+ boundaries: carriedStateSizeBuckets,
5
+ });
@@ -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,5 @@
1
+ import { Metric } from "effect";
2
+ import { sizeBuckets } from "./_buckets.js";
3
+ export const sandboxBundleSizeBytes = Metric.histogram("smithers.sandbox.bundle_size_bytes", {
4
+ boundaries: sizeBuckets,
5
+ });
@@ -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", { boundaries: 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", { boundaries: tokenBuckets });
@@ -0,0 +1,5 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const sandboxTransportDurationMs = Metric.histogram("smithers.sandbox.transport_duration_ms", {
4
+ boundaries: durationBuckets,
5
+ });
@@ -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,5 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const schedulerWaitDuration = Metric.histogram("smithers.scheduler.wait_duration_ms", {
4
+ boundaries: durationBuckets,
5
+ });
@@ -0,0 +1,9 @@
1
+ import { Metric } from "effect";
2
+
3
+ const scorerBuckets = Metric.exponentialBoundaries({
4
+ start: 10,
5
+ factor: 2,
6
+ count: 14,
7
+ }); // ~10ms to ~80s
8
+
9
+ export const scorerDuration = Metric.histogram("smithers.scorer.duration_ms", { boundaries: scorerBuckets });
@@ -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");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+
3
+ export const scorersFailed = Metric.counter("smithers.scorers.failed");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+
3
+ export const scorersFinished = Metric.counter("smithers.scorers.finished");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+
3
+ export const scorersStarted = Metric.counter("smithers.scorers.started");