PHPackages                             chaseconey/laravel-datadog-helper - 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. chaseconey/laravel-datadog-helper

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

chaseconey/laravel-datadog-helper
=================================

A Laravel Datadog helper package.

1.3.0(9mo ago)742.3M↑11.1%22MITPHPPHP &gt;=5.4.0CI failing

Since Aug 2Pushed 9mo ago2 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (14)Used By (0)

laravel-datadog-helper
======================

[](#laravel-datadog-helper)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d69312e9ea76b6d3f7f48434f3f1af32b1097f77f3c147151836923523f204e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368617365636f6e65792f6c61726176656c2d64617461646f672d68656c7065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chaseconey/laravel-datadog-helper)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/66b7bcfe0f37b654d37fd563d670bc6b4c899923c08250f6409e988a304fbe16/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6368617365636f6e65792f6c61726176656c2d64617461646f672d68656c7065722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/chaseconey/laravel-datadog-helper)[![Coverage Status](https://camo.githubusercontent.com/2167fb0614de6d52f006755681de9cc70b6a57c56642bd6dcafe01e060849576/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6368617365636f6e65792f6c61726176656c2d64617461646f672d68656c7065722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/chaseconey/laravel-datadog-helper/code-structure)[![Quality Score](https://camo.githubusercontent.com/71efd53b5f4405d8ae1ee9b18ee0f96fc513081f7a46a19f277fe85ef459550f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6368617365636f6e65792f6c61726176656c2d64617461646f672d68656c7065722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/chaseconey/laravel-datadog-helper)[![Total Downloads](https://camo.githubusercontent.com/59437ca6c68a25eb8e07299da28d713a207aba17b8a21db3c32170d51d383b41/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6368617365636f6e65792f6c61726176656c2d64617461646f672d68656c7065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chaseconey/laravel-datadog-helper)[![StyleCI](https://camo.githubusercontent.com/5675c3f8a62c0fd0b626fbf9b174d8e2b84facef621287179872649ca742f586/68747470733a2f2f7374796c6563692e696f2f7265706f732f36343736333839352f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/64763895)

Laravel Datadog Helper helps you get your application metrics integrated into Laravel as fast as possible.

### Requirements

[](#requirements)

- Laravel &gt;= 5
- Datadog API Key

### Features

[](#features)

- Adds Datadog facade that wraps the official [DataDog/php-datadogstatsd](https://github.com/DataDog/php-datadogstatsd) library
- Provides middleware for tracking response time metrics automatically
- Allows prefixing all metrics that are sent for the whole application with common prefix

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

[](#installation)

Require this package with composer.

```
composer require chaseconey/laravel-datadog-helper
```

Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

If you would like to install the request metric tracking middleware, add the Datadog middleware class like so:

```
// app/Http/Kernel.php

protected $middleware = [
    ...

    \ChaseConey\LaravelDatadogHelper\Middleware\LaravelDatadogMiddleware::class
];
```

### Without Auto-Discovery (or Laravel &lt; 5.5)

[](#without-auto-discovery-or-laravel--55)

If you don't use auto-discovery, or you are using an older version of Laravel, add the ServiceProvider to the providers array in `config/app.php`

```
// config/app.php

'providers' => [
    ...

    ChaseConey\LaravelDatadogHelper\LaravelDatadogHelperServiceProvider::class,
];
```

If you want to use the facade, add this to your facades in `config/app.php`:

```
// config/app.php

'aliases' => [
    ...

    'Datadog' => ChaseConey\LaravelDatadogHelper\Datadog::class
];
```

For configuration options, copy the package config to your local config with the publish command:

```
php artisan vendor:publish --provider="ChaseConey\LaravelDatadogHelper\LaravelDatadogHelperServiceProvider"
```

Middleware
----------

[](#middleware)

This package comes with a handy middleware that you can add to any Laravel project to get up and running in Datadog as fast as possible.

- **Metric Name:** `request_time`
- **Value:** The time it takes Laravel to respond to request
- **Tags:**:
    - `status_code`
    - `url` (toggle via `datadog.middleware_disable_url_tag` config option)
    - *any custom tags you have added to `datadog.global_tags`*

With just these metrics here are a couple of example graphs that you can make:

[![](datadog-screen.png?raw=true)](datadog-screen.png?raw=true)

Datadog Graph Config JSON#### Max Request Time by URL

[](#max-request-time-by-url)

```
{
  "viz": "heatmap",
  "requests": [
    {
      "q": "max:app.example.request_time.max{*} by {url}",
      "type": null,
      "style": {
        "palette": "dog_classic",
        "type": "solid",
        "width": "normal"
      },
      "aggregator": "avg",
      "conditional_formats": []
    }
  ],
  "autoscale": true
}
```

#### Top Pages Hit

[](#top-pages-hit)

```
{
  "viz": "toplist",
  "requests": [
    {
      "q": "top(sum:app.example.request_time.count{*} by {url}.as_count(), 10, 'sum', 'desc')",
      "type": null,
      "style": {
        "palette": "warm",
        "type": "solid",
        "width": "normal"
      },
      "conditional_formats": []
    }
  ]
}
```

#### Slowest Endpoints/Pages

[](#slowest-endpointspages)

```
{
  "viz": "toplist",
  "requests": [
    {
      "q": "top(max:app.example.request_time.max{*} by {url}, 10, 'max', 'desc')",
      "type": null,
      "style": {
        "palette": "dog_classic",
        "type": "solid",
        "width": "normal"
      },
      "conditional_formats": [
        {
          "palette": "white_on_red",
          "value": 5,
          "comparator": ">"
        },
        {
          "palette": "white_on_green",
          "value": 5,
          "comparator": "
