Events & logging
Every request the client sends to Google dispatches exactly one lifecycle event you can listen to for logging, metrics or alerting: PlacesResponseReceived for an answer, PlacesRequestFailed for an error or an unreachable API. Neither event carries the API key:
use RoundlyConsulting\GooglePlaces\Events\PlacesRequestFailed;
use RoundlyConsulting\GooglePlaces\Events\PlacesResponseReceived;
// PlacesResponseReceived: endpoint, httpStatus, googleStatus, durationMs
// PlacesRequestFailed: endpoint, httpStatus, googleStatus, message| Event | Properties | Dispatched |
|---|---|---|
PlacesResponseReceived | endpoint, httpStatus, googleStatus, durationMs | After every answered call — including a details 404 and a geocoding ZERO_RESULTS. |
PlacesRequestFailed | endpoint, httpStatus, googleStatus, message | When Google returns an error or cannot be reached; httpStatus is 0 for a connection failure. |
endpoint is one of details, autocomplete, textSearch (also for findPlace() and each paginated page), nearbySearch, geocode, geocodeAddress, distance, computeMatrix, photoUri or photoContents (also for photo()->url(), contents() and save()). googleStatus is Google’s own status string when the response carries one; a failure’s message is redacted. A call that sends nothing dispatches nothing: a cache hit, photoUrl() (built locally), and a call refused before sending — no key configured, or a client-side rate-limit fail-fast (RateLimitExceededException). check() reports through its return value instead, so its probes dispatch no events either.
Listening
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use RoundlyConsulting\GooglePlaces\Events\PlacesRequestFailed;
use RoundlyConsulting\GooglePlaces\Events\PlacesResponseReceived;
// e.g. in AppServiceProvider::boot()
Event::listen(function (PlacesResponseReceived $event): void {
if ($event->durationMs > 2000) {
Log::warning('Slow Google call', ['endpoint' => $event->endpoint, 'ms' => $event->durationMs]);
}
});
Event::listen(function (PlacesRequestFailed $event): void {
if ($event->googleStatus === 'PERMISSION_DENIED') {
Log::critical('Google API key rejected', ['endpoint' => $event->endpoint, 'message' => $event->message]);
}
});Request logging
Opt-in logging of every request is built on the same events. Responses are logged at info level, failures at warning level, with endpoint, HTTP status, Google status and duration or message. The API key is never logged — a failure’s message is redacted as described under Error handling:
GOOGLE_PLACES_LOGGING=true
GOOGLE_PLACES_LOG_CHANNEL=stack # optional; defaults to the app's default channelLaravel’s own HTTP client events, and tools that record them such as Telescope, see each request as sent — a Geocoding request URL includes the key. That recording happens in your app, outside this package; filter it there.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.