Skip to content

Commit

Permalink
fix guzzle hook class (#310)
Browse files Browse the repository at this point in the history
Guzzle auto-instrumentation is incorrectly hooking ClientInterface::transfer when the actual method is Client::transfer. There
has never been a ClientInterface::transfer in guzzle...
It current works, probably more by accident than design, since the extension will still run a hook method against an
implementing class even if the method is not defined in the interface.
  • Loading branch information
brettmc authored Oct 23, 2024
1 parent d303b87 commit c44eee5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/GuzzleInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenTelemetry\Contrib\Instrumentation\Guzzle;

use function get_cfg_var;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Promise\PromiseInterface;
use OpenTelemetry\API\Globals;
use OpenTelemetry\API\Instrumentation\CachedInstrumentation;
Expand Down Expand Up @@ -35,9 +35,9 @@ public static function register(): void
);

hook(
ClientInterface::class,
Client::class,
'transfer',
pre: static function (ClientInterface $client, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($instrumentation): array {
pre: static function (Client $client, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($instrumentation): array {
$request = $params[0];
assert($request instanceof RequestInterface);

Expand Down Expand Up @@ -84,7 +84,7 @@ public static function register(): void

return [$request];
},
post: static function (ClientInterface $client, array $params, PromiseInterface $promise, ?Throwable $exception): void {
post: static function (Client $client, array $params, PromiseInterface $promise, ?Throwable $exception): void {
$scope = Context::storage()->scope();
$scope?->detach();

Expand Down

0 comments on commit c44eee5

Please sign in to comment.