@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
package/src/index.js ADDED
@@ -0,0 +1,35 @@
1
+ /** @typedef {import("./_coreCorrelation/CorrelationContext.ts").CorrelationContext} CorrelationContext */
2
+ /** @typedef {import("./_coreCorrelation/CorrelationPatch.ts").CorrelationPatch} CorrelationPatch */
3
+ /** @typedef {CorrelationPatch} CorrelationContextPatch */
4
+ /** @typedef {import("./_corePrometheusShape.ts").MetricLabels} MetricLabels */
5
+ /** @typedef {import("./_coreMetricsShape.ts").MetricsServiceShape} MetricsServiceShape */
6
+ /** @typedef {import("./_coreMetricsShape.ts").MetricsSnapshot} MetricsSnapshot */
7
+ /** @typedef {import("./ResolvedSmithersObservabilityOptions.ts").ResolvedSmithersObservabilityOptions} ResolvedSmithersObservabilityOptions */
8
+ /** @typedef {import("./SmithersEvent.ts").SmithersEvent} SmithersEvent */
9
+ /** @typedef {import("./SmithersLogFormat.ts").SmithersLogFormat} SmithersLogFormat */
10
+ /** @typedef {import("./SmithersMetricDefinition.ts").SmithersMetricDefinition} SmithersMetricDefinition */
11
+ /** @typedef {import("./SmithersObservabilityOptions.ts").SmithersObservabilityOptions} SmithersObservabilityOptions */
12
+ /** @typedef {import("./SmithersObservabilityService.ts").SmithersObservabilityService} SmithersObservabilityService */
13
+
14
+ export { MetricsService, } from "./_coreMetrics.js";
15
+ export { TracingService, TracingServiceLive, } from "./_coreTracing.js";
16
+ export { SmithersObservability } from "./SmithersObservability.js";
17
+ export { prometheusContentType } from "./prometheusContentType.js";
18
+ export { smithersSpanNames } from "./smithersSpanNames.js";
19
+ export { getCurrentSmithersTraceSpan } from "./getCurrentSmithersTraceSpan.js";
20
+ export { getCurrentSmithersTraceAnnotations } from "./getCurrentSmithersTraceAnnotations.js";
21
+ export { makeSmithersSpanAttributes } from "./makeSmithersSpanAttributes.js";
22
+ export { annotateSmithersTrace } from "./annotateSmithersTrace.js";
23
+ export { withSmithersSpan } from "./withSmithersSpan.js";
24
+ export { renderPrometheusMetrics } from "./renderPrometheusMetrics.js";
25
+ export { resolveSmithersObservabilityOptions } from "./resolveSmithersObservabilityOptions.js";
26
+ export { smithersMetrics } from "./smithersMetrics.js";
27
+ export { MetricsServiceLive } from "./MetricsServiceLive.js";
28
+ export { createSmithersOtelLayer } from "./createSmithersOtelLayer.js";
29
+ export { createSmithersObservabilityLayer } from "./createSmithersObservabilityLayer.js";
30
+ export { createSmithersRuntimeLayer } from "./createSmithersRuntimeLayer.js";
31
+ export { rewindTotal, rewindRollbackTotal, rewindDurationMs, rewindFramesDeleted, rewindSandboxesReverted, } from "./metrics/index.js";
32
+ export { activeNodes, activeRuns, approvalPending, externalWaitAsyncPending, approvalsDenied, approvalsGranted, approvalsRequested, approvalWaitDuration, timerDelayDuration, timersCancelled, timersCreated, timersFired, timersPending, attemptDuration, cacheHits, cacheMisses, dbQueryDuration, dbRetries, dbTransactionDuration, dbTransactionRetries, dbTransactionRollbacks, errorsTotal, eventsEmittedTotal, hotReloadDuration, hotReloadFailures, hotReloads, httpRequestDuration, httpRequests, nodeDuration, nodeRetriesTotal, nodesFailed, nodesFinished, nodesStarted, processHeapUsedBytes, processMemoryRssBytes, processUptimeSeconds, promptSizeBytes, responseSizeBytes, runDuration, runsCancelledTotal, runsContinuedTotal, runsFailedTotal, runsFinishedTotal, runsResumedTotal, runsAncestryDepth, runsCarriedStateBytes, sandboxActive, sandboxBundleSizeBytes, sandboxCompletedTotal, sandboxCreatedTotal, sandboxDurationMs, sandboxPatchCount, sandboxTransportDurationMs, runsTotal, schedulerConcurrencyUtilization, schedulerQueueDepth, schedulerWaitDuration, tokensCacheReadTotal, tokensCacheWriteTotal, tokensContextWindowBucketTotal, tokensContextWindowPerCall, tokensInputPerCall, tokensInputTotal, tokensOutputPerCall, tokensOutputTotal, tokensReasoningTotal, toolCallErrorsTotal, toolCallsTotal, toolDuration, toolOutputTruncatedTotal, scorerEventsStarted, scorerEventsFinished, scorerEventsFailed, trackEvent as trackSmithersEvent, updateProcessMetrics, vcsDuration, toPrometheusMetricName, smithersMetricCatalog, metricsServiceAdapter, } from "./metrics/index.js";
33
+ export { correlationContextFiberRef, correlationContextToLogAnnotations, CorrelationContextLive, CorrelationContextService, getCurrentCorrelationContext, getCurrentCorrelationContextEffect, mergeCorrelationContext, runWithCorrelationContext, withCorrelationContext, withCurrentCorrelationContext, } from "./correlation.js";
34
+ export { updateCurrentCorrelationContext } from "./correlation.js";
35
+ export { logDebug, logInfo, logWarning, logError, } from "./logging.js";
package/src/logging.js ADDED
@@ -0,0 +1,91 @@
1
+ import { Effect } from "effect";
2
+ import { getCurrentSmithersTraceAnnotations } from "./getCurrentSmithersTraceAnnotations.js";
3
+ import { correlationContextToLogAnnotations, getCurrentCorrelationContext, withCurrentCorrelationContext, } from "./correlation.js";
4
+ /**
5
+ * @typedef {Record<string, unknown> | undefined} LogAnnotations
6
+ */
7
+
8
+ /** @type {number} */
9
+ const LOG_LEVEL_NONE = 0;
10
+ const LOG_LEVEL_DEBUG = 1;
11
+ const LOG_LEVEL_INFO = 2;
12
+ const LOG_LEVEL_WARNING = 3;
13
+ const LOG_LEVEL_ERROR = 4;
14
+
15
+ /** @returns {number} */
16
+ function resolveMinLevel() {
17
+ const env = process.env.SMITHERS_LOG_LEVEL?.toLowerCase();
18
+ switch (env) {
19
+ case "none": return Infinity;
20
+ case "trace":
21
+ case "debug": return LOG_LEVEL_DEBUG;
22
+ case "warning":
23
+ case "warn": return LOG_LEVEL_WARNING;
24
+ case "error": return LOG_LEVEL_ERROR;
25
+ case "fatal": return Infinity;
26
+ case "all": return LOG_LEVEL_NONE;
27
+ case "info": return LOG_LEVEL_INFO;
28
+ default: return LOG_LEVEL_WARNING;
29
+ }
30
+ }
31
+
32
+ const minLevel = resolveMinLevel();
33
+
34
+ /**
35
+ * @param {Effect.Effect<void, never, never>} effect
36
+ * @param {LogAnnotations} [annotations]
37
+ * @param {string} [span]
38
+ * @param {number} [level]
39
+ */
40
+ function emitLog(effect, annotations, span, level = LOG_LEVEL_INFO) {
41
+ if (level < minLevel) return;
42
+ const correlationAnnotations = correlationContextToLogAnnotations(getCurrentCorrelationContext());
43
+ const traceAnnotations = getCurrentSmithersTraceAnnotations();
44
+ const mergedAnnotations = correlationAnnotations || traceAnnotations || annotations
45
+ ? {
46
+ ...correlationAnnotations,
47
+ ...traceAnnotations,
48
+ ...annotations,
49
+ }
50
+ : undefined;
51
+ let program = effect;
52
+ if (mergedAnnotations) {
53
+ program = program.pipe(Effect.annotateLogs(mergedAnnotations));
54
+ }
55
+ if (span) {
56
+ program = program.pipe(Effect.withLogSpan(span));
57
+ }
58
+ void Effect.runFork(withCurrentCorrelationContext(program));
59
+ }
60
+ /**
61
+ * @param {string} message
62
+ * @param {LogAnnotations} [annotations]
63
+ * @param {string} [span]
64
+ */
65
+ export function logDebug(message, annotations, span) {
66
+ emitLog(Effect.logDebug(message), annotations, span, LOG_LEVEL_DEBUG);
67
+ }
68
+ /**
69
+ * @param {string} message
70
+ * @param {LogAnnotations} [annotations]
71
+ * @param {string} [span]
72
+ */
73
+ export function logInfo(message, annotations, span) {
74
+ emitLog(Effect.logInfo(message), annotations, span, LOG_LEVEL_INFO);
75
+ }
76
+ /**
77
+ * @param {string} message
78
+ * @param {LogAnnotations} [annotations]
79
+ * @param {string} [span]
80
+ */
81
+ export function logWarning(message, annotations, span) {
82
+ emitLog(Effect.logWarning(message), annotations, span, LOG_LEVEL_WARNING);
83
+ }
84
+ /**
85
+ * @param {string} message
86
+ * @param {LogAnnotations} [annotations]
87
+ * @param {string} [span]
88
+ */
89
+ export function logError(message, annotations, span) {
90
+ emitLog(Effect.logError(message), annotations, span, LOG_LEVEL_ERROR);
91
+ }
@@ -0,0 +1,20 @@
1
+ import { smithersSpanAttributeAliases } from "./_smithersSpanAttributeAliases.js";
2
+ /**
3
+ * @typedef {Readonly<Record<string, unknown>>} SmithersSpanAttributesInput
4
+ */
5
+
6
+ /**
7
+ * @param {SmithersSpanAttributesInput} [attributes]
8
+ * @returns {Record<string, unknown>}
9
+ */
10
+ export function makeSmithersSpanAttributes(attributes = {}) {
11
+ const spanAttributes = {};
12
+ for (const [key, value] of Object.entries(attributes)) {
13
+ if (value === undefined) {
14
+ continue;
15
+ }
16
+ const nextKey = key.startsWith("smithers.") ? key : (smithersSpanAttributeAliases[key] ?? key);
17
+ spanAttributes[nextKey] = value;
18
+ }
19
+ return spanAttributes;
20
+ }
@@ -0,0 +1,17 @@
1
+ import type { Metric } from "effect";
2
+ import type { SmithersMetricType } from "./SmithersMetricType";
3
+ import type { SmithersMetricUnit } from "./SmithersMetricUnit";
4
+
5
+ export type SmithersMetricDefinition = {
6
+ readonly key: string;
7
+ readonly metric: Metric.Metric<any, any, any>;
8
+ readonly name: string;
9
+ readonly prometheusName: string;
10
+ readonly type: SmithersMetricType;
11
+ readonly label: string;
12
+ readonly unit?: SmithersMetricUnit;
13
+ readonly description?: string;
14
+ readonly labels?: readonly string[];
15
+ readonly boundaries?: readonly number[];
16
+ readonly defaultLabels?: readonly Readonly<Record<string, string>>[];
17
+ };
@@ -0,0 +1 @@
1
+ export type SmithersMetricType = "counter" | "gauge" | "histogram";
@@ -0,0 +1,8 @@
1
+ export type SmithersMetricUnit =
2
+ | "count"
3
+ | "milliseconds"
4
+ | "seconds"
5
+ | "bytes"
6
+ | "tokens"
7
+ | "ratio"
8
+ | "depth";
@@ -0,0 +1,4 @@
1
+ export const asyncExternalWaitCounts = {
2
+ approval: 0,
3
+ event: 0,
4
+ };
@@ -0,0 +1,43 @@
1
+ import { MetricBoundaries } from "effect";
2
+ export const durationBuckets = MetricBoundaries.exponential({
3
+ start: 100,
4
+ factor: 2,
5
+ count: 12,
6
+ }); // ~100ms to ~200s
7
+ export const fastBuckets = MetricBoundaries.exponential({
8
+ start: 1,
9
+ factor: 2,
10
+ count: 12,
11
+ }); // ~1ms to ~2s
12
+ export const toolBuckets = MetricBoundaries.exponential({
13
+ start: 10,
14
+ factor: 2,
15
+ count: 14,
16
+ }); // ~10ms to ~80s
17
+ export const tokenBuckets = MetricBoundaries.exponential({
18
+ start: 10,
19
+ factor: 2,
20
+ count: 18,
21
+ }); // ~10 to ~1.3M tokens
22
+ export const contextWindowBuckets = MetricBoundaries.fromIterable([
23
+ 50_000,
24
+ 100_000,
25
+ 200_000,
26
+ 500_000,
27
+ 1_000_000,
28
+ ]);
29
+ export const sizeBuckets = MetricBoundaries.exponential({
30
+ start: 100,
31
+ factor: 2,
32
+ count: 16,
33
+ }); // ~100 bytes to ~3.2MB
34
+ export const carriedStateSizeBuckets = MetricBoundaries.exponential({
35
+ start: 256,
36
+ factor: 2,
37
+ count: 17,
38
+ }); // ~256 bytes to ~16MB
39
+ export const ancestryDepthBuckets = MetricBoundaries.exponential({
40
+ start: 1,
41
+ factor: 2,
42
+ count: 12,
43
+ }); // depth 1 to 2048
@@ -0,0 +1 @@
1
+ export const processStartMs = Date.now();
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const activeNodes = Metric.gauge("smithers.nodes.active");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const activeRuns = Metric.gauge("smithers.runs.active");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const agentActionsTotal = Metric.counter("smithers.agent_actions_total");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const agentDurationMs = Metric.histogram("smithers.agent_duration_ms", durationBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const agentErrorsTotal = Metric.counter("smithers.agent_errors_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const agentEventsTotal = Metric.counter("smithers.agent_events_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const agentInvocationsTotal = Metric.counter("smithers.agent_invocations_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const agentRetriesTotal = Metric.counter("smithers.agent_retries_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const agentSessionsTotal = Metric.counter("smithers.agent_sessions_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const agentTokensTotal = Metric.counter("smithers.agent_tokens_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const alertDeliveriesAttempted = Metric.counter("smithers.alerts.deliveries_attempted");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const alertDeliveriesSuppressed = Metric.counter("smithers.alerts.deliveries_suppressed");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const alertsAcknowledgedTotal = Metric.counter("smithers.alerts.acknowledged_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const alertsActive = Metric.gauge("smithers.alerts.active");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const alertsEscalatedTotal = Metric.counter("smithers.alerts.escalated_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const alertsFiredTotal = Metric.counter("smithers.alerts.fired_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const alertsReopenedTotal = Metric.counter("smithers.alerts.reopened_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const alertsResolvedTotal = Metric.counter("smithers.alerts.resolved_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const alertsSilencedTotal = Metric.counter("smithers.alerts.silenced_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const approvalPending = Metric.gauge("smithers.approval.pending");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const approvalWaitDuration = Metric.histogram("smithers.approval.wait_duration_ms", durationBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const approvalsDenied = Metric.counter("smithers.approvals.denied");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const approvalsGranted = Metric.counter("smithers.approvals.granted");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const approvalsRequested = Metric.counter("smithers.approvals.requested");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const attemptDuration = Metric.histogram("smithers.attempt.duration_ms", durationBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const attentionBacklog = Metric.gauge("smithers.attention.backlog");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const cacheHits = Metric.counter("smithers.cache.hits");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const cacheMisses = Metric.counter("smithers.cache.misses");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { fastBuckets } from "./_buckets.js";
3
+ export const dbQueryDuration = Metric.histogram("smithers.db.query_ms", fastBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const dbRetries = Metric.counter("smithers.db.retries");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { fastBuckets } from "./_buckets.js";
3
+ export const dbTransactionDuration = Metric.histogram("smithers.db.transaction_ms", fastBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const dbTransactionRetries = Metric.counter("smithers.db.transaction_retries");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const dbTransactionRollbacks = Metric.counter("smithers.db.transaction_rollbacks");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const devtoolsActiveSubscribers = Metric.gauge("smithers.devtools.active_subscribers");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const devtoolsBackpressureDisconnectTotal = Metric.counter("smithers.devtools.backpressure_disconnect_total");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { fastBuckets } from "./_buckets.js";
3
+ export const devtoolsDeltaBuildMs = Metric.histogram("smithers.devtools.delta_build_ms", fastBuckets);
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { sizeBuckets } from "./_buckets.js";
3
+ export const devtoolsEventBytes = Metric.histogram("smithers.devtools.event_bytes", sizeBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const devtoolsEventTotal = Metric.counter("smithers.devtools.event_total");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { fastBuckets } from "./_buckets.js";
3
+ export const devtoolsSnapshotBuildMs = Metric.histogram("smithers.devtools.snapshot_build_ms", fastBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const devtoolsSubscribeTotal = Metric.counter("smithers.devtools.subscribe_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const errorsTotal = Metric.counter("smithers.errors.total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const eventsEmittedTotal = Metric.counter("smithers.events.emitted_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const externalWaitAsyncPending = Metric.gauge("smithers.external_wait.async_pending");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayApprovalDecisionsTotal = Metric.counter("smithers.gateway.approval_decisions_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayAuthEventsTotal = Metric.counter("smithers.gateway.auth_events_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayConnectionsActive = Metric.gauge("smithers.gateway.connections_active");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayConnectionsClosedTotal = Metric.counter("smithers.gateway.connections_closed_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayConnectionsTotal = Metric.counter("smithers.gateway.connections_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayCronTriggersTotal = Metric.counter("smithers.gateway.cron_triggers_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayErrorsTotal = Metric.counter("smithers.gateway.errors_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayHeartbeatTicksTotal = Metric.counter("smithers.gateway.heartbeat_ticks_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayMessagesReceivedTotal = Metric.counter("smithers.gateway.messages_received_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayMessagesSentTotal = Metric.counter("smithers.gateway.messages_sent_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayRpcCallsTotal = Metric.counter("smithers.gateway.rpc_calls_total");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const gatewayRpcDuration = Metric.histogram("smithers.gateway.rpc_duration_ms", durationBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayRunsCompletedTotal = Metric.counter("smithers.gateway.runs_completed_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayRunsStartedTotal = Metric.counter("smithers.gateway.runs_started_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewaySignalsTotal = Metric.counter("smithers.gateway.signals_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayWebhooksReceivedTotal = Metric.counter("smithers.gateway.webhooks_received_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayWebhooksRejectedTotal = Metric.counter("smithers.gateway.webhooks_rejected_total");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const gatewayWebhooksVerifiedTotal = Metric.counter("smithers.gateway.webhooks_verified_total");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { sizeBuckets } from "./_buckets.js";
3
+ export const heartbeatDataSizeBytes = Metric.histogram("smithers.heartbeats.data_size_bytes", sizeBuckets);
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { fastBuckets } from "./_buckets.js";
3
+ export const heartbeatIntervalMs = Metric.histogram("smithers.heartbeats.interval_ms", fastBuckets);
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { durationBuckets } from "./_buckets.js";
3
+ export const hotReloadDuration = Metric.histogram("smithers.hot.reload_duration_ms", durationBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const hotReloadFailures = Metric.counter("smithers.hot.reload_failures");
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const hotReloads = Metric.counter("smithers.hot.reloads");
@@ -0,0 +1,3 @@
1
+ import { Metric } from "effect";
2
+ import { fastBuckets } from "./_buckets.js";
3
+ export const httpRequestDuration = Metric.histogram("smithers.http.request_duration_ms", fastBuckets);
@@ -0,0 +1,2 @@
1
+ import { Metric } from "effect";
2
+ export const httpRequests = Metric.counter("smithers.http.requests");