Skip to content

Conversation

@vamgan
Copy link
Contributor

@vamgan vamgan commented Sep 10, 2025

Description

Tool result messages were incorrectly labeled as 'gen_ai.user.message' in OpenTelemetry traces. This fix adds proper detection of tool results in message content and labels them as 'gen_ai.tool.message' according to OpenTelemetry semantic conventions.

  • Add _get_event_name_for_message() helper method to determine correct event name
  • Update start_model_invoke_span(), start_event_loop_cycle_span(), and start_agent_span() to use the new helper

Related Issues

Fixes #714

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

zastrowm
zastrowm previously approved these changes Sep 15, 2025
- Label messages containing tool results as 'gen_ai.tool.message' regardless of role
- Add OpenTelemetry semantic conventions v1.36.0 reference
- Note that GenAI namespace is experimental
- Add documentation link to semantic conventions
- Convert tests to data-driven parametrized format for better maintainability
- Improve test coverage with comprehensive edge cases including mixed content and multiple tool results
@vamgan vamgan force-pushed the fix/opentelemetry-tool-message-event-type branch from 6c8c6e7 to 84468d2 Compare September 15, 2025 18:32
@dbschmigelski dbschmigelski merged commit 7226025 into strands-agents:main Sep 15, 2025
11 of 12 checks passed
@vamgan vamgan deleted the fix/opentelemetry-tool-message-event-type branch September 15, 2025 20:12
This was referenced Sep 17, 2025
Unshure pushed a commit to Unshure/sdk-python that referenced this pull request Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Tool result show up as user message in traces

3 participants