Add @smooai/observability/metrics subpath — agent metrics on OTel meters - #10
Merged
Conversation
Phase 2 of the ECS/agent instrumentation push: ship a metrics API so the
smooai voice agent and other services can emit agent.turn.completed,
agent.tokens.used, agent.tool.call.latency.ms, agent.ttft.ms, etc.
New module: packages/core/src/metrics/index.ts
getMetricsClient(meterName?: string): MetricsClient {
counter(name, value?, attrs?)
histogram(name, value, attrs?)
timing(name, ms, attrs?) // histogram with unit=ms
startTimer(name, attrs?) → () => void // wall-clock timer
withTiming(name, fn, attrs?) // wraps async, tags status=success|error
}
Thin Smoo-flavored API on top of @opentelemetry/api's metrics surface.
Instruments are cached by (meterName, instrumentName) so we don't leak
Meter handles. All methods swallow internal errors — observability MUST
NOT throw into user code.
setup-otel-sdk.ts updated to also wire a metrics MeterProvider:
- OTLPMetricExporter for OTLP/HTTP metric export
- PeriodicExportingMetricReader, 30s default interval
(overridable via metricExportIntervalMs option — useful for short-
lived Lambda containers where 30s is too long)
- OTEL_EXPORTER_OTLP_METRICS_ENDPOINT env supported alongside the
trace endpoint
Package surface:
- New ./metrics subpath export
- New tsdown entry → dist/metrics.mjs + .d.mts
- Added deps: @opentelemetry/exporter-metrics-otlp-http, @opentelemetry/sdk-metrics
- Version 0.5.0 → 0.6.0
Tests: 8 new in src/metrics/__tests__/metrics-client.test.ts covering
counter, histogram, timing, startTimer, withTiming (success + error),
instrument reuse, and the "swallows internal errors" contract. Uses
InMemoryMetricExporter so tests assert on actual recorded data points
without standing up a collector. 46/46 total tests green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
./metricssubpath withgetMetricsClient()API (counter / histogram / timing / startTimer / withTiming) on top of OTel Meter.setupOtelSdknow also wires OTLP metric export. 8 new tests, 46/46 total green. Version 0.5 → 0.6.