PHPackages                             robbiekibler/laravel-posthog-logs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. robbiekibler/laravel-posthog-logs

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

robbiekibler/laravel-posthog-logs
=================================

Send Laravel logs to PostHog using OpenTelemetry OTLP format

v1.2.0(3mo ago)0218MITPHPPHP ^8.2CI passing

Since Feb 3Pushed 1mo agoCompare

[ Source](https://github.com/robbiekibler/laravel-posthog-logs)[ Packagist](https://packagist.org/packages/robbiekibler/laravel-posthog-logs)[ Docs](https://github.com/robbiekibler/laravel-posthog-logs)[ GitHub Sponsors](https://github.com/:vendor_name)[ RSS](/packages/robbiekibler-laravel-posthog-logs/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (16)Versions (8)Used By (0)

Laravel PostHog Logs
====================

[](#laravel-posthog-logs)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cc4ad392b43390ee229956d2aaceecb459b35972e591c8b32b4184d91de64286/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f626269656b69626c65722f6c61726176656c2d706f7374686f672d6c6f67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/robbiekibler/laravel-posthog-logs)[![GitHub Tests Action Status](https://camo.githubusercontent.com/acc11a6a60438421169b7fbab25425c27f9051284fad5218a6580cf264750232/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726f626269656b69626c65722f6c61726176656c2d706f7374686f672d6c6f67732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/robbiekibler/laravel-posthog-logs/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/116a55d4f62b800a1d7ad266731dd08557ae1a5a1e5c2a502b5bb53f26e07a3f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f626269656b69626c65722f6c61726176656c2d706f7374686f672d6c6f67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/robbiekibler/laravel-posthog-logs)

Send your Laravel application logs to [PostHog](https://posthog.com/docs/logs) using the OpenTelemetry OTLP format. Just add the package, configure your environment variables, and your logs are automatically available in PostHog.

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require robbiekibler/laravel-posthog-logs
```

Configuration
-------------

[](#configuration)

### Quick Start

[](#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

[](#environment-variables)

VariableDescriptionDefault`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)

[](#publishing-config-optional)

To customize all options, publish the config file:

```
php artisan vendor:publish --tag="posthog-logs-config"
```

Testing Your Configuration
--------------------------

[](#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
-----

[](#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

[](#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

[](#log-levels)

The package maps Laravel/Monolog log levels to OpenTelemetry severity:

Laravel LevelOTLP SeveritydebugDEBUG (5)infoINFO (9)noticeINFO (10)warningWARN (13)errorERROR (17)criticalERROR (18)alertFATAL (21)emergencyFATAL (22)Viewing Logs in PostHog
-----------------------

[](#viewing-logs-in-posthog)

1. Go to your PostHog dashboard
2. Navigate to **Logs** in the sidebar
3. Filter by service name, environment, or log level
4. Click on individual logs to see full context and attributes

Advanced Configuration
----------------------

[](#advanced-configuration)

### Channel-Level Overrides

[](#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

[](#custom-resource-attributes)

Add custom attributes to all logs via config:

```
// config/posthog-logs.php
'resource_attributes' => [
    'team.name' => 'backend',
    'version' => '1.2.3',
],
```

### Disable in Tests

[](#disable-in-tests)

```
# .env.testing
POSTHOG_LOGS_ENABLED=false
```

### Performance Considerations

[](#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
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for recent changes.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Robbie Kibler](https://github.com/robbiekibler)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance85

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

105d ago

Major Versions

v0.1.0-beta → v1.0.02026-02-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/805c45ce9e14835ce48aece4e33a046d3038ab0157bcfc62346bd66335813619?d=identicon)[robbiekibler](/maintainers/robbiekibler)

---

Top Contributors

[![robbiekibler](https://avatars.githubusercontent.com/u/7070929?v=4)](https://github.com/robbiekibler "robbiekibler (10 commits)")

---

Tags

laravellogginglogsopentelemetryotlpobservabilityposthog

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/robbiekibler-laravel-posthog-logs/health.svg)

```
[![Health](https://phpackages.com/badges/robbiekibler-laravel-posthog-logs/health.svg)](https://phpackages.com/packages/robbiekibler-laravel-posthog-logs)
```

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

86910.0M83](/packages/spatie-laravel-health)[keepsuit/laravel-opentelemetry

OpenTelemetry integration for laravel

142347.8k](/packages/keepsuit-laravel-opentelemetry)[shaffe/laravel-mail-log-channel

A package to support logging via email in Laravel

1286.2k](/packages/shaffe-laravel-mail-log-channel)[ytake/laravel-fluent-logger

fluent logger for laravel and lumen

63541.6k1](/packages/ytake-laravel-fluent-logger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
