- How do I install this package in a Laravel project?
- Add the package via Composer with `composer require datadog/php-datadogstatsd`. Ensure the PHP sockets extension is enabled (`--enable-sockets` at compile time). For Laravel-specific wrappers, consider `laravel-datadog-helper` for tighter integration.
- What Laravel versions does this package support?
- The package itself has no Laravel-specific dependencies, but it works with all modern Laravel versions (8.x, 9.x, 10.x). Test thoroughly on your target version, as it relies on PHP 5.6+ (though PHP 8.x is recommended).
- Can I use this for Laravel queue workers (Horizon/Redis)?
- Yes. The package’s UDP/UDS support is ideal for queue workers, but enable the new error handler (v1.7.1+) to log socket failures. Pair with Laravel’s `retry()` helper for critical metrics to fall back to HTTP if UDP fails.
- How do I handle socket errors in production?
- Configure the error handler in your `config/datadog.php` to emit structured metrics (e.g., `statsd.socket_errors`) and trigger Datadog alerts. For critical paths, extend the handler to retry via the Datadog HTTP API.
- Does this package support namespacing metrics in Laravel?
- Yes. Use the `namespace` config option (e.g., `namespace: 'laravel.app'`) to prefix all metrics. Combine with tags (e.g., `['env:production', 'service:api']`) for granular filtering in Datadog.
- What’s the performance impact of using UDP vs. UDS?
- UDP is faster (~1ms overhead) but unreliable; UDS (Unix Domain Sockets) is slower (~2ms) but more stable for local Datadog Agent setups. Benchmark both in your Laravel environment using `hhrm/benchmark` to choose.
- How do I correlate Datadog metrics with Laravel logs?
- Use the `tags` parameter to include Laravel’s `request_id` or `job_id` (e.g., `['request_id:'.$request->id]`). For queue jobs, log socket errors to Monolog with the job’s UUID for end-to-end tracing.
- What alternatives exist for Laravel Datadog integration?
- For Laravel-specific solutions, consider `laravel-datadog-helper` (wraps this package) or `spatie/laravel-monitoring` for built-in Laravel metrics. For advanced observability, combine this with `datadog/datadog-api-client` for HTTP fallbacks.
- How do I test this package in a Laravel CI pipeline?
- Mock the Datadog Agent using a local UDP listener (e.g., `ncat -ul 8125`) or a test double like `mockery`. Verify metrics with `phpunit` assertions on `DogStatsd`’s `increment()`/`gauge()` methods, ignoring actual network calls.
- Can I buffer metrics for offline Laravel workers?
- Yes. Enable the `buffer` config option to queue metrics in memory (or use Redis via `predis/predis`). Flush buffers on shutdown or when the Agent reconnects, ensuring no data loss during network outages.