Install the Bundle
Run composer require compasshp/datadog-bundle in your project root.
Enable the Bundle
Add to config/bundles.php:
return [
// ...
Compass\DatadogBundle\CompassDatadogBundle::class => ['all' => true],
];
Configure Basic Settings
Create config/packages/compass_datadog.yaml with minimal APM/ASM settings:
compass_datadog:
tracing:
enabled: true
appsec:
enabled: true
Verify Agent Setup
Ensure the DataDog Agent is running with tracing (--enable-appsec if using ASM).
First Use Case Trigger a request (e.g., login/logout or API call). Check DataDog APM/ASM dashboards for:
APM Integration
session_id and user (if logged in) into DataDog traces.compass_datadog:
tracing:
custom_properties:
- 'user.role'
- 'request.ip'
compass_datadog.trace event to modify traces dynamically:
// In EventSubscriber
public function onTrace(ContextEvent $event) {
$event->getTrace()->setTag('custom.tag', 'value');
}
ASM Integration
AuthenticatesUsers trait or custom guards).compass_datadog:
appsec:
custom_properties:
- 'user.plan'
compass_datadog:
appsec:
ignore_routes:
- '/admin/*'
Conditional Tracing
when@!*prod:
compass_datadog:
tracing:
enabled: false
auth()->user()).Compass\DatadogBundle\Security\Authenticator to support custom guards.use Compass\DatadogBundle\Tracing\Tracer;
$tracer = app(Tracer::class);
$tracer->startTrace('job.processing');
Agent Misconfiguration
datadog-agent status
For ASM, ensure --enable-appsec is set.Session ID Missing
StartSession) runs before compass_datadog.trace.ASM Events Not Triggering
compass_datadog.appsec.login event:
event(new LoginEvent($user, $success));
Performance Overhead
when@prod:
compass_datadog:
tracing:
enabled: true
dd(app('compass_datadog.trace_context')->all()) to inspect injected data.config/logging.php to see bundle events:
'channels' => [
'compass_datadog' => [
'driver' => 'single',
'path' => storage_path('logs/compass_datadog.log'),
'level' => 'debug',
],
],
Custom Tracers Override the default tracer by binding a service:
$this->app->bind(Tracer::class, function () {
return new CustomTracer();
});
Event Subscribers
Listen to compass_datadog.trace or compass_datadog.appsec.login events for custom logic.
Configuration Overrides Dynamically adjust settings via environment variables:
compass_datadog:
tracing:
enabled: '%env(bool:DATADOG_TRACING_ENABLED,false)%'
custom_properties to tag traces by user segments (e.g., user.tier).How can I help you explore Laravel packages today?