Skip to content

Python: Remove span-only tool attributes from invocation metrics - #9592

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
mainfrom
remove-tool-metric-attributes
Oct 22, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
mainfrom
remove-tool-metric-attributes

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

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.description and the per-invocation gen_ai.tool.call.id remained 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

  • What are the major changes? Function-duration metric attributes are now built from an explicit allowlist containing operation name, tool name, tool type, and the framework function name. Failure metrics continue to add error.type. Regression tests assert the complete metric attribute set across successful, sensitive-disabled, failed, and asynchronous invocations.
  • What is the impact of these changes? Tool descriptions and call IDs remain available on execute_tool spans but no longer become metric dimensions. Existing low-cardinality dimensions and failure classification remain unchanged.
  • What do you want reviewers to focus on? Please verify that the explicit allowlist preserves the intended aggregation dimensions while preventing current and future span-only attributes from entering the histogram.

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

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: Copilot assisted with implementation, regression tests, validation, and the PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread python/packages/core/agent_framework/_tools.py Outdated
Comment thread python/packages/core/tests/core/test_tools.py Outdated
Comment thread python/packages/core/agent_framework/_tools.py Outdated
@github-code-quality

github-code-quality Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage overview

Languages: Python

Python / code-coverage/python

main 6ae0f40 remove-tool-metric-a... 4505e79 +/-
92% 92% 0%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 22, 2026 11:34 UTC

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5e52ce1a-cfca-43c6-990b-1dcf74052845

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Merged via the queue into main with commit b7f8ad6 Oct 22, 2026
51 of 52 checks passed
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) deleted the remove-tool-metric-attributes branch October 22, 2026 12:31

This branch was successfully deployed

1 active deployment
github-app-auth — 4505e795 Deployed Oct 22, 2026 by eavanvalkenburg via add_label #25909
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants