Skip to content

Conversation

@fainohub
Copy link
Collaborator

@fainohub fainohub commented Oct 9, 2025

Description

Context

Synchronous flushing of traces/metrics at the end of a request (auto-flush) was adding latency and, in some cases, causing races with spans that finish right at the tail end of the coroutine. In Hyperf/Swoole environments, the hot path must remain non-blocking.

What changed

  • Removed: auto_flush from the BatchSpanProcessor (traces) and any implicit flush in the hot path.
  • Added: Listeners that call forceFlush() periodically inside dedicated coroutines (via Coordinator\Timer), keeping the request flow non-blocking.
  • Ticker start: BeforeWorkerStart (web) and BeforeHandle (CLI).
  • Ticker stop: AfterHandle (CLI) and WORKER_EXIT (web).
  • Anti-reentrancy: Simple lock to prevent concurrent forceFlush() between ticks.
  • Shared abstraction: AbstractFlushListener centralizes lifecycle (start/stop/lock/logs); TraceFlushListener and MetricFlushListener only implement flush() and the interval.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Performance/Refactor
  • CI/CD/Chore

Checklist

  • Title follows Conventional Commits (e.g., feat: add SQS aspect)
  • Tests added/updated
  • composer test passes locally
  • Documentation updated (README/Docs)
  • No breaking changes (or documented if any)

Copilot AI review requested due to automatic review settings October 9, 2025 01:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR disables automatic tracer flushing in OpenTelemetry configuration and implements manual flush control. The changes prevent automatic batch processor flushing while adding explicit flush handling in the middleware layer.

Key changes:

  • Disables auto flush for batch processors (traces and logs)
  • Adds manual flush control in TraceMiddleware using defer()
  • Refactors TracerProviderFactory to support conditional instantiation based on configuration

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Middleware/TraceMiddleware.php Adds deferred manual flush with error handling
src/Factory/Trace/TracerProviderFactory.php Converts to factory pattern with conditional NoopTracerProvider
src/Factory/Trace/Processor/BatchSpanProcessorFactory.php Disables auto flush and fixes max queue size constant
src/Factory/SDKBuilder.php Updates to use injected TracerProviderInterface
src/Factory/Log/Processor/BatchLogProcessorFactory.php Disables auto flush and fixes max queue size constant
src/ConfigProvider.php Registers TracerProviderInterface binding
publish/open-telemetry.php Updates configuration defaults and environment variable names

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings October 9, 2025 13:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings October 9, 2025 18:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings October 9, 2025 20:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings October 9, 2025 20:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings October 10, 2025 01:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

fainohub and others added 2 commits October 10, 2025 11:24
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings October 10, 2025 14:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings October 10, 2025 14:27
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@fainohub fainohub changed the title Fixed: disable tracer auto flush Fixed: Eliminate tracer auto-flush latency; add periodic flush listener Oct 10, 2025
@fainohub fainohub merged commit 05d2280 into main Oct 13, 2025
@fainohub fainohub deleted the hotfix/otlp-exporter branch October 13, 2025 13:18
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.

2 participants