Repository navigation
Python: Remove span-only tool attributes from invocation metrics - #9592
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
What changed in this PR
This PR tightens function-invocation metric dimensions by switching from copying span attributes to an explicit allowlist, preventing span-only (potentially sensitive / high-cardinality) tool metadata from flowing into histogram metrics.
Changes:
- Build metric attributes from an explicit allowlist (operation, tool name/type, framework function tag) instead of cloning span attributes.
- Update regression tests to assert the complete metric attribute set for sync, async, and failure paths.
| File | Description |
|---|---|
| python/packages/core/agent_framework/_tools.py | Replaces metric attribute construction to use an explicit allowlist rather than copying span attributes. |
| python/packages/core/tests/core/test_tools.py | Strengthens assertions to validate the exact set of metric attributes recorded across invocation scenarios. |
Review effort: Lite
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5e52ce1a-cfca-43c6-990b-1dcf74052845
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: No findings
Scope: full PR (1 commit(s)): 9140c4f80f87
Model: gpt-5.6-sol
Overview
The PR replaces the invocation histogram's copy of span attributes with an explicit four-key metric allowlist while preserving span telemetry and failure classification. Exact-set regression assertions cover successful, sensitive-disabled, failed, and asynchronous invocations, and the helper contract guarantees the three selected span keys. No residual Critical, High, or Medium defect was established.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5e52ce1a-cfca-43c6-990b-1dcf74052845
9140c4f to
4505e79
Compare


Motivation & Context
PR #9361 detached tool-call payload attributes from function-invocation metrics, but the metric snapshot still copied every base tool-span attribute. As a result,
gen_ai.tool.descriptionand the per-invocationgen_ai.tool.call.idremained histogram dimensions.This follow-up keeps span telemetry unchanged while preventing span-only, potentially sensitive, and high-cardinality metadata from flowing into metrics.
Description & Review Guide
error.type. Regression tests assert the complete metric attribute set across successful, sensitive-disabled, failed, and asynchronous invocations.execute_toolspans but no longer become metric dimensions. Existing low-cardinality dimensions and failure classification remain unchanged.Related Issue
N/A - trivial change. This is an obvious telemetry correctness and cardinality follow-up to #9361. It supersedes #9567 because this branch is rebased on current
main, includes the explicit metric dictionary type required by Pyright, and strengthens regression coverage by asserting the complete metric attribute set across all relevant invocation paths.AI Assistance
AI assistance details: Copilot assisted with implementation, regression tests, validation, and the PR description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.