Skip to content

feat(kagent-core): wire a MeterProvider so google-adk GenAI metrics export (gated OTEL_METRICS_ENABLED) - #2674

Closed
MartinForReal wants to merge 1 commit into
kagent-dev:mainfrom
MartinForReal:feat-py-meterprovider
Closed

feat(kagent-core): wire a MeterProvider so google-adk GenAI metrics export (gated OTEL_METRICS_ENABLED)#2674
MartinForReal wants to merge 1 commit into
kagent-dev:mainfrom
MartinForReal:feat-py-meterprovider

Conversation

@MartinForReal

Copy link
Copy Markdown

Closes #2458

What

Wires a real MeterProvider into the Python agent runtime (kagent.core.tracing.configure()) so the seven GenAI metric instruments that google-adk already defines and records are exported instead of silently discarded.

Gated default-OFF behind OTEL_METRICS_ENABLED=true, matching the existing OTEL_TRACING_ENABLED / OTEL_LOGGING_ENABLED gates. When the gate is unset the runtime is byte-identical to today.

  • python/packages/kagent-core/src/kagent/core/tracing/_utils.py — new _create_metric_exporter() mirroring the trace/log exporters (_resolve_otlp_protocol("METRICS"), endpoint, _resolve_otlp_timeout_seconds("METRICS")); builds PeriodicExportingMetricReader + MeterProvider(resource=...) and calls metrics.set_meter_provider(...). force_flush() now also flushes the metric reader, reusing the existing KAGENT_PRE_RESPONSE_TRACE_FLUSH pre-response flush to guard against the Agent Substrate checkpoint hazard for periodic readers.
  • helm/kagent/values.yaml — new otel.metrics block alongside otel.tracing / otel.logging.
  • tests/test_tracing_configure.py — 8 tests (default-OFF, env gating incl. garbage values, provider construction, signal-specific endpoint resolution, flush behavior).

Notes

  • Verified google-adk (2.8.0) ships all seven instruments under meter scope gcp.vertex.agent and that token accounting incl. cached_content_token_count is handled upstream; ADK's own provider setup is not invoked by the kagent runtime, so the pipeline was genuinely absent.
  • No new instruments and no new recording call sites.

Follow-up (not in this PR)

The Go-side env plumbing (OTEL_METRICS_ENABLED add to the env-forward allowlist so the flag reaches agent pods) is the companion work; see #2148/#2673. This PR is the Python/collection half.

Signed-off-by / generated by MartinForReal.

…re exported, gated via OTEL_METRICS_ENABLED

Signed-off-by: MartinForReal <fanshangxiang@gmail.com>
@MartinForReal
MartinForReal requested a review from a team as a code owner September 3, 2026 06:37
@github-actions github-actions Bot added the enhancement New feature or request label Sep 3, 2026
@MartinForReal

Copy link
Copy Markdown
Author

Closing as a duplicate of #2672, which is the more complete implementation of #2458 — it additionally wires OTEL_METRICS_ENABLED / OTLP metrics env through helm/kagent/templates/controller-configmap.yaml so the feature is operable end-to-end, and has passing tests + clean ruff. Keeping a single PR for #2458 to avoid duplicate review. All discussion continues in #2672.

@MartinForReal
MartinForReal deleted the feat-py-meterprovider branch September 3, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Python runtime never sets a MeterProvider, so google-adk's 7 built-in GenAI metrics are silently discarded

1 participant