okvpn / datadog-symfony
Symfony Datadog integration
Installs: 1 778 221
Dependents: 1
Suggesters: 0
Security: 0
Stars: 21
Watchers: 3
Forks: 10
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=7.4
- graze/dog-statsd: ^0.4 || ^1.0
- symfony/framework-bundle: ^4.4 || ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- ext-pdo_sqlite: *
- doctrine/doctrine-bundle: ^2.6
- doctrine/orm: ^2.7
- phpunit/phpunit: ^8.5 || ^9.0 || ^10.0
- symfony/browser-kit: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/console: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/flex: ^1.10 || ^2.0
- symfony/monolog-bundle: ^3.2
- symfony/phpunit-bridge: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/security-bundle: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/var-dumper: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/yaml: ^4.4 || ^5.4 || ^6.0 || ^7.0
README
Symfony Datadog integration to monitor and track for application errors and send notifications about them.
Benefits
Use datadog-symfony for:
- Monitor production applications in realtime.
- Application performance insights to see when performance is geting degradated.
- Access to the
okvpn_datadog.client
through the container. - Send notification about errors in Slack, email, telegram, etc.
- Create JIRA issue when some alarm/exception triggers using this plugin
Install
Install using composer following the official Composer documentation:
- Install via composer:
composer require okvpn/datadog-symfony
- And add this bundle to your AppKernel:
For Symfony 4+ add bundle to config/bundles.php
<?php return [ ... // bundles Okvpn\Bundle\DatadogBundle\OkvpnDatadogBundle::class => ['all' => true], ... ]
- Base configuration to enable the datadog client in your
config.yml
okvpn_datadog: clients: default: 'datadog://127.0.0.1/namespace' ## More clients i2pd_client: 'datadog://10.10.1.1:8125/app?tags=tg1,tg2' 'null': null://null mock: mock://mock dns: '%env(DD_CLIENT)%'
Where env var looks like:
DD_CLIENT=datadog://127.0.0.1:8125/app1?tags=tg1,tg2
Access to client via DIC:
$client = $this->container->get('okvpn_datadog.client'); // Default public alias // okvpn_datadog.client.default - private services // okvpn_datadog.client.i2pd_client // okvpn_datadog.client.null class FeedController { public function __construct(private DogStatsInterface $dogStats){} // default } class FeedController { public function __construct(private DogStatsInterface $i2pdClient){} // i2pd_client }
class FeedController extends Controller { // Inject via arg for Symfony 4+ #[Route(path: '/', name: 'feeds')] public function feedsAction(DogStatsInterface $dogStats, DogStatsInterface $i2pdClient): Response { $dogStats->decrement('feed'); return $this->render('feed/feeds.html.twig'); } }
Custom metrics that provided by OkvpnDatadogBundle
Where app
metrics namespace.
Configuration
A more complex setup look like this config/packages/ddog.yml
:
okvpn_datadog:
profiling: true # Default false: enable exception, http request etc.
namespace: app # Metric namespace
port: 8125 # datadog udp port
host: 127.0.0.1
tags: # Default tags which sent with every request
- example.com
- cz1
doctrine: true # Enable timing for sql query
exception: all # Send event on exception
# *all* - handle all exceptions: logger error context, console error, http error.
# *uncaught* - handle uncaught exceptions: console error, http error.
# *none* - disable exceptions handler
dedup_path: null # Path to save duplicates log records across multiple requests.
# Used to prevent send multiple event on the same error
dedup_keep_time: 86400 # Time in seconds during which duplicate entries should be suppressed after a given log is sent through
artifacts_path: null # Long events is aggregate as artifacts, because datadog event size is limited to 4000 characters.
handle_exceptions: # Skip exceptions
skip_instanceof:
- Symfony\Component\Console\Exception\ExceptionInterface
- Symfony\Component\HttpKernel\Exception\HttpExceptionInterface
skip_command: # Skip exception for console command
- okvpn:message-queue:consume
Usage
class FeedController extends Controller { // Inject via arg for Symfony 4+ #[Route(path: '/', name: 'feeds')] public function feedsAction(DogStatsInterface $dogStats): Response { $dogStats->decrement('feed'); return $this->render('feed/feeds.html.twig'); } } // or use service directly for 3.4 $client = $this->container->get('okvpn_datadog.client'); /* * Increment/Decriment * * Counters track how many times something happens per second, such as page views. * @link https://docs.datadoghq.com/developers/dogstatsd/data_types/#counters * * @param string $metrics Metric(s) to increment * @param int $delta Value to decrement the metric by * @param float $sampleRate Sample rate of metric * @param string[] $tags List of tags for this metric * * @return DogStatsInterface */ $client->increment('page.views', 1); $client->increment('page.load', 1, 0.5, ['tag1' => 'http']);
Sets
$consumerPid = getmypid(); $client->set('consumers', $consumerPid);
Timing
$client->timing('http.response_time', 256);
See more metrics here DogStatsInterface
Impact on performance
Datadog bundle use UDP protocol to send custom metrics to DogStatsD collector, that usually running on localhost (127.0.0.1). Because it uses UDP, your application can send metrics without waiting for a response. DogStatsD aggregates multiple data points for each unique metric into a single data point over a period of time called the flush interval and sends it to Datadog where it is stored and available for graphing alongside the rest of your metrics.
Screencasts.
What can be done using datadog.
Datadog custom symfony dashboard
Datadog Anomaly Monitor of running consumers
Live exception event stream
Send notification about errors in telegram.
Create JIRA issue when some alarm/exception triggers
License
MIT License. See LICENSE.