Skip to content

Conversation

@lucas-angeli-gimenes
Copy link
Collaborator

Description

The OtlpHttpTransportFactory [1] uses the PsrTransportFactory [2] which in turn uses Discovery[3] to obtain a functional instance of ClientInterface to emit data via HTTP. Therefore, to inject the Guzzle\Client with the CoroutineHandler, it was necessary to inject HyperfGuzzle as a possible discovery.

Why not use Listeners, for example: BootApplication?
The TracerProviderFactory is executed during the reading of dependencies (dependencies.php) which is read before any event is emitted. Therefore, it is necessary to register the Discovery before this stage.

If the pool configuration is defined within the open-telemetry.php file, the PoolHandler will be used; otherwise, the CoroutineHandler will be used. Example:

return [
/* traces, metrics, logs **/
   'otlp_http' => [
        'pool' => [
            'min_connections' => 3,
            'max_connections' => 30,
            'connect_timeout' => 0.1,
            'wait_timeout' => 0.1,
        ],
    ]
 ];

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 January 30, 2026 12:30
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 introduces support for using CoroutineHandler instead of CurlHandler for the OpenTelemetry HTTP exporter in Hyperf applications. It implements a custom discovery mechanism (HyperfGuzzle) that provides coroutine-aware HTTP clients optimized for Swoole environments, with optional connection pooling support.

Changes:

  • Adds HyperfGuzzle class implementing DiscoveryInterface to provide coroutine-aware Guzzle clients
  • Registers HyperfGuzzle as the primary HTTP client discoverer in ConfigProvider
  • Adds comprehensive unit tests for the HyperfGuzzle implementation

Reviewed changes

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

File Description
src/Support/HyperfGuzzle.php Implements DiscoveryInterface to provide Guzzle clients with CoroutineHandler or PoolHandler based on configuration
src/ConfigProvider.php Registers HyperfGuzzle as the primary client discoverer before the default Guzzle discoverer
tests/Unit/Support/HyperfGuzzleTest.php Adds unit tests covering available(), create(), and handler selection logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +30 to +33
Discovery::setDiscoverers([
HyperfGuzzle::class,
Guzzle::class,
]);
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The new 'otlp_http.pool' configuration option is not documented in the published configuration file. Based on the PR description, this configuration is essential for users who want to use PoolHandler instead of CoroutineHandler. Consider adding a commented example in the configuration file to help users understand this feature. The PR description mentions that pool configuration can be defined within the 'open-telemetry.php' file, but the published config template (publish/open-telemetry.php) doesn't include this section.

Copilot uses AI. Check for mistakes.

private function createHandler(): HandlerStack
{
/** @var ContainerInterface $container */
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

Missing import for ContainerInterface. The PHPDoc annotation uses ContainerInterface but the corresponding use statement is not present. Based on the codebase conventions (see src/Factory/OTelResourceFactory.php:8, src/Factory/Trace/TracerProviderFactory.php:8), this should be 'Hyperf\Contract\ContainerInterface'.

Copilot uses AI. Check for mistakes.
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use ReflectionAttribute;
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The ReflectionAttribute import is unused and should be removed to keep the imports clean.

Suggested change
use ReflectionAttribute;

Copilot uses AI. Check for mistakes.
use GuzzleHttp\HandlerStack;
use Hyperf\Context\ApplicationContext;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Guzzle\ClientFactory;
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The ClientFactory import is unused and should be removed to keep the imports clean.

Suggested change
use Hyperf\Guzzle\ClientFactory;

Copilot uses AI. Check for mistakes.
@lucas-angeli-gimenes lucas-angeli-gimenes merged commit 337c9dd into main Feb 3, 2026
@lucas-angeli-gimenes lucas-angeli-gimenes deleted the hyperf-guzzle branch February 3, 2026 19:55
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.

4 participants