feat(core): wire a MeterProvider into the Python runtime (gated OTEL_METRICS_ENABLED) - #2672
Open
MartinForReal wants to merge 1 commit into
Open
Conversation
…METRICS_ENABLED) google-adk already defines and records its GenAI metric instruments (duration histograms, inference/tool-call counts, gen_ai.client.token.usage) under meter scope gcp.vertex.agent, but kagent.core.tracing.configure only installed a TracerProvider and LoggerProvider, so those data points were silently discarded on every invocation. Add a metric_exporter/PeriodicExportingMetricReader OTLP pipeline mirroring traces and logs (reusing _resolve_otlp_protocol/_resolve_otlp_timeout_seconds) behind a default-OFF OTEL_METRICS_ENABLED gate, flush metrics from force_flush alongside spans so the Agent Substrate pre-response checkpoint hazard is covered, and expose otel.metrics.* from the Helm chart. Signed-off-by: MartinForReal <fanshangxiang@gmail.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.
What
Fixes the Python half of the metrics gap (#2458): the Python runtime never installed a
MeterProvider, so the seven GenAI metric instruments thatgoogle-adkalready defines and records (insrc/google/adk/telemetry/_metrics.pyunder meter scopegcp.vertex.agent) were silently discarded on every invocation. This wires a meter provider (gatedOTEL_METRICS_ENABLED, default-OFF) with no new instrument definitions and no new recording call sites — upstream already records them. Companion to #2148 / #2149 for Go.Changes
kagent.core.tracing.configure()(python/packages/kagent-core/src/kagent/core/tracing/_utils.py):metrics_enabled = os.getenv("OTEL_METRICS_ENABLED", "false") == "true"gate, mirroringOTEL_TRACING_ENABLED/OTEL_LOGGING_ENABLED._create_metric_exporter()helper reusing_resolve_otlp_protocol("METRICS"), the shared endpoint resolution, and_resolve_otlp_timeout_seconds("METRICS"), so protocol/endpoint/timeout semantics match traces and logs.MeterProvider(resource=resource, metric_readers=[PeriodicExportingMetricReader(OTLPMetricExporter(...))])and callsmetrics.set_meter_provider.force_flushto drain the meter provider, covering the Agent Substrate checkpoint hazard that motivatedKAGENT_PRE_RESPONSE_TRACE_FLUSH.helm/kagent/values.yaml: newotel.metricsblock alongsideotel.tracing/otel.logging(defaultenabled: false).helm/kagent/templates/controller-configmap.yaml: mapsotel.metrics.*toOTEL_METRICS_ENABLED/OTEL_EXPORTER_OTLP_METRICS_*with the same unified-vs-separate-endpoint branch as traces/logs.Default-OFF / no behaviour change
When
OTEL_METRICS_ENABLEDis unset (the default),configureinstalls no meter provider and behavior is byte-identical to before. Existing gates unchanged.Testing
uv run pytest packages/kagent-core/tests/test_tracing_configure.py -q→ 30 passed (added tests for default-off, endpoint/timeout reuse, meter-provider install, andforce_flushdraining the meter provider).uv run ruff checkanduv run ruff format --diffclean on changed files.Refs: #2458
DCO sign-off via
git commit -s.