robbiekibler/laravel-posthog-logs
Composer 安装命令:
composer require robbiekibler/laravel-posthog-logs
包简介
Send Laravel logs to PostHog using OpenTelemetry OTLP format
README 文档
README
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.
Installation
Install the package via Composer:
composer require robbiekibler/laravel-posthog-logs
Configuration
Quick Start
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'], ],
Environment Variables
| 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 |
Publishing Config (Optional)
To customize all options, publish the config file:
php artisan vendor:publish --tag="posthog-logs-config"
Testing Your Configuration
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!"
Usage
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, ]);
Trace Correlation
If you're using distributed tracing, you can include trace context:
Log::info('Processing request', [ 'trace_id' => $traceId, 'span_id' => $spanId, 'user_id' => $userId, ]);
Log Levels
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) |
Viewing Logs in PostHog
- Go to your PostHog dashboard
- Navigate to Logs in the sidebar
- Filter by service name, environment, or log level
- Click on individual logs to see full context and attributes
Advanced Configuration
Channel-Level Overrides
Override settings per channel in config/logging.php:
'posthog' => [ 'driver' => 'posthog', 'level' => 'warning', // Only send warnings and above 'service_name' => 'my-api', 'environment' => 'staging', ],
Custom Resource Attributes
Add custom attributes to all logs via config:
// config/posthog-logs.php 'resource_attributes' => [ 'team.name' => 'backend', 'version' => '1.3.0', ],
Disable in Tests
# .env.testing POSTHOG_LOGS_ENABLED=false
Performance Considerations
Logs are sent to PostHog via synchronous HTTP requests. The package includes:
- Batching: Logs are batched (default: 100 per batch) to reduce HTTP overhead
- Timeouts: Short timeouts (5s request, 2s connect) to prevent blocking
- Retries: Automatic retry with exponential backoff for transient failures
- Overflow Protection: Oldest logs are dropped if the batch overflows due to send failures
For high-throughput applications, consider:
- Using a log stack with a fast local channel (e.g.,
single) as primary - Adjusting batch size via
POSTHOG_BATCH_MAX_SIZE - Setting a higher minimum log level in production via
POSTHOG_LOG_LEVEL
Testing
composer test
Changelog
Please see CHANGELOG for recent changes.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
robbiekibler/laravel-posthog-logs 适用场景与选型建议
robbiekibler/laravel-posthog-logs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 347 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「laravel」 「logs」 「posthog」 「observability」 「opentelemetry」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 robbiekibler/laravel-posthog-logs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 robbiekibler/laravel-posthog-logs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 robbiekibler/laravel-posthog-logs 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The tenancy/tenancy logs mutations
A Zend Framework module that sets up Monolog for logging in applications.
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
统计信息
- 总下载量: 347
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-03