Skip to content

fix(telemetry): remove force_flush in tracer#2142

Merged
poshinchen merged 1 commit intostrands-agents:mainfrom
poshinchen:fix/remove-force-flush
Apr 17, 2026
Merged

fix(telemetry): remove force_flush in tracer#2142
poshinchen merged 1 commit intostrands-agents:mainfrom
poshinchen:fix/remove-force-flush

Conversation

@poshinchen
Copy link
Copy Markdown
Contributor

Description

Remove force_flush in tracer.

Tracer._end_span() calls tracer_provider.force_flush() synchronously after every span end. When the OTLP endpoint is unreachable, the exporter retries 6x with exponential backoff, blocking the calling thread. Multiple spans end per invocation (agent, event loop, model invoke, tool calls), so it compounds to ~90s total.

Related Issues

#2138

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
Copy Markdown

codecov bot commented Apr 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread src/strands/telemetry/tracer.py
@github-actions
Copy link
Copy Markdown

Assessment: Approve

Clean, well-scoped bug fix that removes a synchronous force_flush() call from _end_span() which blocked the calling thread for ~90s when the OTLP endpoint was unreachable. The BatchSpanProcessor already exports spans asynchronously on a configurable schedule, and TracerProvider registers an atexit handler (via shutdown_on_exit=True default) that drains pending spans on process exit — so the per-span flush was both unnecessary and harmful.

Verification Notes
  • Confirmed TracerProvider.__init__ registers atexit.register(self.shutdown) by default
  • Confirmed shutdown() calls through to BatchProcessor.shutdown() which joins the worker thread and flushes remaining spans
  • No remaining force_flush references in production code (src/)
  • Test removal is appropriate — only the test for the deleted error-handling path was removed

No concerns with this change. 👍

@poshinchen poshinchen merged commit 4e3ad44 into strands-agents:main Apr 17, 2026
21 checks passed
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.

2 participants