Skip to content

Commit ab15c7e

Browse files
committed
docs: Add comprehensive documentation for Sentry Logs integration
- Document new sentry_logs driver introduced in v4.15.0 - Add detailed setup instructions and configuration examples - Explain differences between sentry and sentry_logs drivers - Provide practical usage examples and best practices - Include advanced structured logging service example - Add dual logging strategy recommendations Resolves lack of documentation for recently added Logs feature.
1 parent 307fb53 commit ab15c7e

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Documentation
6+
7+
- Add comprehensive documentation for Sentry Logs integration (`sentry_logs` driver) introduced in v4.15.0
8+
- Added detailed setup instructions and configuration examples
9+
- Documented differences between traditional `sentry` and new `sentry_logs` drivers
10+
- Provided practical usage examples and best practices
11+
- Added structured logging service example for business applications
12+
13+
314
## 4.15.0
415

516
The Sentry SDK team is happy to announce the immediate availability of Sentry Laravel SDK v4.15.0.

README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,148 @@ return Application::configure(basePath: dirname(__DIR__))
6464

6565
> Alternatively, you can configure Sentry as a [Laravel Log Channel](https://docs.sentry.io/platforms/php/guides/laravel/usage/#log-channels), allowing you to capture `info` and `debug` logs as well.
6666
67+
## Sentry Logs Integration (NEW in v4.15.0+)
68+
69+
The Laravel SDK now supports Sentry's new **Logs feature** (currently in Open Beta), which provides dedicated log management with advanced filtering, real-time streaming, and automatic correlation with errors and performance traces.
70+
71+
### Traditional vs. Logs Drivers
72+
73+
| Driver | Purpose | Destination | Use Case |
74+
|--------|---------|-------------|----------|
75+
| `sentry` | Error events | Issues tab | Error tracking & alerting |
76+
| `sentry_logs` | Application logs | Logs tab | Debugging & monitoring |
77+
78+
### Setup Sentry Logs
79+
80+
**1. Enable logs in your Sentry configuration:**
81+
82+
```php
83+
// config/sentry.php
84+
'enable_logs' => env('SENTRY_ENABLE_LOGS', true),
85+
```
86+
87+
**2. Configure log channels:**
88+
89+
```php
90+
// config/logging.php
91+
'channels' => [
92+
// Traditional error tracking
93+
'sentry' => [
94+
'driver' => 'sentry',
95+
'level' => 'error',
96+
'bubble' => true,
97+
],
98+
99+
// NEW: Dedicated logs feature
100+
'sentry_logs' => [
101+
'driver' => 'sentry_logs',
102+
'level' => 'info',
103+
'bubble' => true,
104+
],
105+
106+
// Combine both: local files + Sentry Logs
107+
'structured' => [
108+
'driver' => 'stack',
109+
'channels' => ['single', 'sentry_logs'],
110+
],
111+
],
112+
```
113+
114+
**3. Environment configuration:**
115+
116+
```bash
117+
# .env
118+
SENTRY_ENABLE_LOGS=true
119+
LOG_STACK=single,sentry_logs # Optional: send to multiple channels
120+
```
121+
122+
### Usage Examples
123+
124+
**Basic logging:**
125+
```php
126+
use Illuminate\Support\Facades\Log;
127+
128+
// Goes to Sentry Logs tab
129+
Log::channel('sentry_logs')->info('User action completed', [
130+
'user_id' => 123,
131+
'action' => 'profile_update',
132+
'ip_address' => $request->ip(),
133+
]);
134+
135+
// Business logic logging with structured data
136+
Log::channel('sentry_logs')->info('Payment processed', [
137+
'order_id' => 'ord_123',
138+
'amount' => 99.99,
139+
'currency' => 'USD',
140+
'payment_method' => 'stripe',
141+
]);
142+
```
143+
144+
**Advanced structured logging service:**
145+
```php
146+
<?php
147+
148+
namespace App\Services;
149+
150+
use Illuminate\Support\Facades\Log;
151+
152+
class BusinessLogger
153+
{
154+
public static function logBusinessEvent(string $event, array $data = []): void
155+
{
156+
Log::channel('sentry_logs')->info("Business event: {$event}", [
157+
'event_type' => $event,
158+
'timestamp' => now()->toISOString(),
159+
'session_id' => session()->getId(),
160+
...$data,
161+
]);
162+
}
163+
}
164+
```
165+
166+
### Benefits of Sentry Logs
167+
168+
- **Dedicated Interface**: Logs appear in Sentry's Logs tab with advanced filtering
169+
- **Structured Data**: Rich querying capabilities with tags and context
170+
- **Error Correlation**: Automatic linking between logs and related errors
171+
- **Performance Integration**: View logs alongside performance traces
172+
- **Real-time Streaming**: Live log monitoring in Sentry dashboard
173+
174+
### Best Practices
175+
176+
**Dual Logging Strategy:**
177+
```php
178+
// config/logging.php
179+
'channels' => [
180+
'app_monitoring' => [
181+
'driver' => 'stack',
182+
'channels' => ['sentry_logs'], // Application logs
183+
],
184+
'error_tracking' => [
185+
'driver' => 'stack',
186+
'channels' => ['sentry'], // Critical errors
187+
],
188+
'comprehensive' => [
189+
'driver' => 'stack',
190+
'channels' => ['single', 'sentry_logs'], // Local + Sentry
191+
],
192+
],
193+
```
194+
195+
**Structured Context:**
196+
```php
197+
Log::channel('sentry_logs')->info('API request completed', [
198+
'endpoint' => '/api/users',
199+
'method' => 'POST',
200+
'response_time_ms' => 150,
201+
'status_code' => 201,
202+
'user_id' => auth()->id(),
203+
]);
204+
```
205+
206+
> **Note**: Sentry Logs is currently in Open Beta. The `sentry_logs` driver requires `sentry/sentry-laravel` v4.15.0 or higher.
207+
208+
67209
### Configure
68210

69211
Configure the Sentry DSN with this command:

0 commit comments

Comments
 (0)