PHPackages                             shadowbane/laravel-datadog-logger - 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. shadowbane/laravel-datadog-logger

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

shadowbane/laravel-datadog-logger
=================================

Custom laravel monolog logger for datadog logs management, both api and agent ways

v1.2.0(7mo ago)05.2k↓32.5%2MITPHPPHP ^8.1 || ^8.2 || ^8.3 || ^8.4

Since Jul 19Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/shadowbane/laravel-datadog-logger)[ Packagist](https://packagist.org/packages/shadowbane/laravel-datadog-logger)[ Docs](https://github.com/shadowbane/laravel-datadog-logger)[ RSS](/packages/shadowbane-laravel-datadog-logger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (10)Used By (0)

Laravel DataDog Logger
======================

[](#laravel-datadog-logger)

A custom Laravel Monolog logger for sending logs to DataDog via their HTTP API.

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

Features
--------

[](#features)

- Send Laravel logs directly to DataDog via HTTP API
- Automatic exception tracking with stack traces
- Custom log context support
- Configurable log levels and endpoints
- Error reporting for failed API requests
- Environment-based tagging

Requirements
------------

[](#requirements)

- PHP ^8.1 || ^8.2 || ^8.3 || ^8.4
- Laravel 10.x or higher
- ext-json
- ext-curl
- Guzzle ^6.0 || ^7.0
- Monolog ^3.0

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

[](#installation)

Install the package via Composer:

```
composer require shadowbane/laravel-datadog-logger
```

The service provider will be automatically registered.

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

[](#configuration)

### Environment Variables

[](#environment-variables)

Add the following to your `.env` file:

```
DATADOG_API_KEY=your-datadog-api-key
DATADOG_LEVEL=warning
DATADOG_BUBBLE=true
DATADOG_ENVIRONMENT=production
DATADOG_API_ENDPOINT=https://http-intake.logs.datadoghq.com/api/v2/logs
DATADOG_ERROR_LOG_CHANNEL=stack
```

#### Configuration Options

[](#configuration-options)

VariableDescriptionDefault`DATADOG_API_KEY`Your DataDog API key (required)-`DATADOG_LEVEL`Minimum log level (debug, info, notice, warning, error, critical, alert, emergency)`warning``DATADOG_BUBBLE`Whether logs should bubble to other handlers`true``DATADOG_ENVIRONMENT`Environment tag for DataDogLaravel's `app()->environment()``DATADOG_API_ENDPOINT`DataDog logs API endpoint`https://http-intake.logs.datadoghq.com/api/v2/logs``DATADOG_ERROR_LOG_CHANNEL`Laravel log channel for logging DataDog API failures`false`### Laravel Logging Configuration

[](#laravel-logging-configuration)

The package automatically merges the `datadog-api` channel into your logging configuration. You can use it in your `config/logging.php`:

```
'channels' => [
    'stack' => [
        'driver' => 'stack',
        'channels' => ['single', 'datadog-api'],
    ],
]
```

Usage
-----

[](#usage)

### Basic Logging

[](#basic-logging)

Use the `datadog-api` channel to send logs to DataDog:

```
use Illuminate\Support\Facades\Log;

Log::channel('datadog-api')->info('User logged in', [
    'user_id' => 123,
    'ip_address' => '192.168.1.1',
]);

Log::channel('datadog-api')->error('Payment failed', [
    'order_id' => 456,
    'amount' => 99.99,
]);
```

### Exception Logging

[](#exception-logging)

When logging exceptions, pass the exception in the context array with the key `exception`:

```
try {
    // Your code
} catch (\Exception $e) {
    Log::channel('datadog-api')->error('Failed to create company: ' . $e->getMessage(), [
        'exception' => $e,
        'company_id' => 123,
        'user_id' => 456,
    ]);
}
```

The logger will automatically extract:

- Exception class name (becomes the message)
- Error code (`error.kind`)
- Error message (`error.message`)
- Stack trace (`error.stack`)

### Log Context

[](#log-context)

All context data (except `exception`, `message`, and `messages`) is sent to DataDog as custom attributes:

```
Log::channel('datadog-api')->warning('High memory usage', [
    'memory_used' => '512MB',
    'memory_limit' => '256MB',
    'server' => 'web-01',
]);
```

This will create a log in DataDog with custom attributes: `memory_used`, `memory_limit`, and `server`.

### Testing

[](#testing)

Test your DataDog integration using the included Artisan command:

```
php artisan datadog:send-test-exception
```

This command sends a test exception to DataDog with sample context data.

Log Level Mapping
-----------------

[](#log-level-mapping)

Laravel log levels are mapped to DataDog status levels:

Laravel LevelDataDog Statusdebug, infoinfonotice, warningwarnerror, critical, alert, emergencyerrorError Handling
--------------

[](#error-handling)

If the DataDog API request fails, you can configure a fallback Laravel log channel to capture these errors:

```
DATADOG_ERROR_LOG_CHANNEL=stack
```

Failed API requests will be logged to this channel with the Guzzle exception details.

DataDog Log Structure
---------------------

[](#datadog-log-structure)

Logs sent to DataDog include the following fields:

- `ddsource`: Always set to `laravel`
- `ddtags`: Environment tag (e.g., `env:production`)
- `hostname`: Server hostname
- `message`: Formatted log message (or exception class name)
- `service`: Your Laravel application name (from `config('app.name')`)
- `status`: Mapped log level (info, warn, error)
- `timestamp`: Log timestamp in milliseconds
- Custom attributes from log context

For exceptions:

- `error.kind`: Exception code
- `error.message`: Exception message
- `error.stack`: Exception stack trace

Development
-----------

[](#development)

### Static Analysis

[](#static-analysis)

Run PHPStan for static analysis:

```
vendor/bin/phpstan analyze
```

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

Credits
-------

[](#credits)

- [Shadowbane](https://github.com/shadowbane)

Support
-------

[](#support)

If you discover any issues, please open an issue on the [GitHub repository](https://github.com/shadowbane/laravel-datadog-logger/issues).

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance63

Regular maintenance activity

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity71

Established project with proven stability

 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 ~147 days

Recently: every ~292 days

Total

9

Last Release

223d ago

Major Versions

v0.2.3 → v1.02023-05-29

PHP version history (4 changes)v0.1PHP ^7.4 || ^8.0 || ^8.1

v1.0PHP ^8.1 || ^8.2

v1.1.0PHP ^8.1 || ^8.2 || ^8.3

v1.2.0PHP ^8.1 || ^8.2 || ^8.3 || ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6396154?v=4)[Shadowbane](/maintainers/shadowbane)[@shadowbane](https://github.com/shadowbane)

---

Top Contributors

[![shadowbane](https://avatars.githubusercontent.com/u/6396154?v=4)](https://github.com/shadowbane "shadowbane (15 commits)")

---

Tags

logphpformatterapilaravelDataDoghandlerAgentloggermanagementmonologdatadogagentdatadoglogdatadog-logger

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/shadowbane-laravel-datadog-logger/health.svg)

```
[![Health](https://phpackages.com/badges/shadowbane-laravel-datadog-logger/health.svg)](https://phpackages.com/packages/shadowbane-laravel-datadog-logger)
```

###  Alternatives

[logtail/monolog-logtail

Logtail handler for Monolog

233.2M3](/packages/logtail-monolog-logtail)[yzen.dev/mono-processor

This Processor will display in the logs bread crumbs by which you can more quickly and accurately identify the cause of the error.

116.1k](/packages/yzendev-mono-processor)

PHPackages © 2026

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