What is Profiling?
Profiling samples your application’s call stack at regular intervals, creating a detailed picture of where time is spent:- Function-level insights: See which functions are slowest
- Call hierarchies: Understand the call tree
- Flame graphs: Visual representation of time spent
- CPU usage: Identify CPU-intensive operations
Profiling is currently available for Node.js, Python, PHP, Ruby, and other server-side platforms. Browser profiling support is limited.
Setup (Node.js)
Enable profiling during SDK initialization:Sampling
Profile Sample Rate
Percentage of sampled transactions to profile:Dynamic Profiling
Dynamically decide which transactions to profile:Continuous Profiling
Continuously profile your application:Integration with Transactions
Profiles are automatically attached to transactions:- Which functions were called during the transaction
- How long each function took
- The call hierarchy
- CPU time distribution
Manual Profiling
Start/Stop Profiler
Most applications should use automatic profiling via
profilesSampleRate rather than manual control.Understanding Profiles
Flame Graphs
Profiles are visualized as flame graphs in Sentry:- Width: Time spent in the function
- Height: Call stack depth
- Color: Different colors for different functions
- Hover: See function details
Profile Data
Each profile includes:Performance Overhead
Profiling has minimal overhead:- Sampling-based: Only captures at intervals (not every function call)
- Efficient: Native code for stack capture
- Configurable: Adjust sample rate to balance detail vs overhead
Typical Overhead
- CPU: 1-5% additional CPU usage
- Memory: ~5-10MB per profile
- Impact: Negligible for most applications
Practical Examples
Express.js API
Background Job
Critical Path Profiling
Analyzing Profiles
Finding Slow Functions
- Look for wide bars: Functions that take a lot of time
- Check self-time: Time spent in the function itself (not children)
- Identify hot paths: Call paths that appear frequently
- Compare with baseline: Look for regressions
Common Issues to Look For
- Synchronous I/O: Blocking operations
- Inefficient algorithms: O(n²) loops
- Unnecessary computation: Repeated calculations
- Large object processing: JSON parsing, serialization
- Deep call stacks: Excessive function calls
Best Practices
- Start with low sample rates: 0.01-0.1 in production
- Profile consistently: Keep profiling enabled
- Compare over time: Look for regressions
- Focus on hot paths: Optimize frequently-called code
- Combine with tracing: Use profiles with performance monitoring
- Monitor overhead: Ensure profiling doesn’t impact users
Profiling vs Other Tools
Profiling vs Tracing
- Tracing: Shows what operations ran and their duration
- Profiling: Shows where time was spent at the code level
Profiling vs Debugging
- Debugging: Step-by-step execution
- Profiling: Statistical sampling in production
Troubleshooting
Profiling Not Working
High Memory Usage
Missing Profiles
Profiles require:- Profiling integration installed
- Transaction sampling enabled
- Profile sampling enabled
- Node.js >= 16.0.0
Platform Support
Node.js
Other Platforms
- Python:
sentry_sdk.profiler - PHP: Native profiling support
- Ruby:
sentry-rubywith profiling - Browser: Limited support (experimental)
Check the platform-specific documentation for profiling setup details.
Next Steps
Performance
Performance monitoring overview
Tracing
Combine profiling with tracing
Spans
Understand span timing
Session Replay
Visual debugging with replay