Skip to main content
Profiling captures code-level performance data, helping you identify which functions are consuming the most CPU time and where optimization efforts should be focused.

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:
Profiling requires Node.js 16.0.0 or higher and the @sentry/profiling-node package.

Sampling

Profile Sample Rate

Percentage of sampled transactions to profile:

Dynamic Profiling

Dynamically decide which transactions to profile:
In production, use lower profile sample rates (0.01-0.1) to reduce overhead while still collecting useful data.

Continuous Profiling

Continuously profile your application:

Integration with Transactions

Profiles are automatically attached to transactions:
The profile shows:
  • 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

  1. Look for wide bars: Functions that take a lot of time
  2. Check self-time: Time spent in the function itself (not children)
  3. Identify hot paths: Call paths that appear frequently
  4. 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

  1. Start with low sample rates: 0.01-0.1 in production
  2. Profile consistently: Keep profiling enabled
  3. Compare over time: Look for regressions
  4. Focus on hot paths: Optimize frequently-called code
  5. Combine with tracing: Use profiles with performance monitoring
  6. 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:
  1. Profiling integration installed
  2. Transaction sampling enabled
  3. Profile sampling enabled
  4. Node.js >= 16.0.0

Platform Support

Node.js

Other Platforms

  • Python: sentry_sdk.profiler
  • PHP: Native profiling support
  • Ruby: sentry-ruby with 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