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
Closed
Conversation
…re exported, gated via OTEL_METRICS_ENABLED Signed-off-by: MartinForReal <fanshangxiang@gmail.com>
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. |
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.
Closes #2458
What
Wires a real
MeterProviderinto the Python agent runtime (kagent.core.tracing.configure()) so the seven GenAI metric instruments thatgoogle-adkalready defines and records are exported instead of silently discarded.Gated default-OFF behind
OTEL_METRICS_ENABLED=true, matching the existingOTEL_TRACING_ENABLED/OTEL_LOGGING_ENABLEDgates. 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")); buildsPeriodicExportingMetricReader+MeterProvider(resource=...)and callsmetrics.set_meter_provider(...).force_flush()now also flushes the metric reader, reusing the existingKAGENT_PRE_RESPONSE_TRACE_FLUSHpre-response flush to guard against the Agent Substrate checkpoint hazard for periodic readers.helm/kagent/values.yaml— newotel.metricsblock alongsideotel.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
google-adk(2.8.0) ships all seven instruments under meter scopegcp.vertex.agentand that token accounting incl.cached_content_token_countis handled upstream; ADK's own provider setup is not invoked by the kagent runtime, so the pipeline was genuinely absent.Follow-up (not in this PR)
The Go-side env plumbing (
OTEL_METRICS_ENABLEDadd 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.