Skip to content

Python: Keep tool arguments off invocation metrics - #9361

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
mainfrom
fix-metric-attribute-leak
Oct 14, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
mainfrom
fix-metric-attribute-leak

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation & Context

A report in an email thread identified that gen_ai.tool.call.arguments was being attached to the agent_framework.function.invocation.duration metric for Foundry-hosted Agent Framework agents. This exposed serialized tool inputs, including calculator expressions and complete questions passed to specialist agents, as metric dimensions even though the attribute is intended for tool-execution spans.

The metric and span shared the same mutable attribute dictionary, allowing span-only payload attributes to flow into the histogram recording.

Description & Review Guide

  • What are the major changes? Function invocation spans and duration metrics now use separate attribute dictionaries. The metric snapshot is created before sensitive span attributes are added, and failure classification is propagated explicitly. Regression coverage verifies that calculator-expression payloads remain on eligible spans but never reach histogram attributes.
  • What is the impact of these changes? Tool arguments and results remain available on tool-execution spans when sensitive telemetry and the applicable semantic conventions are enabled, while function-duration metrics no longer contain those payloads. Existing non-sensitive metric dimensions and error.type behavior are preserved.
  • What do you want reviewers to focus on? Please verify the attribute lifecycle around successful and failed invocations, particularly that metric attributes remain detached from later span enrichment.

Related Issue

N/A - trivial change. This was reported through an email thread rather than a GitHub issue; keeping span-only tool argument payloads off a duration metric is an obvious telemetry correction. No competing open PR was found.

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 the implementation, regression tests, and 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.

🟢 Approval recommended

The attribute separation is correct and regression coverage validates both successful and failed invocations.

0 open findings

What changed in this PR

Separates tool-span attributes from invocation-metric attributes to prevent sensitive tool payloads leaking into metric dimensions.

Changes:

  • Creates independent span and metric attribute dictionaries.
  • Preserves metric error classification.
  • Adds success and failure regression coverage.
File Description
python/​packages/​core/​agent_framework/​_tools.py Detaches metric attributes before span enrichment.
python/​packages/​core/​tests/​core/​test_tools.py Verifies arguments and results remain absent from metrics.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@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)): 3c6058ecc884
Model: gpt-5.6-sol

Overview

The change takes a detached metric-attribute snapshot before enriching the function span with sensitive tool arguments, while continuing to write tool results directly to the span. Explicit error propagation preserves error.type on failed-invocation metrics, and the updated tests cover successful and failed calls while asserting that payloads stay off histogram attributes. No publishable Critical, High, or Medium regression 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.

@github-code-quality

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: Python

Python / code-coverage/python

The overall line coverage in commit 3c6058e in the fix-metric-attribute... branch remains at 92%, unchanged from commit ec47b90 in the main branch.

This branch was previously deployed

1 inactive deployment
github-app-auth — 3c6058ec Deployed Oct 14, 2026 by eavanvalkenburg via team_check #6729
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