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