- How do I integrate Jaeger tracing into a Laravel application using jonahgeorge/jaeger-client-php?
- Start by installing the package via Composer, then bind the Jaeger tracer to Laravel’s service container using `bind()` in a service provider. Use middleware to inject tracing headers (e.g., `X-B3-TraceId`) into HTTP requests and instrument Laravel’s HTTP client, Eloquent queries, and queues with spans. The package provides helpers for creating spans and propagating context across services.
- Does this package support Laravel’s HTTP client (Http::macro) and Guzzle for outgoing request tracing?
- Yes, you can manually instrument outgoing requests by wrapping `Http::macro` or Guzzle clients with span creation logic. The package’s OpenTracing API allows you to start spans for HTTP calls, log errors, and set tags like `http.method` and `http.url`. For Laravel, consider creating a custom macro or middleware to automate this.
- What Laravel versions and PHP versions are supported by this Jaeger client?
- The package is compatible with PHP 8.0+ and Laravel 8+. While it isn’t Laravel-specific, its OpenTracing API ensures broad compatibility with Laravel’s ecosystem. Test thoroughly in your environment, especially if using older Laravel versions (e.g., 7.x), as some features may require adjustments.
- How do I configure sampling to avoid high overhead in production?
- The package supports both manual and probabilistic sampling. For production, start with a low rate (e.g., 1% or 10%) and adjust based on observability needs. Use the `sampler` option when creating the tracer to configure this. Dynamic sampling (e.g., tracing only errors) can be implemented by checking span tags or context in middleware.
- Can I use this Jaeger client with Laravel Queues or Horizon for async job tracing?
- Yes, instrument Laravel Queues by wrapping job execution in spans. For Horizon, ensure worker processes inherit trace context from the parent request (e.g., via `X-B3-*` headers). Use the package’s `Span` class to log job start/end times, payloads, and exceptions. This helps track async workflows in Jaeger’s UI.
- Are there conflicts with existing Laravel packages like spatie/laravel-activitylog or monolog?
- Potential conflicts may arise if other packages modify HTTP headers or logging behavior. For example, `spatie/laravel-activitylog` might interfere with trace context propagation. Test thoroughly and use middleware to ensure trace headers (e.g., `X-B3-TraceId`) are preserved. Monolog handlers can be configured to exclude trace logs if needed.
- How do I send traces to a remote Jaeger collector or agent?
- Configure the Jaeger client’s transport options when creating the tracer. Use the `UdpTransport` or `HttpTransport` classes to send spans to a Jaeger collector (e.g., `http://jaeger-collector:14268/api/traces`). For production, ensure the collector is deployed and accessible from your Laravel environment. The package supports both UDP and HTTP protocols.
- Is OpenTracing still recommended, or should I migrate to OpenTelemetry (OTel) for Laravel?
- OpenTracing is deprecated in favor of OpenTelemetry, which offers broader language support and vendor neutrality. If your team plans long-term observability, consider migrating to `open-telemetry/php`. However, this package provides a solid foundation for Jaeger tracing today, and you can gradually adopt OTel by leveraging its backward-compatible APIs.
- How do I debug distributed tracing issues across multiple Laravel services?
- Use Jaeger’s UI to correlate traces across services by matching `traceId` and `spanId`. Ensure context propagation is consistent (e.g., `X-B3-TraceId`, `X-B3-SpanId`, `X-B3-Sampled` headers for HTTP). For queues, include trace context in job payloads or use message attributes. If traces are missing, verify middleware or instrumentation points are correctly injecting spans.
- What are the alternatives to jonahgeorge/jaeger-client-php for Laravel tracing?
- For Laravel, consider `open-telemetry/php` (recommended for future-proofing) or `ddtrace/dd-trace-php` for Datadog integration. If sticking with OpenTracing, `opentracing/opentracing-php` is the official API, but you’ll need to implement Jaeger transport separately. For a Laravel-specific wrapper, explore community packages like `laravel-jaeger` or build your own using this client.