Datadog
Send Vortos metrics via OpenTelemetry OTLP or DogStatsD and traces via OpenTelemetry to Datadog — Agent setup and full APM configuration.
Datadog
Datadog is a fully managed observability platform covering metrics, logs, and traces in one product. Vortos connects to Datadog in two ways:
- Metrics via OpenTelemetry OTLP — Vortos pushes OTLP metrics directly to Datadog or to a Collector/Agent
- Metrics via DogStatsD — the Datadog Agent accepts StatsD UDP datagrams and forwards them to Datadog
- Traces via OpenTelemetry OTLP — the Datadog Agent accepts OTLP spans and maps them to Datadog APM traces
You do not need to install a Datadog-specific SDK in your application — Vortos's standard OTLP, StatsD, and OpenTelemetry output is all that's needed.
What you need
- A Datadog account and API key (datadoghq.com, free trial available)
- The Datadog Agent running on your host or as a Docker container
vortos-metricsinstalled for metricsvortos-tracing+ OpenTelemetry SDK for traces (optional)
Step 1 — Get your Datadog API key
- Log in to app.datadoghq.com
- Go to Organization Settings → API Keys
- Click New Key, name it (e.g.
my-app), copy the key
Step 2 — Run the Datadog Agent
Docker:
services:
datadog-agent:
image: gcr.io/datadoghq/agent:7
environment:
DD_API_KEY: "${DD_API_KEY}"
DD_SITE: "datadoghq.com" # or datadoghq.eu for EU region
DD_DOGSTATSD_NON_LOCAL_TRAFFIC: "true" # accept StatsD from other containers
DD_APM_ENABLED: "true"
DD_APM_NON_LOCAL_TRAFFIC: "true" # accept OTLP traces from other containers
DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_HTTP_ENDPOINT: "0.0.0.0:4318"
ports:
- "8125:8125/udp" # DogStatsD
- "4318:4318" # OTLP HTTP
volumes:
- /var/run/docker.sock:/var/run/docker.sock:roDD_API_KEY=your-datadog-api-keydocker compose up -d datadog-agentStep 3 — Configure Vortos metrics
Option A: OTLP metrics push
Use this when you want one vendor-neutral metrics path across Datadog, New Relic, and an OpenTelemetry Collector.
composer require open-telemetry/sdk open-telemetry/exporter-otlp guzzlehttp/guzzleuse Vortos\Metrics\Config\MetricsAdapter;
use Vortos\Metrics\DependencyInjection\VortosMetricsConfig;
return static function (VortosMetricsConfig $config): void {
$config
->adapter(MetricsAdapter::OpenTelemetry)
->namespace('myapp')
->service('checkout-api', version: $_ENV['APP_VERSION'] ?? '', environment: $_ENV['APP_ENV'] ?? 'prod')
->datadogOtlp(
apiKey: $_ENV['DD_API_KEY'] ?? '',
site: $_ENV['DD_SITE'] ?? 'datadoghq.com',
timeoutMs: 200,
);
};For larger deployments, push to the local Datadog Agent or OpenTelemetry Collector instead of pushing directly to Datadog:
$config->otlpCollector('http://datadog-agent:4318/v1/metrics', timeoutMs: 200);Option B: StatsD → DogStatsD
use Vortos\Metrics\Config\MetricsAdapter;
use Vortos\Metrics\DependencyInjection\VortosMetricsConfig;
return static function (VortosMetricsConfig $config): void {
$config->adapter(MetricsAdapter::StatsD)
->statsDHost($_ENV['DD_AGENT_HOST'] ?? '127.0.0.1')
->statsDPort(8125)
->statsDSampleRate(1.0); // send all metrics — Datadog handles aggregation
// Optionally set metric prefix (all names become {namespace}.*)
$config->namespace('myapp');
};DD_AGENT_HOST=datadog-agent # Docker service name, or 127.0.0.1 for same-host agentDogStatsD tag format
Vortos uses the DogStatsD tag extension: |#key:value,key:value. This is natively supported by the Datadog Agent and maps directly to Datadog metric tags — no conversion needed.
OTLP lifecycle
The OTLP metrics adapter calls forceFlush() at request and command termination, and reserves shutdown() for actual process exit. This is safe for both PHP-FPM and FrankenPHP worker mode.
Step 4 — Verify metrics in Datadog
- Make a few requests to your application
- In Datadog → Metrics → Explorer
- Search for
myapp.http_requests_total(using your configured namespace) - You should see the metric with tags like
method:POST,route:orders.place,status:201
If the metric doesn't appear within 60 seconds:
# Check the agent is receiving StatsD traffic
docker compose exec datadog-agent agent status | grep DogStatsDFor OTLP metrics, check the Agent or Collector logs first. If the collector sees the data but Datadog does not, the app is working and the issue is usually API key, site, or exporter configuration.
Step 5 — Configure Vortos traces (OpenTelemetry → Datadog APM)
composer require open-telemetry/sdk open-telemetry/exporter-otlpuse OpenTelemetry\Contrib\Otlp\OtlpHttpSpanExporter;
use OpenTelemetry\SDK\Trace\SpanProcessor\BatchSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;
use Vortos\Tracing\NoOpTracer;
use Vortos\Tracing\OpenTelemetry\OpenTelemetryTracer;
$services->set(OtlpHttpSpanExporter::class)
->arg('$endpoint', $_ENV['OTEL_EXPORTER_OTLP_ENDPOINT'] ?? 'http://localhost:4318/v1/traces');
$services->set(BatchSpanProcessor::class)
->arg('$exporter', service(OtlpHttpSpanExporter::class));
$services->set(TracerProvider::class)
->call('addSpanProcessor', [service(BatchSpanProcessor::class)]);
$services->set('otel.tracer')
->factory([service(TracerProvider::class), 'getTracer'])
->arg('$name', $_ENV['OTEL_SERVICE_NAME'] ?? 'my-app');
$services->set(NoOpTracer::class, OpenTelemetryTracer::class)
->arg('$tracer', service('otel.tracer'))
->public(false);OTEL_EXPORTER_OTLP_ENDPOINT=http://datadog-agent:4318/v1/traces
OTEL_SERVICE_NAME=my-app
DD_AGENT_HOST=datadog-agentStep 6 — Verify traces in Datadog APM
- Make a few requests to your application
- In Datadog → APM → Traces
- Filter by service name (
my-app) - Click any trace to see the span waterfall
Datadog maps OpenTelemetry span attributes to Datadog's own fields — http.method, http.status_code, db.statement, etc. all appear as first-class attributes in the trace UI.
Step 7 — Connect metrics to traces (Datadog APM correlation)
Datadog can correlate metrics with traces when both use the same service name and environment tags. In your metrics config, add resource attribute tags that match your Datadog service:
OTEL_RESOURCE_ATTRIBUTES=service.name=my-app,deployment.environment=prod,service.version=1.2.3In Datadog, navigate to a metric in a dashboard → click View traces to jump to traces from the same service at the same time period.
Datadog Dashboards
Datadog automatically creates a service overview dashboard when APM data arrives. For custom dashboards using Vortos metrics:
- Go to Dashboards → New Dashboard
- Add a Timeseries widget
- Search for
myapp.http_requests_totalin the metric field - Group by
routeandstatus
Logs (optional)
To ship Vortos logs to Datadog:
- Enable Log Management in your Datadog account
- Add the log collection configuration to the Datadog Agent:
logs: - type: file path: /var/log/*.log service: my-app source: php - In
docker-compose.yml, mount yourvar/log/directory into the Datadog Agent container