Skip to content

Fix Http::withTraceable() facade-call TypeError by registering macro on PendingRequest#4

Merged
mjarestad merged 2 commits into
mainfrom
copilot/fix-http-withtraceable-typeerror
Apr 20, 2026
Merged

Fix Http::withTraceable() facade-call TypeError by registering macro on PendingRequest#4
mjarestad merged 2 commits into
mainfrom
copilot/fix-http-withtraceable-typeerror

Conversation

Copilot AI commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Http::withTraceable($model) could throw a TypeError when used directly from the facade because the macro was registered on the HTTP factory and returned the wrong bound $this. This change aligns macro registration with Laravel's forwarding behavior so direct facade usage resolves to PendingRequest correctly.

  • Macro registration scope

    • Moved withTraceable macro registration from Http (Factory) to Illuminate\Http\Client\PendingRequest.
    • Removed the now-unused Http facade import from the service provider.
  • Regression coverage

    • Added an integration test to verify:
      • Http::withTraceable($model)->post(...) does not throw TypeError.
      • The resulting trace persists correct traceable_type / traceable_id.
  • Changelog

    • Added an [Unreleased] > Fixed entry documenting the Http::withTraceable() TypeError fix and the PendingRequest macro registration change.
PendingRequest::macro('withTraceable', function (object $traceable): PendingRequest {
    /** @var PendingRequest $this */
    app(TraceableScope::class)->push($traceable);

    return $this;
});

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Iu5hpN /usr/bin/composer install (http block)
  • https://api.github.com/repos/symfony/polyfill-ctype/zipball/141046a8f9477948ff284fa65be2095baafb94f2
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Iu5hpN /usr/bin/composer install (http block)
  • https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/ad1b7b9092976d6c948b8a187cec9faaea9ec1df
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Iu5hpN /usr/bin/composer install (http block)
  • https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Iu5hpN /usr/bin/composer install (http block)
  • https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6a21eb99c6973357967f6ce3708cd55a6bec6315
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Iu5hpN /usr/bin/composer install (http block)
  • https://api.github.com/repos/symfony/process/zipball/60f19cd3badc8de688421e21e4305eba50f8089a
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Iu5hpN /usr/bin/composer install (http block)
  • https://api.github.com/repos/symfony/string/zipball/114ac57257d75df748eda23dd003878080b8e688
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Iu5hpN /usr/bin/composer install (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Agent task: Fix Http::withTraceable() TypeError
Start by reading wiretap-bug-report.md in the project root — it contains the full bug description, root cause, and suggested fix with rationale.
Steps:
In src/Laravel/WiretapServiceProvider.php (~line 122), change Http::macro(...) to PendingRequest::macro(...). Ensure Illuminate\Http\Client\PendingRequest is imported; remove the Illuminate\Support\Facades\Http import if it's no longer used elsewhere in the file.
Add a regression test in tests/Feature/WiretapIntegrationTest.php (Pest 4 syntax) verifying that Http::withTraceable($model)->post(...) works without throwing a TypeError and that the traceable is attached to the resulting trace.
Update CHANGELOG.md under [Unreleased] with a Fixed entry: Fixed \Http::withTraceable()throwingTypeErrorwhen called directly on the facade by registering the macro onPendingRequestinstead ofFactory.
Run composer lint and composer test — fix any failures before finishing.
Commit with message fix: register withTraceable macro on PendingRequest instead of Factory and push to main.

The user has attached the following files from their workspace:

  • wiretap-bug-report.md

Copilot AI changed the title [WIP] Fix Http::withTraceable() TypeError by updating macro registration Fix Http::withTraceable() facade-call TypeError by registering macro on PendingRequest Apr 20, 2026
Copilot AI requested a review from mjarestad April 20, 2026 09:58
@mjarestad mjarestad marked this pull request as ready for review April 20, 2026 10:02
@mjarestad mjarestad merged commit 07434d9 into main Apr 20, 2026
10 checks passed
@mjarestad mjarestad deleted the copilot/fix-http-withtraceable-typeerror branch April 20, 2026 10:03
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