amarc-sudo/sentry-enhanced-tracing
Installation:
composer require amarc-sudo/sentry-enhanced-tracing lexik/jwt-authentication-bundle
Enable Bundle:
Add to config/bundles.php:
AmarcSudo\SentryEnhancedTracing\SentryEnhancedTracingBundle::class => ['all' => true],
Configure Sentry (ensure traces_sample_rate is set in config/packages/sentry.yaml):
sentry:
dsn: '%env(SENTRY_DSN)%'
options:
traces_sample_rate: 1.0
First Use Case: Trigger an HTTP request to your Symfony app. Open Sentry dashboard to see:
kernel.request, kernel.controller).Automatic Tracing:
// DB query auto-traced under kernel.controller
$users = $em->getRepository(User::class)->findAll();
Event Phase Tracking:
kernel.request, kernel.controller, etc.) are traced as spans.# config/packages/sentry_enhanced_tracing.yaml
sentry_enhanced_tracing:
tracked_events:
- 'kernel.request'
- 'kernel.controller'
User Context:
User entity with EnhancedUserInterface for richer Sentry context:
class User implements EnhancedUserInterface {
public function getEnhancedFirstname(): ?string { ... }
public function getEnhancedLastname(): ?string { ... }
}
lexik_jwt_authentication.on_jwt_authenticated.Messenger Integration:
SentryTraceStamp):
// Dispatch
$bus->dispatch(new EmailJob($payload));
// Worker (auto-traced)
php bin/console messenger:consume async
traces_sample_rate: 0.1 in production to reduce overhead.config/packages/sentry_enhanced_tracing.yaml:
sentry_enhanced_tracing:
performance_thresholds:
kernel.controller: 0.1 # 100ms
Sentry\State\HubInterface:
$hub->configureScope(function (Scope $scope) {
$scope->setSpan(null); // Disable tracing for this request
});
Missing Spans:
traces_sample_rate set to 0 or Sentry DSN misconfigured.sentry.yaml and check Sentry dashboard for transactions.SentryListenerPhasesTracer errors.High Overhead:
traces_sample_rate: 1.0) on high-traffic endpoints.# config/packages/sentry_enhanced_tracing.yaml
sentry_enhanced_tracing:
excluded_routes:
- '^/api/health'
PII Leakage:
capture_email: true).user_context:
sentry_enhanced_tracing:
user_context:
capture_email: false
Listener Conflicts:
ChangeSentryListenerPriorityPass runs early (priority 99999-99995).# config/packages/dev/sentry_enhanced_tracing.yaml
sentry_enhanced_tracing:
debug: true
$hub->startSpan('custom_operation', [
'op' => 'custom',
'description' => 'Manual span example',
]);
SentryTraceStamp and SentryUserStamp are registered:
use AmarcSudo\SentryEnhancedTracing\Messenger\SentryTraceStamp;
use AmarcSudo\SentryEnhancedTracing\Messenger\SentryUserStamp;
Custom Integrations:
SentryListenerPhasesTracer to add support for new services (e.g., Elasticsearch):
// src/EventListener/CustomSentryTracer.php
class CustomSentryTracer implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
KernelEvents::CONTROLLER => ['onController', 100],
];
}
public function onController(ControllerEvent $event) {
$hub = \Sentry\SentrySdk::getCurrentHub();
$hub->startSpan('elasticsearch.query', ['op' => 'search']);
// ... your logic
}
}
Override User Context:
EnhancedUserInterface to customize PII handling:
class User implements EnhancedUserInterface {
public function getEnhancedEmail(): ?string {
return $this->email ?? null; // Sanitize or redact if needed
}
}
Phase Customization:
$tracer = $container->get(SentryListenerPhasesTracer::class);
$tracer->addTrackedEvent('custom.event');
How can I help you explore Laravel packages today?