Monitoring
performance
Performance monitoring and optimization
performance
Performance monitoring with real-time metrics, Core Web Vitals tracking, application profiling, bottleneck detection, and optimization recommendations.
Overview
The performance primitive provides comprehensive performance monitoring including page load metrics, Core Web Vitals, API latency tracking, resource utilization, performance budgets, and automated optimization suggestions.
Parent Primitive: analytics - Analytics and metrics platform
SDK Object Mapping
This primitive maps to the send SDK object for performance tracking:
import { send, performance } from 'sdk.do'
// Track Core Web Vitals
await send('analytics.track', {
event: 'performance.pageLoad',
metrics: {
FCP: 1200, // First Contentful Paint
LCP: 2100, // Largest Contentful Paint
FID: 50, // First Input Delay
CLS: 0.05, // Cumulative Layout Shift
},
})
// Monitor API performance
await performance.trackAPI({
endpoint: '/api/users',
method: 'GET',
duration: 245,
status: 200,
})
// Set performance budgets
await performance.setBudget({
page: '/products',
budgets: {
LCP: { max: 2500, warning: 2000 },
totalSize: { max: 1048576, warning: 819200 },
},
})Quick Example
import { performance } from 'sdk.do'
// Track page load performance
await performance.trackPageLoad({
url: '/products',
metrics: {
FCP: 1200, // First Contentful Paint
LCP: 2100, // Largest Contentful Paint
FID: 50, // First Input Delay
CLS: 0.05, // Cumulative Layout Shift
TTFB: 300, // Time to First Byte
},
navigation: 'navigate',
connection: '4g',
})
// Monitor API performance
await performance.trackAPI({
endpoint: '/api/users',
method: 'GET',
duration: 245,
status: 200,
size: 15360,
})
// Set performance budgets
await performance.setBudget({
page: '/products',
budgets: {
LCP: { max: 2500, warning: 2000 },
FID: { max: 100, warning: 50 },
CLS: { max: 0.1, warning: 0.05 },
totalSize: { max: 1048576, warning: 819200 }, // 1MB max, 800KB warning
},
})
// Get performance report
const report = await performance.getReport({
timeRange: { last: '7d' },
pages: ['/products', '/checkout'],
metrics: ['LCP', 'FID', 'CLS', 'TTFB'],
})
console.log(`Average LCP: ${report.averages.LCP}ms`)
console.log(`P75 FID: ${report.percentiles.FID.p75}ms`)
// Detect bottlenecks
const bottlenecks = await performance.detectBottlenecks({
endpoint: '/api/search',
threshold: { duration: 1000 },
})
bottlenecks.forEach((bottleneck) => {
console.log(`Bottleneck: ${bottleneck.operation}`)
console.log(`Duration: ${bottleneck.duration}ms`)
console.log(`Recommendation: ${bottleneck.suggestion}`)
})
// Profile function execution
const profile = await performance.profile(async () => {
// Code to profile
const results = await database.query(complexQuery)
const processed = await processResults(results)
return processed
})
console.log(`Total time: ${profile.duration}ms`)
console.log(`Database query: ${profile.breakdown.query}ms`)
console.log(`Processing: ${profile.breakdown.processing}ms`)
// Monitor resource usage
await performance.trackResource({
type: 'script',
url: 'https://cdn.example.com/app.js',
size: 245760,
duration: 450,
cached: false,
})
// Real-time alerts
on(performance.budgetExceeded, async (event) => {
console.log(`Budget exceeded for ${event.page}`)
console.log(`Metric: ${event.metric}`)
console.log(`Value: ${event.value} (budget: ${event.budget})`)
await alerts.send({
to: '[email protected]',
subject: 'Performance budget exceeded',
body: `${event.metric} on ${event.page}: ${event.value}ms`,
})
})
// Get optimization suggestions
const suggestions = await performance.getOptimizations({
page: '/products',
})
suggestions.forEach((suggestion) => {
console.log(`Priority: ${suggestion.priority}`)
console.log(`Issue: ${suggestion.issue}`)
console.log(`Fix: ${suggestion.recommendation}`)
console.log(`Impact: ${suggestion.expectedImprovement}`)
})Core Capabilities
- Core Web Vitals - LCP, FID, CLS tracking
- API Monitoring - Endpoint performance tracking
- Profiling - Code execution profiling
- Budgets - Performance budget enforcement
- Optimization - Automated recommendations
Access Methods
SDK
TypeScript/JavaScript library for performance
await performance.trackPageLoad({ url: '/products', metrics })CLI
Command-line tool for performance operations
do performance report --page /products --last 7dAPI
REST/RPC endpoints for performance management
curl https://api.do/v1/performance/report?page=/products&last=7dMCP
Model Context Protocol for AI-driven performance
Show me the performance report for the products page over the last 7 daysRelated Primitives
Parent Primitive
- analytics - Analytics and metrics platform
Sibling Primitives
- kpis - KPI tracking
- trace - Distributed tracing
- experiments - A/B testing