npm package: @stacksleuth/laravel-agent
Description: Comprehensive Laravel performance monitoring agent - Eloquent ORM optimization, route performance analysis, middleware tracking, job queue monitoring, and advanced cache performance metrics.
Author: StackSleuth Team
Latest version: 0.2.4

# @stacksleuth/laravel-agent

<div align="center">

![StackSleuth Laravel Agent](../../assets/logo.svg)

**StackSleuth Laravel Agent**

[![npm version](https://badge.fury.io/js/%40stacksleuth%2Flaravel-agent.svg)](https://badge.fury.io/js/%40stacksleuth%2Flaravel-agent)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
[![Node.js](https://img.shields.io/badge/Node.js-18.0+-green.svg)](https://nodejs.org/)

</div>

## 🚀 What is StackSleuth Laravel Agent?

Comprehensive Laravel performance monitoring agent - Eloquent ORM optimization, route performance analysis, middleware tracking, job queue monitoring, and advanced cache performance metrics.

## ✨ Key Features

- 🎼 **Eloquent ORM Monitoring**: Query optimization and N+1 detection
- 🛣️ **Route Performance**: Laravel route execution analysis
- 🔧 **Middleware Tracking**: Request middleware performance monitoring
- ⚙️ **Job Queue Monitoring**: Background job performance tracking
- 🗄️ **Cache Performance**: Laravel cache system optimization
- 📧 **Mail Tracking**: Email sending performance analysis
- 🔄 **Event Monitoring**: Laravel event system performance
- ⚡ **Artisan Integration**: Command-line monitoring capabilities

## 📦 Installation

```bash
# npm
npm install @stacksleuth/laravel-agent

# yarn
yarn add @stacksleuth/laravel-agent

# pnpm
pnpm add @stacksleuth/laravel-agent
```

```bash
yarn add @stacksleuth/laravel-agent
```

```bash
pnpm add @stacksleuth/laravel-agent
```

## 🏁 Quick Start

```php
<?php
// config/app.php
'providers' => [
    // ... other providers
    StackSleuth\Laravel\StackSleuthServiceProvider::class,
],

// config/stacksleuth.php
return [
    'enabled' => env('STACKSLEUTH_ENABLED', true),
    'sample_rate' => env('STACKSLEUTH_SAMPLE_RATE', 0.1),
    'monitor_eloquent' => true,
    'monitor_cache' => true,
    'monitor_jobs' => true,
];

// In your controller
use StackSleuth\Laravel\Facades\StackSleuth;

class UserController extends Controller
{
    public function index()
    {
        StackSleuth::startSpan('fetch-users');
        
        $users = User::with('profile')->paginate(10);
        
        StackSleuth::endSpan();
        
        return response()->json($users);
    }
}
```


## 🛠️ Troubleshooting

### Common Issues

**Agent Not Starting**
```typescript
// Enable debug mode
const agent = new LaravelAgent({
  enabled: true,
  debug: true
});
```

**High Memory Usage**
```typescript
// Optimize memory usage
const agent = new LaravelAgent({
  bufferSize: 500,
  flushInterval: 5000,
  sampleRate: 0.01
});
```

**Missing Metrics**
- Check that the agent is enabled
- Verify your API key and project ID
- Ensure sampling rate allows data through
- Check network connectivity to StackSleuth API

### Debug Mode

```bash
DEBUG=stacksleuth:* node your-app.js
```

## 📚 Resources

- **[Official Documentation](https://github.com/Jack-GitHub12/StackSleuth#readme)**
- **[API Reference](https://github.com/Jack-GitHub12/StackSleuth/blob/main/docs/laravel-agent.md)**
- **[Examples Repository](https://github.com/Jack-GitHub12/StackSleuth/tree/main/examples/laravel-agent)**

## 🤝 Contributing

We welcome contributions! Please see our [Contributing Guide](https://github.com/Jack-GitHub12/StackSleuth/blob/main/CONTRIBUTING.md) for details.

## 📄 License

MIT License - see the [LICENSE](https://github.com/Jack-GitHub12/StackSleuth/blob/main/LICENSE) file for details.

---

<div align="center">

**[Website](https://github.com/Jack-GitHub12/StackSleuth)** • 
**[Documentation](https://github.com/Jack-GitHub12/StackSleuth#readme)** • 
**[NPM Registry](https://www.npmjs.com/package/@stacksleuth/laravel-agent)** • 
**[GitHub](https://github.com/Jack-GitHub12/StackSleuth)**

Made with ⚡ by [StackSleuth](https://github.com/Jack-GitHub12/StackSleuth)

</div>