Propagate metric groups to cross-language resources
Propagated action metric groups across Apache Flink Agents Java/Python resource boundaries so cross-language resources keep the caller's observability scope.
apache/flink-agents · #860
Problem
Flink Agents bound action metric groups to same-language resources, but Java-to-Python and Python-to-Java wrappers did not consistently forward that group to the underlying provider resource. Provider-owned metrics for chat models, embeddings, vector stores, MCP resources, latency, errors, and cache behavior could therefore miss the caller's action scope.
Approach
Added default metric-forwarding hooks to PythonResourceAdapter and PythonResourceWrapper, wired Java wrappers for Python-backed resources to forward their metric group, and added Python-side helpers that unwrap FlinkMetricGroup when binding Java resources while rejecting unsupported custom metric groups clearly.
Impact and scope
- Makes cross-language Java/Python resource observability match same-language resource behavior.
- Preserves single-recorder metric ownership while forwarding the bound metric group into provider implementations.
- Improves production tracing for agent resources that need backend-specific dimensions such as service, endpoint, tenant, latency, errors, or cache behavior.
Validation
- Added Python coverage for Java resource wrappers, FlinkMetricGroup unwrapping, None forwarding, and unsupported metric-group rejection.
- Added Java coverage for PythonResourceAdapterImpl and Python chat model setup metric forwarding.
- PR validation covered focused pytest, Maven compile/test targets across api/plan/runtime, and the repository lint script.