Skip to content

Add @smooai/observability/metrics subpath — agent metrics on OTel meters - #10

Merged
brentrager merged 1 commit into
mainfrom
metrics-module
May 18, 2026
Merged

Add @smooai/observability/metrics subpath — agent metrics on OTel meters#10
brentrager merged 1 commit into
mainfrom
metrics-module

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

Adds ./metrics subpath with getMetricsClient() API (counter / histogram / timing / startTimer / withTiming) on top of OTel Meter. setupOtelSdk now also wires OTLP metric export. 8 new tests, 46/46 total green. Version 0.5 → 0.6.

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>
@brentrager
brentrager merged commit 97952a6 into main May 18, 2026
@brentrager
brentrager deleted the metrics-module branch May 18, 2026 19:44
@changeset-bot

changeset-bot Bot commented May 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4be7719

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant