@stacksleuth/django-agent
v0.2.4
Published
Advanced Django performance monitoring agent - Middleware tracking, database query optimization, template rendering analysis, session monitoring, and comprehensive view-level performance metrics.
Maintainers
Readme
@stacksleuth/django-agent
StackSleuth Django Agent
🚀 What is StackSleuth Django Agent?
Advanced Django performance monitoring agent - Middleware tracking, database query optimization, template rendering analysis, session monitoring, and comprehensive view-level performance metrics.
✨ Key Features
- 🐍 Django Middleware Tracking: Request/response middleware performance
- 🗄️ ORM Query Optimization: Django ORM query performance analysis
- 🎨 Template Rendering: Django template performance monitoring
- 👤 Session Monitoring: User session performance tracking
- 🔍 View-level Metrics: Detailed view function performance data
- 🔄 Real-time Updates: WebSocket integration for live monitoring
- 📊 Admin Integration: Django admin performance insights
- ⚡ Production Ready: Minimal overhead Django integration
📦 Installation
# npm
npm install @stacksleuth/django-agent
# yarn
yarn add @stacksleuth/django-agent
# pnpm
pnpm add @stacksleuth/django-agentyarn add @stacksleuth/django-agentpnpm add @stacksleuth/django-agent🏁 Quick Start
# settings.py
INSTALLED_APPS = [
# ... your apps
'stacksleuth.django',
]
MIDDLEWARE = [
'stacksleuth.django.middleware.StackSleuthMiddleware',
# ... your middleware
]
STACKSLEUTH = {
'ENABLED': True,
'SAMPLE_RATE': 0.1,
'MONITOR_DATABASE': True,
'MONITOR_TEMPLATES': True,
}
# views.py
from stacksleuth.django import track_performance
@track_performance('user-list-view')
def user_list(request):
users = User.objects.all()
return JsonResponse({'users': list(users.values())})📖 Comprehensive Examples
Django Settings
# settings.py
INSTALLED_APPS = [
# ... your apps
'stacksleuth.django',
]
MIDDLEWARE = [
'stacksleuth.django.middleware.StackSleuthMiddleware',
# ... your middleware
]
STACKSLEUTH = {
'ENABLED': True,
'PROJECT_ID': 'your-project-id',
'API_KEY': 'your-api-key',
'SAMPLE_RATE': 0.1,
'MONITOR_DATABASE': True,
'MONITOR_TEMPLATES': True,
}View Performance Tracking
# views.py
from stacksleuth.django import track_performance
from django.http import JsonResponse
@track_performance('user-list-view')
def user_list(request):
users = User.objects.select_related('profile').all()
# Track business metrics
track_metric('users.listed', len(users), {
'request_method': request.method,
'user_authenticated': request.user.is_authenticated
})
return JsonResponse({'users': list(users.values())})🎯 Real-World Usage
Production Configuration
const agent = new DjangoAgent({
enabled: process.env.NODE_ENV === 'production',
projectId: process.env.STACKSLEUTH_PROJECT_ID,
apiKey: process.env.STACKSLEUTH_API_KEY,
sampleRate: process.env.NODE_ENV === 'production' ? 0.01 : 0.1,
bufferSize: 1000,
flushInterval: 10000
});Monitoring Best Practices
- Sampling Rate: Use lower sampling rates (1-5%) in production
- Buffer Management: Configure appropriate buffer sizes for your traffic
- Error Handling: Always include error context in your monitoring
- Security: Never log sensitive data like passwords or API keys
- Performance: Monitor the monitoring - track agent overhead
🛠️ Troubleshooting
Common Issues
Agent Not Starting
// Enable debug mode
const agent = new DjangoAgent({
enabled: true,
debug: true
});High Memory Usage
// Optimize memory usage
const agent = new DjangoAgent({
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
DEBUG=stacksleuth:* node your-app.js📚 Resources
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
📄 License
MIT License - see the LICENSE file for details.
Website • Documentation • NPM Registry • GitHub
Made with ⚡ by StackSleuth
