Skip to content

Conversation

@poshinchen
Copy link
Contributor

Description

Agentcore with strands sometimes see the warning message of Tried calling _add_event on an ended spanTried calling _add_event on an ended span.

In our current code base, we control the lifecycle of the spans, which sometimes could go wrong. Therefore, this PR makes the change to let OTEL handle the lifecycle in the use_span (end_on_exit=True).

  1. It'll record the exception automatically
  2. It'll end the span automatically when exiting the function

Related Issues

Issue on Agentcore

Documentation PR

N/A

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.

@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

❌ Patch coverage is 91.83673% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/strands/event_loop/event_loop.py 95.45% 1 Missing and 1 partial ⚠️
src/strands/telemetry/tracer.py 60.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@poshinchen poshinchen requested a review from a team December 5, 2025 16:00
@poshinchen poshinchen self-assigned this Dec 5, 2025
@poshinchen poshinchen marked this pull request as ready for review December 5, 2025 16:01
Copy link
Member

@zastrowm zastrowm left a comment

Choose a reason for hiding this comment

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

Agree with the intent of the changes, but have some nit callouts about the docs/code

@poshinchen poshinchen changed the title chore: refactor use_span to be close automatically chore: refactor use_span to be closed automatically Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants