@smthrs/observability 0.35.0 → 1.0.0-rc.12

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 (363) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/LICENSE +1 -1
  3. package/README.md +87 -0
  4. package/dist/cjs/BrowserOtel.d.ts +37 -0
  5. package/dist/cjs/BrowserOtel.d.ts.map +1 -0
  6. package/dist/cjs/BrowserOtel.js +47 -0
  7. package/dist/cjs/BrowserOtel.js.map +7 -0
  8. package/dist/cjs/Endpoint.d.ts +70 -0
  9. package/dist/cjs/Endpoint.d.ts.map +1 -0
  10. package/dist/cjs/Endpoint.js +85 -0
  11. package/dist/cjs/Endpoint.js.map +7 -0
  12. package/dist/cjs/JournalLogger.d.ts +232 -0
  13. package/dist/cjs/JournalLogger.d.ts.map +1 -0
  14. package/dist/cjs/JournalLogger.js +415 -0
  15. package/dist/cjs/JournalLogger.js.map +7 -0
  16. package/dist/cjs/Logger.d.ts +56 -0
  17. package/dist/cjs/Logger.d.ts.map +1 -0
  18. package/dist/cjs/Logger.js +72 -0
  19. package/dist/cjs/Logger.js.map +7 -0
  20. package/dist/cjs/Metric.d.ts +67 -0
  21. package/dist/cjs/Metric.d.ts.map +1 -0
  22. package/dist/cjs/Metric.js +68 -0
  23. package/dist/cjs/Metric.js.map +7 -0
  24. package/dist/cjs/NodeOtel.d.ts +42 -0
  25. package/dist/cjs/NodeOtel.d.ts.map +1 -0
  26. package/dist/cjs/NodeOtel.js +78 -0
  27. package/dist/cjs/NodeOtel.js.map +7 -0
  28. package/dist/cjs/Otel.d.ts +63 -0
  29. package/dist/cjs/Otel.d.ts.map +1 -0
  30. package/dist/cjs/Otel.js +75 -0
  31. package/dist/cjs/Otel.js.map +7 -0
  32. package/dist/cjs/Otlp.d.ts +203 -0
  33. package/dist/cjs/Otlp.d.ts.map +1 -0
  34. package/dist/cjs/Otlp.js +251 -0
  35. package/dist/cjs/Otlp.js.map +7 -0
  36. package/dist/cjs/Resource.d.ts +163 -0
  37. package/dist/cjs/Resource.d.ts.map +1 -0
  38. package/dist/cjs/Resource.js +186 -0
  39. package/dist/cjs/Resource.js.map +7 -0
  40. package/dist/cjs/index.d.ts +61 -0
  41. package/dist/cjs/index.d.ts.map +1 -0
  42. package/dist/cjs/index.js +47 -0
  43. package/dist/cjs/index.js.map +7 -0
  44. package/dist/cjs/internal/schemaIssuePath.d.ts +31 -0
  45. package/dist/cjs/internal/schemaIssuePath.d.ts.map +1 -0
  46. package/dist/cjs/internal/schemaIssuePath.js +49 -0
  47. package/dist/cjs/internal/schemaIssuePath.js.map +7 -0
  48. package/dist/cjs/package.json +1 -0
  49. package/dist/esm/BrowserOtel.d.ts +37 -0
  50. package/dist/esm/BrowserOtel.d.ts.map +1 -0
  51. package/dist/esm/BrowserOtel.js +24 -0
  52. package/dist/esm/BrowserOtel.js.map +1 -0
  53. package/dist/esm/Endpoint.d.ts +70 -0
  54. package/dist/esm/Endpoint.d.ts.map +1 -0
  55. package/dist/esm/Endpoint.js +110 -0
  56. package/dist/esm/Endpoint.js.map +1 -0
  57. package/dist/esm/JournalLogger.d.ts +232 -0
  58. package/dist/esm/JournalLogger.d.ts.map +1 -0
  59. package/dist/esm/JournalLogger.js +520 -0
  60. package/dist/esm/JournalLogger.js.map +1 -0
  61. package/dist/esm/Logger.d.ts +56 -0
  62. package/dist/esm/Logger.d.ts.map +1 -0
  63. package/dist/esm/Logger.js +61 -0
  64. package/dist/esm/Logger.js.map +1 -0
  65. package/dist/esm/Metric.d.ts +67 -0
  66. package/dist/esm/Metric.d.ts.map +1 -0
  67. package/dist/esm/Metric.js +80 -0
  68. package/dist/esm/Metric.js.map +1 -0
  69. package/dist/esm/NodeOtel.d.ts +42 -0
  70. package/dist/esm/NodeOtel.d.ts.map +1 -0
  71. package/dist/esm/NodeOtel.js +56 -0
  72. package/dist/esm/NodeOtel.js.map +1 -0
  73. package/dist/esm/Otel.d.ts +63 -0
  74. package/dist/esm/Otel.d.ts.map +1 -0
  75. package/dist/esm/Otel.js +52 -0
  76. package/dist/esm/Otel.js.map +1 -0
  77. package/dist/esm/Otlp.d.ts +203 -0
  78. package/dist/esm/Otlp.d.ts.map +1 -0
  79. package/dist/esm/Otlp.js +384 -0
  80. package/dist/esm/Otlp.js.map +1 -0
  81. package/dist/esm/Resource.d.ts +163 -0
  82. package/dist/esm/Resource.d.ts.map +1 -0
  83. package/dist/esm/Resource.js +238 -0
  84. package/dist/esm/Resource.js.map +1 -0
  85. package/dist/esm/index.d.ts +61 -0
  86. package/dist/esm/index.d.ts.map +1 -0
  87. package/dist/esm/index.js +61 -0
  88. package/dist/esm/index.js.map +1 -0
  89. package/dist/esm/internal/schemaIssuePath.d.ts +31 -0
  90. package/dist/esm/internal/schemaIssuePath.d.ts.map +1 -0
  91. package/dist/esm/internal/schemaIssuePath.js +59 -0
  92. package/dist/esm/internal/schemaIssuePath.js.map +1 -0
  93. package/docs/README.md +164 -0
  94. package/docs/api.md +780 -0
  95. package/docs/concepts/instrumentation-and-export.md +98 -0
  96. package/docs/concepts/layer-map.md +73 -0
  97. package/docs/concepts/validated-acquisition.md +106 -0
  98. package/docs/guides/export-to-a-collector.md +190 -0
  99. package/docs/guides/forward-logs-to-the-journal.md +226 -0
  100. package/docs/guides/install-a-logger.md +111 -0
  101. package/docs/guides/read-runtime-metrics.md +83 -0
  102. package/docs/guides/testing.md +134 -0
  103. package/docs/guides/wire-an-opentelemetry-sdk.md +226 -0
  104. package/docs/installation.md +102 -0
  105. package/docs/quickstart.md +145 -0
  106. package/docs/troubleshooting.md +168 -0
  107. package/package.json +221 -32
  108. package/src/BrowserOtel.ts +51 -0
  109. package/src/Endpoint.ts +131 -0
  110. package/src/JournalLogger.ts +635 -0
  111. package/src/Logger.ts +107 -0
  112. package/src/Metric.ts +88 -0
  113. package/src/NodeOtel.ts +90 -0
  114. package/src/Otel.ts +118 -0
  115. package/src/Otlp.ts +514 -0
  116. package/src/Resource.ts +325 -0
  117. package/src/index.ts +67 -0
  118. package/src/internal/schemaIssuePath.ts +65 -0
  119. package/docker-compose.otel.yml +0 -104
  120. package/grafana/dashboards/smithers-dashboard.json +0 -453
  121. package/grafana/provisioning/dashboards/dashboards.yml +0 -12
  122. package/grafana/provisioning/datasources/datasources.yml +0 -49
  123. package/loki/loki-config.yaml +0 -35
  124. package/otel-collector-config.yml +0 -38
  125. package/prometheus/prometheus.yml +0 -8
  126. package/src/MetricName.ts +0 -1
  127. package/src/MetricsServiceLive.js +0 -9
  128. package/src/README.md +0 -28
  129. package/src/ResolvedSmithersObservabilityOptions.ts +0 -12
  130. package/src/SmithersEvent.ts +0 -843
  131. package/src/SmithersLogFormat.ts +0 -1
  132. package/src/SmithersMetricDefinition.ts +0 -15
  133. package/src/SmithersMetricType.ts +0 -1
  134. package/src/SmithersMetricUnit.ts +0 -1
  135. package/src/SmithersObservability.js +0 -15
  136. package/src/SmithersObservabilityOptions.ts +0 -12
  137. package/src/SmithersObservabilityService.ts +0 -13
  138. package/src/_coreCorrelation/CorrelationContext.ts +0 -10
  139. package/src/_coreCorrelation/CorrelationContextLive.js +0 -11
  140. package/src/_coreCorrelation/CorrelationContextService.js +0 -15
  141. package/src/_coreCorrelation/CorrelationContextServiceShape.ts +0 -12
  142. package/src/_coreCorrelation/CorrelationPatch.ts +0 -3
  143. package/src/_coreCorrelation/README.md +0 -20
  144. package/src/_coreCorrelation/_correlationStorage.js +0 -4
  145. package/src/_coreCorrelation/correlationContextFiberRef.js +0 -5
  146. package/src/_coreCorrelation/correlationContextToLogAnnotations.js +0 -18
  147. package/src/_coreCorrelation/getCurrentCorrelationContext.js +0 -9
  148. package/src/_coreCorrelation/getCurrentCorrelationContextEffect.js +0 -11
  149. package/src/_coreCorrelation/index.js +0 -14
  150. package/src/_coreCorrelation/mergeCorrelationContext.js +0 -51
  151. package/src/_coreCorrelation/runWithCorrelationContext.js +0 -14
  152. package/src/_coreCorrelation/updateCurrentCorrelationContext.js +0 -17
  153. package/src/_coreCorrelation/withCorrelationContext.js +0 -38
  154. package/src/_coreCorrelation/withCurrentCorrelationContext.js +0 -11
  155. package/src/_coreMetrics.js +0 -14
  156. package/src/_coreMetricsShape.ts +0 -44
  157. package/src/_corePrometheus.js +0 -91
  158. package/src/_corePrometheusShape.ts +0 -11
  159. package/src/_coreTracing.js +0 -132
  160. package/src/_coreTracingShape.ts +0 -17
  161. package/src/_otelLogBuilders.js +0 -102
  162. package/src/_sessionFileResolvers.js +0 -164
  163. package/src/_smithersSpanAttributeAliases.js +0 -19
  164. package/src/_smithersTraceSpanStorage.js +0 -3
  165. package/src/_traceEventNormalizers.js +0 -499
  166. package/src/_traceRedaction.js +0 -162
  167. package/src/agentSessionEventToOtelLogRecord.js +0 -55
  168. package/src/agentTrace.ts +0 -144
  169. package/src/agentTraceCapabilities.js +0 -151
  170. package/src/annotateSmithersTrace.js +0 -11
  171. package/src/canonicalTraceEventToOtelLogRecord.js +0 -55
  172. package/src/correlation.js +0 -56
  173. package/src/createSmithersObservabilityLayer.js +0 -59
  174. package/src/createSmithersOtelLayer.js +0 -23
  175. package/src/createSmithersRuntimeLayer.js +0 -2
  176. package/src/detectAgentFamily.js +0 -26
  177. package/src/detectCaptureMode.js +0 -29
  178. package/src/emitOtelLogRecord.js +0 -19
  179. package/src/getCurrentSmithersTraceAnnotations.js +0 -14
  180. package/src/getCurrentSmithersTraceSpan.js +0 -7
  181. package/src/index.d.ts +0 -1392
  182. package/src/index.js +0 -137
  183. package/src/kindPhase.js +0 -17
  184. package/src/logging.js +0 -264
  185. package/src/makeSmithersSpanAttributes.js +0 -20
  186. package/src/metrics/README.md +0 -22
  187. package/src/metrics/SmithersMetricDefinition.ts +0 -17
  188. package/src/metrics/SmithersMetricType.ts +0 -1
  189. package/src/metrics/SmithersMetricUnit.ts +0 -1
  190. package/src/metrics/_asyncExternalWaitCounts.js +0 -4
  191. package/src/metrics/_buckets.js +0 -37
  192. package/src/metrics/_incrementGauge.js +0 -11
  193. package/src/metrics/_processStartMs.js +0 -1
  194. package/src/metrics/activeNodes.js +0 -2
  195. package/src/metrics/activeRuns.js +0 -2
  196. package/src/metrics/agentActionsTotal.js +0 -2
  197. package/src/metrics/agentDurationMs.js +0 -3
  198. package/src/metrics/agentErrorsTotal.js +0 -2
  199. package/src/metrics/agentEventsTotal.js +0 -2
  200. package/src/metrics/agentInvocationsTotal.js +0 -2
  201. package/src/metrics/agentRetriesTotal.js +0 -2
  202. package/src/metrics/agentSessionsTotal.js +0 -2
  203. package/src/metrics/agentTokensTotal.js +0 -2
  204. package/src/metrics/alertDeliveriesAttempted.js +0 -2
  205. package/src/metrics/alertDeliveriesSuppressed.js +0 -2
  206. package/src/metrics/alertsAcknowledgedTotal.js +0 -2
  207. package/src/metrics/alertsActive.js +0 -2
  208. package/src/metrics/alertsEscalatedTotal.js +0 -2
  209. package/src/metrics/alertsFiredTotal.js +0 -2
  210. package/src/metrics/alertsReopenedTotal.js +0 -2
  211. package/src/metrics/alertsResolvedTotal.js +0 -2
  212. package/src/metrics/alertsSilencedTotal.js +0 -2
  213. package/src/metrics/approvalPending.js +0 -2
  214. package/src/metrics/approvalWaitDuration.js +0 -5
  215. package/src/metrics/approvalsDenied.js +0 -2
  216. package/src/metrics/approvalsGranted.js +0 -2
  217. package/src/metrics/approvalsRequested.js +0 -2
  218. package/src/metrics/attemptDuration.js +0 -3
  219. package/src/metrics/attentionBacklog.js +0 -2
  220. package/src/metrics/cacheHits.js +0 -2
  221. package/src/metrics/cacheMisses.js +0 -2
  222. package/src/metrics/dbQueryDuration.js +0 -3
  223. package/src/metrics/dbRetries.js +0 -2
  224. package/src/metrics/dbTransactionDuration.js +0 -3
  225. package/src/metrics/dbTransactionRetries.js +0 -2
  226. package/src/metrics/dbTransactionRollbacks.js +0 -2
  227. package/src/metrics/devtoolsActiveSubscribers.js +0 -2
  228. package/src/metrics/devtoolsBackpressureDisconnectTotal.js +0 -2
  229. package/src/metrics/devtoolsDeltaBuildMs.js +0 -3
  230. package/src/metrics/devtoolsEventBytes.js +0 -3
  231. package/src/metrics/devtoolsEventTotal.js +0 -2
  232. package/src/metrics/devtoolsSnapshotBuildMs.js +0 -5
  233. package/src/metrics/devtoolsSubscribeTotal.js +0 -2
  234. package/src/metrics/errorsTotal.js +0 -2
  235. package/src/metrics/eventsEmittedTotal.js +0 -2
  236. package/src/metrics/externalWaitAsyncPending.js +0 -2
  237. package/src/metrics/gatewayApprovalDecisionsTotal.js +0 -2
  238. package/src/metrics/gatewayAuthEventsTotal.js +0 -2
  239. package/src/metrics/gatewayConnectionsActive.js +0 -2
  240. package/src/metrics/gatewayConnectionsClosedTotal.js +0 -2
  241. package/src/metrics/gatewayConnectionsTotal.js +0 -2
  242. package/src/metrics/gatewayCronTriggersTotal.js +0 -2
  243. package/src/metrics/gatewayErrorsTotal.js +0 -2
  244. package/src/metrics/gatewayHeartbeatTicksTotal.js +0 -2
  245. package/src/metrics/gatewayMessagesReceivedTotal.js +0 -2
  246. package/src/metrics/gatewayMessagesSentTotal.js +0 -2
  247. package/src/metrics/gatewayRpcCallsTotal.js +0 -2
  248. package/src/metrics/gatewayRpcDuration.js +0 -3
  249. package/src/metrics/gatewayRunEventBackpressureDisconnectTotal.js +0 -4
  250. package/src/metrics/gatewayRunsCompletedTotal.js +0 -2
  251. package/src/metrics/gatewayRunsStartedTotal.js +0 -2
  252. package/src/metrics/gatewaySignalsTotal.js +0 -2
  253. package/src/metrics/gatewayWebhooksReceivedTotal.js +0 -2
  254. package/src/metrics/gatewayWebhooksRejectedTotal.js +0 -2
  255. package/src/metrics/gatewayWebhooksVerifiedTotal.js +0 -2
  256. package/src/metrics/heartbeatDataSizeBytes.js +0 -5
  257. package/src/metrics/heartbeatIntervalMs.js +0 -3
  258. package/src/metrics/hotReloadDuration.js +0 -3
  259. package/src/metrics/hotReloadFailures.js +0 -2
  260. package/src/metrics/hotReloads.js +0 -2
  261. package/src/metrics/httpRequestDuration.js +0 -3
  262. package/src/metrics/httpRequests.js +0 -2
  263. package/src/metrics/index.d.ts +0 -1222
  264. package/src/metrics/index.js +0 -168
  265. package/src/metrics/memoryFactReads.js +0 -3
  266. package/src/metrics/memoryFactWrites.js +0 -3
  267. package/src/metrics/memoryMessageSaves.js +0 -3
  268. package/src/metrics/memoryRecallDuration.js +0 -11
  269. package/src/metrics/memoryRecallQueries.js +0 -3
  270. package/src/metrics/metricsServiceAdapter.js +0 -181
  271. package/src/metrics/nodeDuration.js +0 -3
  272. package/src/metrics/nodeRetriesTotal.js +0 -2
  273. package/src/metrics/nodesFailed.js +0 -2
  274. package/src/metrics/nodesFinished.js +0 -2
  275. package/src/metrics/nodesStarted.js +0 -2
  276. package/src/metrics/openApiToolCallErrorsTotal.js +0 -3
  277. package/src/metrics/openApiToolCallsTotal.js +0 -3
  278. package/src/metrics/openApiToolDuration.js +0 -9
  279. package/src/metrics/processHeapUsedBytes.js +0 -2
  280. package/src/metrics/processMemoryRssBytes.js +0 -2
  281. package/src/metrics/processUptimeSeconds.js +0 -2
  282. package/src/metrics/promptSizeBytes.js +0 -3
  283. package/src/metrics/replaysStarted.js +0 -3
  284. package/src/metrics/responseSizeBytes.js +0 -3
  285. package/src/metrics/rewindDurationMs.js +0 -3
  286. package/src/metrics/rewindFramesDeleted.js +0 -3
  287. package/src/metrics/rewindRollbackTotal.js +0 -2
  288. package/src/metrics/rewindSandboxesReverted.js +0 -3
  289. package/src/metrics/rewindTotal.js +0 -2
  290. package/src/metrics/runDuration.js +0 -3
  291. package/src/metrics/runForksCreated.js +0 -3
  292. package/src/metrics/runsAncestryDepth.js +0 -3
  293. package/src/metrics/runsCancelledTotal.js +0 -2
  294. package/src/metrics/runsCarriedStateBytes.js +0 -5
  295. package/src/metrics/runsContinuedTotal.js +0 -2
  296. package/src/metrics/runsFailedTotal.js +0 -2
  297. package/src/metrics/runsFinishedTotal.js +0 -2
  298. package/src/metrics/runsResumedTotal.js +0 -2
  299. package/src/metrics/runsTotal.js +0 -2
  300. package/src/metrics/sandboxActive.js +0 -2
  301. package/src/metrics/sandboxBundleSizeBytes.js +0 -5
  302. package/src/metrics/sandboxCompletedTotal.js +0 -2
  303. package/src/metrics/sandboxCreatedTotal.js +0 -2
  304. package/src/metrics/sandboxDurationMs.js +0 -3
  305. package/src/metrics/sandboxPatchCount.js +0 -3
  306. package/src/metrics/sandboxTransportDurationMs.js +0 -5
  307. package/src/metrics/schedulerConcurrencyUtilization.js +0 -2
  308. package/src/metrics/schedulerQueueDepth.js +0 -2
  309. package/src/metrics/schedulerWaitDuration.js +0 -5
  310. package/src/metrics/scorerDuration.js +0 -9
  311. package/src/metrics/scorerEventsFailed.js +0 -2
  312. package/src/metrics/scorerEventsFinished.js +0 -2
  313. package/src/metrics/scorerEventsStarted.js +0 -2
  314. package/src/metrics/scorersFailed.js +0 -3
  315. package/src/metrics/scorersFinished.js +0 -3
  316. package/src/metrics/scorersStarted.js +0 -3
  317. package/src/metrics/smithersMetricCatalog.js +0 -893
  318. package/src/metrics/smithersMetricCatalogByKey.js +0 -2
  319. package/src/metrics/smithersMetricCatalogByName.js +0 -2
  320. package/src/metrics/smithersMetricCatalogByPrometheusName.js +0 -4
  321. package/src/metrics/snapshotDuration.js +0 -9
  322. package/src/metrics/snapshotsCaptured.js +0 -3
  323. package/src/metrics/supervisorPollDuration.js +0 -5
  324. package/src/metrics/supervisorPollsTotal.js +0 -2
  325. package/src/metrics/supervisorResumeLag.js +0 -5
  326. package/src/metrics/supervisorResumedTotal.js +0 -2
  327. package/src/metrics/supervisorSkippedTotal.js +0 -2
  328. package/src/metrics/supervisorStaleDetected.js +0 -2
  329. package/src/metrics/taskHeartbeatTimeoutTotal.js +0 -2
  330. package/src/metrics/taskHeartbeatsTotal.js +0 -2
  331. package/src/metrics/timerDelayDuration.js +0 -3
  332. package/src/metrics/timersCancelled.js +0 -2
  333. package/src/metrics/timersCreated.js +0 -2
  334. package/src/metrics/timersFired.js +0 -2
  335. package/src/metrics/timersPending.js +0 -2
  336. package/src/metrics/toPrometheusMetricName.js +0 -8
  337. package/src/metrics/tokensCacheReadTotal.js +0 -2
  338. package/src/metrics/tokensCacheWriteTotal.js +0 -2
  339. package/src/metrics/tokensContextWindowBucketTotal.js +0 -2
  340. package/src/metrics/tokensContextWindowPerCall.js +0 -5
  341. package/src/metrics/tokensInputPerCall.js +0 -3
  342. package/src/metrics/tokensInputTotal.js +0 -2
  343. package/src/metrics/tokensOutputPerCall.js +0 -3
  344. package/src/metrics/tokensOutputTotal.js +0 -2
  345. package/src/metrics/tokensReasoningTotal.js +0 -2
  346. package/src/metrics/toolCallErrorsTotal.js +0 -2
  347. package/src/metrics/toolCallsTotal.js +0 -2
  348. package/src/metrics/toolDuration.js +0 -3
  349. package/src/metrics/toolOutputTruncatedTotal.js +0 -2
  350. package/src/metrics/trackEvent.js +0 -608
  351. package/src/metrics/updateAsyncExternalWaitPending.js +0 -18
  352. package/src/metrics/updateProcessMetrics.js +0 -20
  353. package/src/metrics/vcsDuration.js +0 -3
  354. package/src/normalizeStructuredEvent.js +0 -15
  355. package/src/prometheusContentType.js +0 -1
  356. package/src/renderPrometheusMetrics.js +0 -212
  357. package/src/resolveAgentTraceCapabilities.js +0 -59
  358. package/src/resolveSmithersObservabilityOptions.js +0 -109
  359. package/src/smithersMetrics.js +0 -2
  360. package/src/smithersSpanNames.js +0 -6
  361. package/src/unsupportedKindsForCapabilities.js +0 -32
  362. package/src/withSmithersSpan.js +0 -17
  363. package/tempo/tempo.yml +0 -17
@@ -1,608 +0,0 @@
1
- import { Effect, Metric } from "effect";
2
- import { incrementGauge } from "./_incrementGauge.js";
3
- import { memoryFactWrites } from "./memoryFactWrites.js";
4
- import { memoryRecallQueries } from "./memoryRecallQueries.js";
5
- import { memoryMessageSaves } from "./memoryMessageSaves.js";
6
- import { openApiToolCallsTotal } from "./openApiToolCallsTotal.js";
7
- import { openApiToolCallErrorsTotal } from "./openApiToolCallErrorsTotal.js";
8
- import { openApiToolDuration } from "./openApiToolDuration.js";
9
- import { runsTotal } from "./runsTotal.js";
10
- import { nodesStarted } from "./nodesStarted.js";
11
- import { nodesFinished } from "./nodesFinished.js";
12
- import { nodesFailed } from "./nodesFailed.js";
13
- import { toolCallsTotal } from "./toolCallsTotal.js";
14
- import { toolCallErrorsTotal } from "./toolCallErrorsTotal.js";
15
- import { errorsTotal } from "./errorsTotal.js";
16
- import { nodeRetriesTotal } from "./nodeRetriesTotal.js";
17
- import { eventsEmittedTotal } from "./eventsEmittedTotal.js";
18
- import { activeRuns } from "./activeRuns.js";
19
- import { activeNodes } from "./activeNodes.js";
20
- import { runsFinishedTotal } from "./runsFinishedTotal.js";
21
- import { runsFailedTotal } from "./runsFailedTotal.js";
22
- import { runsCancelledTotal } from "./runsCancelledTotal.js";
23
- import { runsContinuedTotal } from "./runsContinuedTotal.js";
24
- import { runsAncestryDepth } from "./runsAncestryDepth.js";
25
- import { runsCarriedStateBytes } from "./runsCarriedStateBytes.js";
26
- import { approvalsRequested } from "./approvalsRequested.js";
27
- import { approvalsGranted } from "./approvalsGranted.js";
28
- import { approvalsDenied } from "./approvalsDenied.js";
29
- import { approvalPending } from "./approvalPending.js";
30
- import { timersCreated } from "./timersCreated.js";
31
- import { timersFired } from "./timersFired.js";
32
- import { timersCancelled } from "./timersCancelled.js";
33
- import { timersPending } from "./timersPending.js";
34
- import { timerDelayDuration } from "./timerDelayDuration.js";
35
- import { tokensInputTotal } from "./tokensInputTotal.js";
36
- import { tokensOutputTotal } from "./tokensOutputTotal.js";
37
- import { tokensCacheReadTotal } from "./tokensCacheReadTotal.js";
38
- import { tokensCacheWriteTotal } from "./tokensCacheWriteTotal.js";
39
- import { tokensReasoningTotal } from "./tokensReasoningTotal.js";
40
- import { tokensContextWindowBucketTotal } from "./tokensContextWindowBucketTotal.js";
41
- import { tokensInputPerCall } from "./tokensInputPerCall.js";
42
- import { tokensOutputPerCall } from "./tokensOutputPerCall.js";
43
- import { tokensContextWindowPerCall } from "./tokensContextWindowPerCall.js";
44
- import { scorerEventsStarted } from "./scorerEventsStarted.js";
45
- import { scorerEventsFinished } from "./scorerEventsFinished.js";
46
- import { scorerEventsFailed } from "./scorerEventsFailed.js";
47
- import { supervisorPollsTotal } from "./supervisorPollsTotal.js";
48
- import { supervisorStaleDetected } from "./supervisorStaleDetected.js";
49
- import { supervisorResumedTotal } from "./supervisorResumedTotal.js";
50
- import { supervisorSkippedTotal } from "./supervisorSkippedTotal.js";
51
- import { supervisorPollDuration } from "./supervisorPollDuration.js";
52
- import { supervisorResumeLag } from "./supervisorResumeLag.js";
53
- import { sandboxCreatedTotal } from "./sandboxCreatedTotal.js";
54
- import { sandboxCompletedTotal } from "./sandboxCompletedTotal.js";
55
- import { sandboxActive } from "./sandboxActive.js";
56
- import { sandboxBundleSizeBytes } from "./sandboxBundleSizeBytes.js";
57
- import { sandboxDurationMs } from "./sandboxDurationMs.js";
58
- import { sandboxPatchCount } from "./sandboxPatchCount.js";
59
- import { taskHeartbeatsTotal } from "./taskHeartbeatsTotal.js";
60
- import { taskHeartbeatTimeoutTotal } from "./taskHeartbeatTimeoutTotal.js";
61
- import { heartbeatDataSizeBytes } from "./heartbeatDataSizeBytes.js";
62
- import { heartbeatIntervalMs } from "./heartbeatIntervalMs.js";
63
- import { agentEventsTotal } from "./agentEventsTotal.js";
64
- import { agentSessionsTotal } from "./agentSessionsTotal.js";
65
- import { agentActionsTotal } from "./agentActionsTotal.js";
66
- import { agentErrorsTotal } from "./agentErrorsTotal.js";
67
- import { agentRetriesTotal } from "./agentRetriesTotal.js";
68
- import { agentTokensTotal } from "./agentTokensTotal.js";
69
- /** @typedef {import("@smthrs/observability/SmithersEvent").SmithersEvent} SmithersEvent */
70
- /** @typedef {Extract<SmithersEvent, { type: "AgentEvent" }>["event"]} AgentEventPayload */
71
- /** @typedef {{ inputTokens?: number; outputTokens?: number; cacheReadTokens?: number; cacheWriteTokens?: number; reasoningTokens?: number; totalTokens?: number }} AgentUsageTotals */
72
-
73
- /**
74
- * @param {unknown} value
75
- * @returns {string | undefined}
76
- */
77
- function normalizeMetricTag(value) {
78
- if (typeof value !== "string") return undefined;
79
- const trimmed = value.trim();
80
- return trimmed.length > 0 ? trimmed : undefined;
81
- }
82
- /**
83
- * @template A
84
- * @param {A} metric
85
- * @param {Record<string, string | undefined>} tags
86
- * @returns {A}
87
- */
88
- function tagMetricWithTags(metric, tags) {
89
- let tagged = metric;
90
- for (const [key, value] of Object.entries(tags)) {
91
- if (!value) continue;
92
- tagged = Metric.withAttributes(tagged, { [key]: String(value) });
93
- }
94
- return tagged;
95
- }
96
- /**
97
- * @param {unknown} value
98
- * @returns {number | undefined}
99
- */
100
- function asFiniteMetricCount(value) {
101
- return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
102
- }
103
- /**
104
- * @param {Extract<SmithersEvent, { type: "TokenUsageReported" }>} event
105
- * @returns {number | undefined}
106
- */
107
- function resolveContextWindowTokens(event) {
108
- const contextWindowTokens =
109
- (asFiniteMetricCount(event.inputTokens) ?? 0) +
110
- (asFiniteMetricCount(event.cacheReadTokens) ?? 0) +
111
- (asFiniteMetricCount(event.cacheWriteTokens) ?? 0);
112
- return contextWindowTokens > 0 ? contextWindowTokens : undefined;
113
- }
114
- /**
115
- * @param {number} tokens
116
- * @returns {string}
117
- */
118
- function classifyContextWindowBucket(tokens) {
119
- if (tokens < 50_000) return "lt_50k";
120
- if (tokens < 100_000) return "gte_50k_lt_100k";
121
- if (tokens < 200_000) return "gte_100k_lt_200k";
122
- if (tokens < 500_000) return "gte_200k_lt_500k";
123
- if (tokens < 1_000_000) return "gte_500k_lt_1m";
124
- return "gte_1m";
125
- }
126
- /**
127
- * @param {Record<string, unknown> | undefined} usage
128
- * @returns {AgentUsageTotals}
129
- */
130
- function extractAgentUsageTotals(usage) {
131
- if (!usage) return {};
132
- const value = usage;
133
- const inputTokens =
134
- asFiniteMetricCount(value.inputTokens) ??
135
- asFiniteMetricCount(value.input_tokens) ??
136
- asFiniteMetricCount(value.prompt_tokens);
137
- const outputTokens =
138
- asFiniteMetricCount(value.outputTokens) ??
139
- asFiniteMetricCount(value.output_tokens) ??
140
- asFiniteMetricCount(value.completion_tokens);
141
- const cacheReadTokens =
142
- asFiniteMetricCount(value.cacheReadTokens) ??
143
- asFiniteMetricCount(value.cache_read_input_tokens) ??
144
- asFiniteMetricCount(value.cached_input_tokens) ??
145
- asFiniteMetricCount(value.inputTokenDetails?.cacheReadTokens);
146
- const cacheWriteTokens =
147
- asFiniteMetricCount(value.cacheWriteTokens) ??
148
- asFiniteMetricCount(value.cache_creation_input_tokens) ??
149
- asFiniteMetricCount(value.inputTokenDetails?.cacheWriteTokens);
150
- const reasoningTokens =
151
- asFiniteMetricCount(value.reasoningTokens) ??
152
- asFiniteMetricCount(value.reasoning_tokens) ??
153
- asFiniteMetricCount(value.outputTokenDetails?.reasoningTokens);
154
- const totalTokens =
155
- asFiniteMetricCount(value.totalTokens) ??
156
- asFiniteMetricCount(
157
- (inputTokens ?? 0) +
158
- (outputTokens ?? 0) +
159
- (cacheReadTokens ?? 0) +
160
- (cacheWriteTokens ?? 0) +
161
- (reasoningTokens ?? 0),
162
- );
163
- return {
164
- inputTokens,
165
- outputTokens,
166
- cacheReadTokens,
167
- cacheWriteTokens,
168
- reasoningTokens,
169
- totalTokens,
170
- };
171
- }
172
- /**
173
- * @param {Record<string, string | undefined>} tags
174
- * @param {Record<string, unknown> | undefined} usage
175
- * @returns {Effect.Effect<void>}
176
- */
177
- function recordAgentUsageMetrics(tags, usage) {
178
- const totals = extractAgentUsageTotals(usage);
179
- const effects = [];
180
- /**
181
- * @param {string} kind
182
- * @param {number | undefined} value
183
- */
184
- const pushMetric = (kind, value) => {
185
- if (!value || value <= 0) return;
186
- effects.push(
187
- Metric.update(
188
- tagMetricWithTags(agentTokensTotal, {
189
- ...tags,
190
- kind,
191
- }),
192
- value,
193
- ),
194
- );
195
- };
196
- pushMetric("input", totals.inputTokens);
197
- pushMetric("output", totals.outputTokens);
198
- pushMetric("cache_read", totals.cacheReadTokens);
199
- pushMetric("cache_write", totals.cacheWriteTokens);
200
- pushMetric("reasoning", totals.reasoningTokens);
201
- pushMetric("total", totals.totalTokens);
202
- return effects.length > 0 ? Effect.all(effects, { discard: true }) : Effect.void;
203
- }
204
- /**
205
- * @param {AgentEventPayload} event
206
- * @returns {boolean}
207
- */
208
- function hasAgentRetrySignal(event) {
209
- const retryPattern = /\bretry(?:ing|able| after)?\b|\bbackoff\b|\brate limit\b/i;
210
- switch (event.type) {
211
- case "started":
212
- return false;
213
- case "action": {
214
- const detail = event.action.detail;
215
- if (detail) {
216
- const retryKeys = ["retryAfter", "retryAttempt", "retryDelayMs", "retryable", "backoffMs"];
217
- if (retryKeys.some((key) => key in detail)) {
218
- return true;
219
- }
220
- }
221
- return retryPattern.test(`${event.action.title} ${event.message ?? ""}`);
222
- }
223
- case "completed":
224
- return retryPattern.test(event.error ?? "");
225
- }
226
- }
227
- // ---------------------------------------------------------------------------
228
- // Event-driven metric tracking
229
- // ---------------------------------------------------------------------------
230
- /**
231
- * @param {SmithersEvent} event
232
- * @returns {Effect.Effect<void>}
233
- */
234
- export function trackEvent(event) {
235
- // Always count the event by type
236
- const countEvent = Metric.update(eventsEmittedTotal, 1);
237
- switch (event.type) {
238
- case "SupervisorStarted":
239
- return countEvent;
240
- case "SupervisorPollCompleted":
241
- return Effect.all(
242
- [
243
- countEvent,
244
- Metric.update(supervisorPollsTotal, 1),
245
- Metric.update(supervisorStaleDetected, event.staleCount),
246
- Metric.update(supervisorPollDuration, event.durationMs),
247
- ],
248
- { discard: true },
249
- );
250
- case "RunAutoResumed":
251
- return Effect.all(
252
- [
253
- countEvent,
254
- Metric.update(supervisorResumedTotal, 1),
255
- Metric.update(supervisorResumeLag, event.staleDurationMs),
256
- ],
257
- { discard: true },
258
- );
259
- case "RunAutoResumeSkipped":
260
- return Effect.all(
261
- [
262
- countEvent,
263
- Metric.update(Metric.withAttributes(supervisorSkippedTotal, { ["reason"]: String(event.reason) }), 1),
264
- ],
265
- {
266
- discard: true,
267
- },
268
- );
269
- case "RunStarted":
270
- return Effect.all([countEvent, Metric.update(runsTotal, 1), incrementGauge(activeRuns, 1)], {
271
- discard: true,
272
- });
273
- case "SandboxCreated": {
274
- const byRuntime =
275
- event.runtime && event.runtime.length > 0
276
- ? Metric.withAttributes(sandboxCreatedTotal, { ["runtime"]: String(event.runtime) })
277
- : sandboxCreatedTotal;
278
- return Effect.all(
279
- [
280
- countEvent,
281
- Metric.update(byRuntime, 1),
282
- incrementGauge(
283
- event.runtime ? Metric.withAttributes(sandboxActive, { runtime: String(event.runtime) }) : sandboxActive,
284
- 1,
285
- ),
286
- ],
287
- { discard: true },
288
- );
289
- }
290
- case "SandboxShipped":
291
- return Effect.all([countEvent, Metric.update(sandboxBundleSizeBytes, event.bundleSizeBytes)], { discard: true });
292
- case "SandboxBundleReceived":
293
- return Effect.all(
294
- [
295
- countEvent,
296
- Metric.update(sandboxBundleSizeBytes, event.bundleSizeBytes),
297
- Metric.update(sandboxPatchCount, event.patchCount),
298
- ],
299
- { discard: true },
300
- );
301
- case "SandboxCompleted": {
302
- const byStatus = Metric.withAttributes(sandboxCompletedTotal, { ["status"]: String(event.status) });
303
- const byRuntime =
304
- event.runtime && event.runtime.length > 0
305
- ? Metric.withAttributes(byStatus, { ["runtime"]: String(event.runtime) })
306
- : byStatus;
307
- return Effect.all(
308
- [
309
- countEvent,
310
- Metric.update(byRuntime, 1),
311
- incrementGauge(
312
- event.runtime ? Metric.withAttributes(sandboxActive, { runtime: String(event.runtime) }) : sandboxActive,
313
- -1,
314
- ),
315
- Metric.update(sandboxDurationMs, event.durationMs),
316
- ],
317
- { discard: true },
318
- );
319
- }
320
- case "SandboxFailed":
321
- return Effect.all([countEvent, Metric.update(errorsTotal, 1)], { discard: true });
322
- case "SandboxDiffReviewRequested":
323
- return Effect.all([countEvent, Metric.update(sandboxPatchCount, event.patchCount)], { discard: true });
324
- case "SandboxDiffAccepted":
325
- return Effect.all([countEvent, Metric.update(sandboxPatchCount, event.patchCount)], { discard: true });
326
- case "SandboxDiffRejected":
327
- return Effect.all([countEvent, Metric.update(errorsTotal, 1)], { discard: true });
328
- case "RunFinished":
329
- return Effect.all([countEvent, incrementGauge(activeRuns, -1), Metric.update(runsFinishedTotal, 1)], {
330
- discard: true,
331
- });
332
- case "RunFailed":
333
- return Effect.all(
334
- [countEvent, incrementGauge(activeRuns, -1), Metric.update(runsFailedTotal, 1), Metric.update(errorsTotal, 1)],
335
- { discard: true },
336
- );
337
- case "RunCancelled":
338
- return Effect.all([countEvent, incrementGauge(activeRuns, -1), Metric.update(runsCancelledTotal, 1)], {
339
- discard: true,
340
- });
341
- case "RunContinuedAsNew":
342
- return Effect.all(
343
- [
344
- countEvent,
345
- incrementGauge(activeRuns, -1),
346
- Metric.update(runsContinuedTotal, 1),
347
- Metric.update(runsCarriedStateBytes, event.carriedStateSize),
348
- ...(typeof event.ancestryDepth === "number" ? [Metric.update(runsAncestryDepth, event.ancestryDepth)] : []),
349
- ],
350
- { discard: true },
351
- );
352
- case "NodeStarted":
353
- return Effect.all([countEvent, Metric.update(nodesStarted, 1), incrementGauge(activeNodes, 1)], {
354
- discard: true,
355
- });
356
- case "TaskHeartbeat":
357
- return Effect.all(
358
- [
359
- countEvent,
360
- Metric.update(taskHeartbeatsTotal, 1),
361
- Metric.update(heartbeatDataSizeBytes, event.dataSizeBytes),
362
- ...(typeof event.intervalMs === "number" ? [Metric.update(heartbeatIntervalMs, event.intervalMs)] : []),
363
- ],
364
- { discard: true },
365
- );
366
- case "TaskHeartbeatTimeout":
367
- return Effect.all([countEvent, Metric.update(taskHeartbeatTimeoutTotal, 1)], { discard: true });
368
- case "NodeFinished":
369
- return Effect.all([countEvent, Metric.update(nodesFinished, 1), incrementGauge(activeNodes, -1)], {
370
- discard: true,
371
- });
372
- case "NodeFailed":
373
- return Effect.all(
374
- [countEvent, Metric.update(nodesFailed, 1), incrementGauge(activeNodes, -1), Metric.update(errorsTotal, 1)],
375
- { discard: true },
376
- );
377
- case "NodeCancelled":
378
- return Effect.all([countEvent, incrementGauge(activeNodes, -1)], { discard: true });
379
- case "NodeRetrying":
380
- return Effect.all([countEvent, Metric.update(nodeRetriesTotal, 1)], { discard: true });
381
- case "ToolCallStarted":
382
- return Effect.all([countEvent, Metric.update(toolCallsTotal, 1)], { discard: true });
383
- case "ToolCallFinished":
384
- return event.status === "error"
385
- ? Effect.all([countEvent, Metric.update(toolCallErrorsTotal, 1)], { discard: true })
386
- : countEvent;
387
- case "ApprovalRequested":
388
- return Effect.all([countEvent, Metric.update(approvalsRequested, 1), incrementGauge(approvalPending, 1)], {
389
- discard: true,
390
- });
391
- case "ApprovalGranted":
392
- return Effect.all([countEvent, Metric.update(approvalsGranted, 1), incrementGauge(approvalPending, -1)], {
393
- discard: true,
394
- });
395
- case "ApprovalAutoApproved":
396
- return Effect.all([countEvent, Metric.update(approvalsGranted, 1)], { discard: true });
397
- case "ApprovalDenied":
398
- return Effect.all([countEvent, Metric.update(approvalsDenied, 1), incrementGauge(approvalPending, -1)], {
399
- discard: true,
400
- });
401
- case "TimerCreated":
402
- return Effect.all([countEvent, Metric.update(timersCreated, 1), incrementGauge(timersPending, 1)], {
403
- discard: true,
404
- });
405
- case "TimerFired":
406
- return Effect.all(
407
- [
408
- countEvent,
409
- Metric.update(timersFired, 1),
410
- incrementGauge(timersPending, -1),
411
- Metric.update(timerDelayDuration, event.delayMs),
412
- ],
413
- { discard: true },
414
- );
415
- case "TimerCancelled":
416
- return Effect.all([countEvent, Metric.update(timersCancelled, 1), incrementGauge(timersPending, -1)], {
417
- discard: true,
418
- });
419
- case "TokenUsageReported": {
420
- const effects = [countEvent];
421
- const tags = {};
422
- if (event.model && event.model !== "unknown") tags.model = event.model;
423
- if (event.agent && event.agent !== "unknown") tags.agent = event.agent;
424
- // tags only ever holds non-empty strings, so tagMetricWithTags' falsy-skip is a no-op here.
425
- /** @type {<A>(m: A) => A} */
426
- const tagMetric = (m) => tagMetricWithTags(m, tags);
427
- if (event.inputTokens > 0) {
428
- effects.push(
429
- Metric.update(tagMetric(tokensInputTotal), event.inputTokens),
430
- Metric.update(tagMetric(tokensInputPerCall), event.inputTokens),
431
- );
432
- }
433
- if (event.outputTokens > 0) {
434
- effects.push(
435
- Metric.update(tagMetric(tokensOutputTotal), event.outputTokens),
436
- Metric.update(tagMetric(tokensOutputPerCall), event.outputTokens),
437
- );
438
- }
439
- if (event.cacheReadTokens && event.cacheReadTokens > 0) {
440
- effects.push(Metric.update(tagMetric(tokensCacheReadTotal), event.cacheReadTokens));
441
- }
442
- if (event.cacheWriteTokens && event.cacheWriteTokens > 0) {
443
- effects.push(Metric.update(tagMetric(tokensCacheWriteTotal), event.cacheWriteTokens));
444
- }
445
- if (event.reasoningTokens && event.reasoningTokens > 0) {
446
- effects.push(Metric.update(tagMetric(tokensReasoningTotal), event.reasoningTokens));
447
- }
448
- const contextWindowTokens = resolveContextWindowTokens(event);
449
- if (contextWindowTokens) {
450
- effects.push(
451
- Metric.update(tagMetric(tokensContextWindowPerCall), contextWindowTokens),
452
- Metric.update(
453
- tagMetric(
454
- Metric.withAttributes(tokensContextWindowBucketTotal, {
455
- ["bucket"]: String(classifyContextWindowBucket(contextWindowTokens)),
456
- }),
457
- ),
458
- 1,
459
- ),
460
- );
461
- }
462
- return Effect.all(effects, { discard: true });
463
- }
464
- case "AgentEvent": {
465
- const agentEvent = event.event;
466
- const engine = normalizeMetricTag(agentEvent.engine) ?? normalizeMetricTag(event.engine) ?? "unknown";
467
- const baseTags = {
468
- engine,
469
- source: "event",
470
- };
471
- const effects = [
472
- countEvent,
473
- Metric.update(
474
- tagMetricWithTags(agentEventsTotal, {
475
- ...baseTags,
476
- event_type: agentEvent.type,
477
- }),
478
- 1,
479
- ),
480
- ];
481
- switch (agentEvent.type) {
482
- case "started":
483
- effects.push(
484
- Metric.update(
485
- tagMetricWithTags(agentSessionsTotal, {
486
- ...baseTags,
487
- status: "started",
488
- resume: agentEvent.resume ? "true" : "false",
489
- }),
490
- 1,
491
- ),
492
- );
493
- break;
494
- case "action":
495
- effects.push(
496
- Metric.update(
497
- tagMetricWithTags(agentActionsTotal, {
498
- ...baseTags,
499
- action_kind: agentEvent.action.kind,
500
- phase: agentEvent.phase,
501
- level: agentEvent.level,
502
- entry_type: agentEvent.entryType,
503
- ok: typeof agentEvent.ok === "boolean" ? String(agentEvent.ok) : undefined,
504
- }),
505
- 1,
506
- ),
507
- );
508
- if (agentEvent.level === "error" || agentEvent.ok === false) {
509
- effects.push(
510
- Metric.update(
511
- tagMetricWithTags(agentErrorsTotal, {
512
- ...baseTags,
513
- event_type: agentEvent.type,
514
- action_kind: agentEvent.action.kind,
515
- }),
516
- 1,
517
- ),
518
- );
519
- }
520
- if (hasAgentRetrySignal(agentEvent)) {
521
- effects.push(
522
- Metric.update(
523
- tagMetricWithTags(agentRetriesTotal, {
524
- ...baseTags,
525
- reason: "event_signal",
526
- }),
527
- 1,
528
- ),
529
- );
530
- }
531
- break;
532
- case "completed":
533
- effects.push(
534
- Metric.update(
535
- tagMetricWithTags(agentSessionsTotal, {
536
- ...baseTags,
537
- status: agentEvent.ok ? "completed" : "failed",
538
- resume: agentEvent.resume ? "true" : "false",
539
- }),
540
- 1,
541
- ),
542
- );
543
- effects.push(recordAgentUsageMetrics(baseTags, agentEvent.usage));
544
- if (!agentEvent.ok) {
545
- effects.push(
546
- Metric.update(
547
- tagMetricWithTags(agentErrorsTotal, {
548
- ...baseTags,
549
- event_type: agentEvent.type,
550
- }),
551
- 1,
552
- ),
553
- );
554
- }
555
- if (hasAgentRetrySignal(agentEvent)) {
556
- effects.push(
557
- Metric.update(
558
- tagMetricWithTags(agentRetriesTotal, {
559
- ...baseTags,
560
- reason: "event_signal",
561
- }),
562
- 1,
563
- ),
564
- );
565
- }
566
- break;
567
- }
568
- return Effect.all(effects, { discard: true });
569
- }
570
- case "ScorerStarted":
571
- return Effect.all([countEvent, Metric.update(scorerEventsStarted, 1)], { discard: true });
572
- case "ScorerFinished":
573
- return Effect.all([countEvent, Metric.update(scorerEventsFinished, 1)], { discard: true });
574
- case "ScorerFailed":
575
- return Effect.all([countEvent, Metric.update(scorerEventsFailed, 1), Metric.update(errorsTotal, 1)], {
576
- discard: true,
577
- });
578
- case "SnapshotCaptured":
579
- return countEvent;
580
- case "RunForked":
581
- return countEvent;
582
- case "ReplayStarted":
583
- return countEvent;
584
- case "MemoryFactSet":
585
- return Effect.all([countEvent, Metric.update(memoryFactWrites, 1)], { discard: true });
586
- case "MemoryRecalled":
587
- return Effect.all([countEvent, Metric.update(memoryRecallQueries, 1)], { discard: true });
588
- case "MemoryMessageSaved":
589
- return Effect.all([countEvent, Metric.update(memoryMessageSaves, 1)], { discard: true });
590
- case "OpenApiToolCalled":
591
- return event.status === "error"
592
- ? Effect.all(
593
- [
594
- countEvent,
595
- Metric.update(openApiToolCallsTotal, 1),
596
- Metric.update(openApiToolCallErrorsTotal, 1),
597
- Metric.update(openApiToolDuration, event.durationMs),
598
- ],
599
- { discard: true },
600
- )
601
- : Effect.all(
602
- [countEvent, Metric.update(openApiToolCallsTotal, 1), Metric.update(openApiToolDuration, event.durationMs)],
603
- { discard: true },
604
- );
605
- default:
606
- return countEvent;
607
- }
608
- }
@@ -1,18 +0,0 @@
1
- import { Effect, Metric } from "effect";
2
- import { asyncExternalWaitCounts } from "./_asyncExternalWaitCounts.js";
3
- import { externalWaitAsyncPending } from "./externalWaitAsyncPending.js";
4
- /**
5
- * @param {"approval" | "event"} kind
6
- * @param {number} delta
7
- * @returns {Effect.Effect<void>}
8
- */
9
- export function updateAsyncExternalWaitPending(kind, delta) {
10
- return Effect.sync(() => {
11
- asyncExternalWaitCounts[kind] = Math.max(0, asyncExternalWaitCounts[kind] + delta);
12
- return asyncExternalWaitCounts[kind];
13
- }).pipe(
14
- Effect.flatMap((value) =>
15
- Metric.update(Metric.withAttributes(externalWaitAsyncPending, { ["kind"]: String(kind) }), value),
16
- ),
17
- );
18
- }
@@ -1,20 +0,0 @@
1
- import { Effect, Metric } from "effect";
2
- import { processStartMs } from "./_processStartMs.js";
3
- import { processUptimeSeconds } from "./processUptimeSeconds.js";
4
- import { processMemoryRssBytes } from "./processMemoryRssBytes.js";
5
- import { processHeapUsedBytes } from "./processHeapUsedBytes.js";
6
- /**
7
- * @returns {Effect.Effect<void>}
8
- */
9
- export function updateProcessMetrics() {
10
- const uptimeS = (Date.now() - processStartMs) / 1000;
11
- const mem = process.memoryUsage();
12
- return Effect.all(
13
- [
14
- Metric.update(processUptimeSeconds, uptimeS),
15
- Metric.update(processMemoryRssBytes, mem.rss),
16
- Metric.update(processHeapUsedBytes, mem.heapUsed),
17
- ],
18
- { discard: true },
19
- );
20
- }
@@ -1,3 +0,0 @@
1
- import { Metric } from "effect";
2
- import { fastBuckets } from "./_buckets.js";
3
- export const vcsDuration = Metric.histogram("smithers.vcs.duration_ms", { boundaries: fastBuckets });
@@ -1,15 +0,0 @@
1
- import { normalizeStructuredEventForFamily } from "./_traceEventNormalizers.js";
2
- /**
3
- * @typedef {import('./agentTrace.ts').AgentFamily} AgentFamily
4
- * @typedef {import('./_traceEventNormalizers.js').NormalizedTraceBatch} NormalizedTraceBatch
5
- */
6
-
7
- /**
8
- * @param {AgentFamily} agentFamily
9
- * @param {any} parsed
10
- * @param {string} rawType
11
- * @returns {NormalizedTraceBatch}
12
- */
13
- export function normalizeStructuredEvent(agentFamily, parsed, rawType) {
14
- return normalizeStructuredEventForFamily(agentFamily, parsed, rawType);
15
- }
@@ -1 +0,0 @@
1
- export const prometheusContentType = "text/plain; version=0.0.4; charset=utf-8";