This library makes it simple to integrate Datadog into your laravel project
- PHP >= 7.1
- Laravel Framework ^5.6, ^6.0, ^7.0
The library can be installed using Composer.
Add vcs repository url to the composer.json
:
"repositories": [
{
"type": "vcs",
"url": "git@github.com:airslateinc/laravel-datadog.git"
}
]
Install
composer require airslate/laravel-datadog
This package provide auto discovery for service provider
If Laravel package auto-discovery is disabled, add service providers manually. There are two service providers you must add:
\AirSlate\Datadog\ServiceProviders\DatadogProvider::class
\AirSlate\Datadog\ServiceProviders\ComponentsProvider::class
php artisan vendor:publish --tag=datadog
If you were using v2 version of this library you must run next code to recreate config file
php artisan vendor:publish --tag=datadog --force
or add next code to existing config
'components' => [
'http' => [
\AirSlate\Datadog\Components\ResponseTimeComponent::class,
\AirSlate\Datadog\Components\HttpQueryCounterComponent::class,
],
'console' => [
\AirSlate\Datadog\Components\JobTimingComponent::class,
\AirSlate\Datadog\Components\JobQueryCounterComponent::class,
],
'all' => [
\AirSlate\Datadog\Components\CacheHitsComponent::class,
\AirSlate\Datadog\Components\DbTransactionsComponent::class,
\AirSlate\Datadog\Components\DbQueryExecutedComponent::class,
\AirSlate\Datadog\Components\CustomEventsComponent::class,
\AirSlate\Datadog\Components\MemoryPeakUsageComponent::class,
]
],
Add Datadog keys to docker/config/env.ctmpl
STATSD_HOST=172.17.0.1
STATSD_PORT=8125
Add datadog agent for your docker-compose.yml file
datadog:
container_name: as-infra-datadog
image: datadog/docker-dd-agent
ports:
- 8125:8125/udp
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /proc/:/host/proc/:ro
- /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
environment:
API_KEY: __enter__your__key__there
SD_BACKEND: docker
NON_LOCAL_TRAFFIC: "true"
$this->app->bind('datadog.company.tag', function() {
return new Tag('company', 'airslate');
});
$this->app->tag('datadog.company.tag', DatadogProvider::DATADOG_TAG);
You can add your own events with name and custom tags. You need:
- Add
AirSlate\Datadog\Events\DatadogEventInterface
orAirSlate\Datadog\Events\DatadogEventExtendedInterface
interface to you event. - dispatch event by
event(new YourEvent());
This is part of functionality that responsible for processing of the metric. You can remove component by removing it from datadog.php config. Below you will find short description of each component.
Note: {application_namespace} - configurable through config file
AirSlate\Datadog\Components\CacheHitsComponent
- {application_namespace}.cache.item
- status - hit|miss|del|put
- increment
AirSlate\Datadog\Components\HttpQueryCounterComponent
- sends gauge metric with amount of queries executed during http call
- {application_namespace}.db.queries
- code - (http status code)
- method - (http method)
- gauge
AirSlate\Datadog\Components\DbTransactionsComponent
- {application_namespace}.db.transaction
- status - begin|commit|rollback
- increment
AirSlate\Datadog\Components\DbQueryExecutedComponent
- {application_namespace}.db.query
- status - executed
- increment
AirSlate\Datadog\Components\JobQueryCounterComponent
- {application_namespace}.queue.db.queries
- status - processed|exceptionOccurred|failed
- queue - (queue name)
- task - (job name)
- exception - (exception class name)
- gauge
AirSlate\Datadog\Components\JobTimingComponent
- {application_namespace}.queue.job
- status - processed|exceptionOccurred|failed
- queue - (queue name)
- task - (job name)
- exception - (exception class name)
- timing
AirSlate\Datadog\Components\JobTimingComponent
- {application_namespace}.memory_peak_usage
- code - (http response code)
- method - (http request method)
- gauge
- {application_namespace}.memory_peak_usage_real
- code - (http response code)
- method - (http request method)
- gauge
AirSlate\Datadog\Components\MemoryPeakUsageComponent
- {application_namespace}.queue.job
- status - processed|exceptionOccurred|failed
- queue - (queue name)
- task - (job name)
- exception - (exception class name)
- timing
AirSlate\Datadog\Components\ResponseTimeComponent
- {application_namespace}.response_time
- code - (http response code)
- method - (http request method)
- timing
AirSlate\Datadog\Components\CustomEventsComponent
- To send simple metric you must implement
AirSlate\Datadog\Events\DatadogEventInterface
- To send metric with specific type you must implement
AirSlate\Datadog\Events\DatadogEventExtendedInterface
Supported metric types:
-
DatadogEventExtendedInterface::METRIC_TYPE_HISTOGRAM
-
DatadogEventExtendedInterface::METRIC_TYPE_INCREMENT
-
DatadogEventExtendedInterface::METRIC_TYPE_DECREMENT
-
DatadogEventExtendedInterface::METRIC_TYPE_GAUGE
-
DatadogEventExtendedInterface::METRIC_TYPE_TIMING
- {application_namespace}.{$event->getEventCategory()}.{$event->getEventName()}
- code - (http response code)
- method - (http request method)
- timing