Send Laravel logs to PostHog using OpenTelemetry OTLP format
robbiekibler/laravel-posthog-logs is a Laravel package for send laravel logs to posthog using opentelemetry otlp format.
It currently has 0 GitHub stars and 738 downloads on Packagist (latest version v1.3.0).
Install it with composer require robbiekibler/laravel-posthog-logs.
Discover more Laravel packages by robbiekibler
or browse all Laravel packages to compare alternatives.
Last updated
Send your Laravel application logs to PostHog using the OpenTelemetry OTLP format. Just add the package, configure your environment variables, and your logs are automatically available in PostHog.
Install the package via Composer:
composer require robbiekibler/laravel-posthog-logs
Add these environment variables to your .env file:
POSTHOG_API_KEY=phc_your_project_api_key
POSTHOG_HOST=us.i.posthog.com
Security Note: Use a project API key (starts with
phc_), not a personal API key. Project API keys have limited scope and are safe for server-side usage.
Then add the posthog channel to your config/logging.php:
'channels' => [
// ... other channels
'posthog' => [
'driver' => 'posthog',
],
],
To use PostHog as your default log channel, or as part of a stack:
// Use PostHog as default
'default' => env('LOG_CHANNEL', 'posthog'),
// Or add to a stack
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'posthog'],
],
| Variable | Description | Default |
|----------|-------------|---------|
| POSTHOG_API_KEY | Your PostHog project API key | (required) |
| POSTHOG_HOST | PostHog host (us.i.posthog.com, eu.i.posthog.com, or self-hosted) | us.i.posthog.com |
| POSTHOG_SERVICE_NAME | Service name for log identification | APP_NAME |
| POSTHOG_ENVIRONMENT | Deployment environment | APP_ENV |
| POSTHOG_LOG_LEVEL | Minimum log level to send | debug |
| POSTHOG_LOGS_ENABLED | Enable/disable sending logs | true |
| POSTHOG_BATCH_ENABLED | Enable batching of logs | true |
| POSTHOG_BATCH_MAX_SIZE | Maximum logs per batch | 100 |
To customize all options, publish the config file:
php artisan vendor:publish --tag="posthog-logs-config"
Verify your setup is working by running the test command:
php artisan posthog:test
This will display your current configuration and send a test log entry to PostHog. You can customize the test message:
php artisan posthog:test --message="Hello from my app!"
Once configured, use Laravel's standard logging:
use Illuminate\Support\Facades\Log;
// Basic logging
Log::info('User logged in');
Log::warning('Rate limit approaching');
Log::error('Payment failed', ['order_id' => 123]);
// With context
Log::channel('posthog')->info('Order created', [
'order_id' => $order->id,
'customer_id' => $customer->id,
'total' => $order->total,
]);
If you're using distributed tracing, you can include trace context:
Log::info('Processing request', [
'trace_id' => $traceId,
'span_id' => $spanId,
'user_id' => $userId,
]);
The package maps Laravel/Monolog log levels to OpenTelemetry severity:
| Laravel Level | OTLP Severity | |---------------|---------------| | debug | DEBUG (5) | | info | INFO (9) | | notice | INFO (10) | | warning | WARN (13) | | error | ERROR (17) | | critical | ERROR (18) | | alert | FATAL (21) | | emergency | FATAL (22) |
Override settings per channel in config/logging.php:
'posthog' => [
'driver' => 'posthog',
'level' => 'warning', // Only send warnings and above
'service_name' => 'my-api',
'environment' => 'staging',
],
Add custom attributes to all logs via config:
// config/posthog-logs.php
'resource_attributes' => [
'team.name' => 'backend',
'version' => '1.3.0',
],
# .env.testing
POSTHOG_LOGS_ENABLED=false
Logs are sent to PostHog via synchronous HTTP requests. The package includes:
For high-throughput applications, consider:
single) as primaryPOSTHOG_BATCH_MAX_SIZEPOSTHOG_LOG_LEVELcomposer test
Please see CHANGELOG for recent changes.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.