yoursurprisecom/monolog-dd-udp-handler

Monolog Datadog UDP Handler

v1.6.3 2024-04-05 07:43 UTC

This package is auto-updated.

Last update: 2024-05-16 08:24:58 UTC


README

workflow Minimum PHP Version phpstan License: MIT

Overview

This Monolog handler will send the messages to the dd-log-proxy over UDP and the dd-log-proxy will send the messages over TCP to the Datadog API.

Datadog Log Proxy

This handler is build to use in conjunction with the Datadog Log Proxy written in go. The proxy can be run as a container next to you application as a sidecar or as a standalone service.

One proxy for all applications

As this handler gather the information from the current trace, only one proxy is needed for all your applications. The logs will be connected to the correct trace and service.

Usage

Install the package using composer: composer require yoursurprisecom/monolog-dd-udp-handler

Simply create the handler with the proxy hostname and port, and push the handler into monolog:

<?php

use Monolog\Logger;
use YourSurpriseCom\Monolog\DatadogUdp\Handler\DataDogUdpHandler;

$logger  = new Logger('my_logger');
$handler = new DataDogUdpHandler("<proxy host>",1053);
$logger->pushHandler($handler);

$logger->info("This log message is sent non blocking over UDP to Datadog!");

Data flow

The data flow is as following:

+-----+       +-------------------------+             +--------------+             +-------------+ 
| PHP |  ==>  | Monolog Datadog Handler |  ==> (UDP)  | dd-log-proxy |  ==> (TCP)  | Datadog API |
+-----+       +-------------------------+             +--------------+             +-------------+ 

Datadog

This handler uses the Datadog PHP ddtrace package to gather information about the current span and trace. Logs will be connected to the trace in the UI.

It will also create its own Datadog service log-proxy with it own spans.