Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Fixed `Http::withTraceable()` throwing `TypeError` when called directly on the facade by registering the macro on `PendingRequest` instead of `Factory`.

## [2.3.1] - 2026-04-19

### Fixed
Expand Down Expand Up @@ -156,4 +159,3 @@ php artisan migrate
[1.2.0]: https://github.com/nordkit/wiretap/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/nordkit/wiretap/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/nordkit/wiretap/releases/tag/v1.0.0

3 changes: 1 addition & 2 deletions src/Laravel/WiretapServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Routing\Route;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\ServiceProvider;
use Nordkit\Wiretap\Contracts\TraceWriter;
use Nordkit\Wiretap\Guzzle\WiretapClient;
Expand Down Expand Up @@ -119,7 +118,7 @@ public function boot(): void
$this->loadMigrationsFrom(__DIR__.'/../../database/migrations');

if ($this->app['config']['wiretap.outbound.laravel_http']) {
Http::macro('withTraceable', function (object $traceable): PendingRequest {
PendingRequest::macro('withTraceable', function (object $traceable): PendingRequest {
/** @var PendingRequest $this */
app(TraceableScope::class)->push($traceable);

Expand Down
38 changes: 38 additions & 0 deletions tests/Feature/WiretapIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
declare(strict_types=1);

use GuzzleHttp\Psr7\Request as GuzzlePsrRequest;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\Events\ConnectionFailed;
use Illuminate\Http\Client\Request as LaravelHttpRequest;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Schema;
use Nordkit\Wiretap\Laravel\Models\Trace;

uses(RefreshDatabase::class);
Expand Down Expand Up @@ -56,3 +58,39 @@
->and($log->response_status)->toBeNull()
->and($log->error_message)->toContain('Could not resolve host');
});

it('supports calling Http::withTraceable() directly on the facade and stores traceable morph keys', function (): void {
Schema::create('outbound_traceables', function ($table): void {
$table->string('id')->primary();
$table->timestamps();
});

$model = new class extends Model
{
public $table = 'outbound_traceables';

public $incrementing = false;

protected $keyType = 'string';

protected $guarded = [];
};

$modelClass = $model::class;
$instance = $modelClass::create(['id' => 'order-1']);

Http::fake([
'github.com/*' => Http::response(['ok' => true], 200),
]);

expect(function () use ($instance): void {
Http::withTraceable($instance)
->post('https://github.com/users', ['name' => 'octocat']);
})->not->toThrow(TypeError::class);

$trace = Trace::query()->first();

expect($trace)->not->toBeNull()
->and($trace->traceable_type)->toBe($modelClass)
->and($trace->traceable_id)->toBe('order-1');
});
Loading