Skip to content

Wire the SDK client to the application's HTTP client - #47

Merged
loevgaard merged 1 commit into
masterfrom
fix/26-http-client-wiring
Sep 7, 2026
Merged

Wire the SDK client to the application's HTTP client#47
loevgaard merged 1 commit into
masterfrom
fix/26-http-client-wiring

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Fixes #26

Stacked on #46.

Problem

The SDK Client was registered with only a setLogger() call, leaving the HTTP client, request factory and stream factory to php-http/discovery at runtime. That meant requests to Meta never appeared in the profiler's HttpClient panel, ignored any timeout, proxy, retry or scoped client configuration, could not be replaced by a MockHttpClient in tests, and depended on whichever PSR-18 implementation happened to be installed first.

Change

The Client definition now calls setHttpClient(), setRequestFactory() and setStreamFactory(), each with on-invalid="ignore". Symfony drops a method call whose argument cannot be resolved, so an application missing any of those services simply keeps the old discovery behaviour. Verified: in the test kernel psr18.http_client exists and the call survives, while the two PSR-17 factory services do not exist and those calls are removed.

New http_client option (default psr18.http_client) points the bundle at a different PSR-18 service, which is how you give Meta its own timeout. README.md shows the scoped client setup.

The client also joins the setono_meta_conversions_api Monolog channel.

Tests

  • An end-to-end integration test replaces psr18.http_client with a Psr18Client wrapping a MockHttpClient, sends an event through the container's ClientInterface, and asserts the request was POST https://graph.facebook.com/v26.0/1234/events. That assertion only holds because the client is wired rather than discovered.
  • A second test points http_client at a service that does not exist and asserts the container still boots.
  • The mock is built by a factory (RecordingHttpClientFactory) because a container definition cannot hold a live object.

@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.00%. Comparing base (919b3dd) to head (2a07fca).

Additional details and impacted files
@@                       Coverage Diff                       @@
##             fix/25-log-dropped-events      #47      +/-   ##
===============================================================
+ Coverage                        76.70%   77.00%   +0.30%     
  Complexity                         139      139              
===============================================================
  Files                               30       30              
  Lines                              455      461       +6     
===============================================================
+ Hits                               349      355       +6     
  Misses                             106      106              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@loevgaard
loevgaard force-pushed the fix/25-log-dropped-events branch from a0c147e to 324e9e7 Compare September 7, 2026 12:03
@loevgaard
loevgaard force-pushed the fix/26-http-client-wiring branch from 155836b to 7d0d09e Compare September 7, 2026 12:03
@loevgaard
loevgaard force-pushed the fix/25-log-dropped-events branch from 324e9e7 to 1ed2b29 Compare September 7, 2026 12:18
@loevgaard
loevgaard force-pushed the fix/26-http-client-wiring branch from 7d0d09e to 88c612e Compare September 7, 2026 12:18
@loevgaard
loevgaard force-pushed the fix/25-log-dropped-events branch from 1ed2b29 to 37e9af9 Compare September 7, 2026 12:46
@loevgaard
loevgaard force-pushed the fix/26-http-client-wiring branch from 88c612e to 632c3c2 Compare September 7, 2026 12:46
The client left the PSR-18 client and PSR-17 factories to runtime
discovery, so requests to Meta never showed up in the profiler, ignored
configured timeouts and could not be mocked in tests.

Wire the application's services with on-invalid="ignore" so a missing
service falls back to discovery, and add an http_client option for
pointing Meta at a scoped client.

Fixes #26
@loevgaard
loevgaard force-pushed the fix/25-log-dropped-events branch from 37e9af9 to 919b3dd Compare September 7, 2026 12:51
@loevgaard
loevgaard force-pushed the fix/26-http-client-wiring branch from 632c3c2 to 2a07fca Compare September 7, 2026 12:51
Base automatically changed from fix/25-log-dropped-events to master September 7, 2026 12:54
@loevgaard
loevgaard merged commit 0a85008 into master Sep 7, 2026
47 checks passed
@loevgaard
loevgaard deleted the fix/26-http-client-wiring branch September 7, 2026 12:54
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.

Wire the SDK client to the application's PSR-18 client and PSR-17 factories

1 participant