Fix execute_tool span kind#274
Conversation
execute_tool runs in-process, so its span must be INTERNAL, not CLIENT. ToolInvocation was inheriting the CLIENT default from GenAIInvocation. Also add a rego live-check rule (genai_span_kind_unexpected) that pins the expected span kind per gen_ai.operation.name, which surfaces this class of bug.
There was a problem hiding this comment.
Pull request overview
This PR corrects the span kind for execute_tool in opentelemetry-util-genai (tool execution is in-process, so spans should be INTERNAL rather than CLIENT) and adds a Weaver live-check policy rule to enforce per-operation span kind expectations.
Changes:
- Emit
execute_toolspans withSpanKind.INTERNAL. - Add a unit test asserting tool spans are
INTERNAL. - Add a Rego live-check rule (
genai_span_kind_unexpected) that validates span kind againstgen_ai.operation.name.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| util/opentelemetry-util-genai/tests/test_toolcall.py | Adds a test to ensure tool spans are created with SpanKind.INTERNAL. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/_tool_invocation.py | Sets span_kind=SpanKind.INTERNAL when creating ToolInvocation spans. |
| util/opentelemetry-util-genai/.changelog/+tool-span-internal-kind.fixed | Adds a changelog fragment describing the user-visible fix (but filename does not meet CI requirements). |
| policies/genai_span_validation.rego | Adds a policy rule to flag spans whose kind doesn’t match semconv expectations for the operation (with a sort() typing concern). |
|
This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome. For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question. Automation flags a PR for human review once every review thread has a reply or is marked as resolved. Status across open PRs is visible on the pull request dashboard. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Renames the changelog fragment to 274.fixed to satisfy the changelog CI check, and sorts imports in test_toolcall.py to fix the ruff lint gate. Assisted-by: Claude Opus 4.8
execute_tool is INTERNAL, not CLIENT.
Also add a rego live-check rule (genai_span_kind_unexpected) that pins the expected span kind per gen_ai.operation.name, which surfaces this class of bug.