PHPackages                             amarc-sudo/sentry-enhanced-tracing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. amarc-sudo/sentry-enhanced-tracing

ActiveSymfony-bundle[Logging &amp; Monitoring](/categories/logging)

amarc-sudo/sentry-enhanced-tracing
==================================

Enhanced Sentry tracing package with automatic child span capture and listener phase tracking for Symfony applications

v1.1.0(4mo ago)01.6k↓36.8%MITPHPPHP &gt;=8.1CI failing

Since Jul 6Pushed 4mo agoCompare

[ Source](https://github.com/amarc-sudo/sentry-enhanced-tracing)[ Packagist](https://packagist.org/packages/amarc-sudo/sentry-enhanced-tracing)[ RSS](/packages/amarc-sudo-sentry-enhanced-tracing/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (17)Versions (5)Used By (0)

Sentry Enhanced Tracing Bundle
==============================

[](#sentry-enhanced-tracing-bundle)

[![Latest Version](https://camo.githubusercontent.com/3a2226ca8aee633c1126cdab25aeafcf55ea4cd97764fef65ad2b900dd2f6bea/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f616d6172632d7375646f2f73656e7472792d656e68616e6365642d74726163696e672e737667)](https://github.com/amarc-sudo/sentry-enhanced-tracing/releases)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)

Enhanced Sentry tracing package with **automatic child span capture** and **listener phase tracking** for Symfony applications.

🚀 Key Features
--------------

[](#-key-features)

### 🔍 **Automatic Child Span Capture**

[](#-automatic-child-span-capture)

- **Database queries** (DBAL) automatically nested under event phases
- **Cache operations** (Redis, APCu) traced hierarchically
- **Template rendering** (Twig) performance tracking
- **HTTP client** calls monitored automatically
- **Zero configuration** - works out of the box!

### 📊 **Listener Phase Tracking**

[](#-listener-phase-tracking)

- Traces Symfony kernel event phases as Sentry spans
- Measures execution time of all event listeners
- Performance categorization (fast/normal/slow/very\_slow)
- Detailed breadcrumbs with execution metrics

### 👤 **Enhanced User Context**

[](#-enhanced-user-context)

- Automatic user identification in Sentry **after JWT authentication**
- Enhanced user information capture with `EnhancedUserInterface`
- Request/response metadata capture
- Exception context enrichment
- Security-aware PII handling

📦 Installation
--------------

[](#-installation)

```
composer require amarc-sudo/sentry-enhanced-tracing
```

### 🔧 Requirements

[](#-requirements)

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.

### 📝 Bundle Registration

[](#-bundle-registration)

Add the bundle to your `config/bundles.php`:

```
return [
    // ... other bundles
    Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
    AmarcSudo\SentryEnhancedTracing\SentryEnhancedTracingBundle::class => ['all' => true],
];
```

🎯 How It Works
--------------

[](#-how-it-works)

### Automatic Span Hierarchy

[](#automatic-span-hierarchy)

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)

```

### 🔧 No Code Changes Required!

[](#-no-code-changes-required)

The bundle uses **Sentry Hub manipulation** to automatically capture:

- SQL queries from Doctrine DBAL
- Cache operations from Symfony Cache
- Template rendering from Twig
- HTTP client requests
- Redis commands
- Custom integrations

📋 What You Get
--------------

[](#-what-you-get)

### 🎭 **Event Listeners**

[](#-event-listeners)

- `SentryListenerPhasesTracer` - Core phase tracking with child span capture
- `SentryUserContextListener` - Enhanced user context and request metadata

### ⚡ **Performance Optimization**

[](#-performance-optimization)

- `ChangeSentryListenerPriorityPass` - Optimized Sentry listener priorities
- High-priority execution (99999-99995) for proper data capture
- Minimal performance overhead

### 📊 **Rich Metrics**

[](#-rich-metrics)

- Execution time categorization
- Memory usage tracking
- Request/response size analysis
- Performance breadcrumbs
- Exception context enrichment

🔧 Configuration
---------------

[](#-configuration)

The bundle works **zero-config** but you can customize behavior:

```
# config/packages/sentry_enhanced_tracing.yaml
sentry_enhanced_tracing:
    # Configuration options (if needed)
```

### 🔐 JWT Authentication Integration

[](#-jwt-authentication-integration)

The bundle automatically captures user context **after** successful JWT authentication by listening to the `lexik_jwt_authentication.on_jwt_authenticated` event.

### 👤 Enhanced User Interface

[](#-enhanced-user-interface)

To provide richer user context in Sentry, implement the `EnhancedUserInterface` in your User entity:

```
