amarc-sudo/sentry-enhanced-tracing
Enhanced Sentry tracing package with automatic child span capture and listener phase tracking for Symfony applications.
EnhancedUserInterfacecomposer require amarc-sudo/sentry-enhanced-tracing
This bundle requires LexikJWTAuthenticationBundle to be installed and configured:
composer require lexik/jwt-authentication-bundle
The bundle automatically hooks into JWT authentication events to capture user context after successful authentication.
Add the bundle to your config/bundles.php:
return [
// ... other bundles
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
AmarcSudo\SentryEnhancedTracing\SentryEnhancedTracingBundle::class => ['all' => true],
];
The bundle creates a magical hierarchy in Sentry by setting event phase spans as "current spans":
POST /api/resources (500ms)
├── Event Listeners Phase: kernel.request (50ms)
│ ├── db.query: SELECT users WHERE id=? (15ms)
│ ├── cache.get: user:permissions:123 (2ms)
│ └── security.check (30ms)
├── Event Listeners Phase: kernel.controller (200ms)
│ ├── db.query: SELECT resources WHERE category=? (80ms)
│ ├── cache.set: resources:category:456 (5ms)
│ └── business.logic (115ms)
└── Event Listeners Phase: kernel.response (100ms)
├── twig.render: response.html.twig (85ms)
└── cache.set: rendered:template:hash (3ms)
The bundle uses Sentry Hub manipulation to automatically capture:
SentryListenerPhasesTracer - Core phase tracking with child span captureSentryUserContextListener - Enhanced user context and request metadataChangeSentryListenerPriorityPass - Optimized Sentry listener prioritiesThe bundle works zero-config but you can customize behavior:
# config/packages/sentry_enhanced_tracing.yaml
sentry_enhanced_tracing:
# Configuration options (if needed)
The bundle automatically captures user context after successful JWT authentication by listening to the lexik_jwt_authentication.on_jwt_authenticated event.
To provide richer user context in Sentry, implement the EnhancedUserInterface in your User entity:
<?php
namespace App\Entity;
use AmarcSudo\SentryEnhancedTracing\User\EnhancedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
class User implements UserInterface, EnhancedUserInterface
{
// ... your existing User entity code
public function getEnhancedFirstname(): ?string
{
return $this->firstname;
}
public function getEnhancedLastname(): ?string
{
return $this->lastname;
}
public function getEnhancedEmail(): ?string
{
return $this->email;
}
}
This will automatically enrich your Sentry traces with:
getUserIdentifier() (used as UUID)In your Sentry dashboard, you'll see:
Transaction: POST /api/users/123/resources
Duration: 450ms
Spans:
MIT License. See LICENSE for details.
Contributions welcome! Please see CONTRIBUTING.md for details.
Made with ❤️ by Aurelien Marc
How can I help you explore Laravel packages today?