| 1 | /** |
| 2 | * Optional profiling integration loader |
| 3 | * This module handles the optional @sentry/profiling-node dependency |
| 4 | * which contains native bindings and may not be available in all environments |
| 5 | */ |
| 6 | |
| 7 | let profilingIntegration: any = null; |
| 8 | let profilingLoadAttempted = false; |
| 9 | |
| 10 | /** |
| 11 | * Lazy load the profiling integration |
| 12 | */ |
| 13 | async function loadProfilingIntegration() { |
| 14 | if (profilingLoadAttempted) { |
| 15 | return profilingIntegration; |
| 16 | } |
| 17 | |
| 18 | profilingLoadAttempted = true; |
| 19 | |
| 20 | try { |
| 21 | // Try to load the native profiling module if available |
| 22 | const profilingModule = await import("@sentry/profiling-node"); |
| 23 | profilingIntegration = profilingModule.nodeProfilingIntegration; |
| 24 | } catch { |
| 25 | // Profiling module not available - this is fine, profiling is optional |
| 26 | // The CLI will work without it, just without performance profiling |
| 27 | } |
| 28 | |
| 29 | return profilingIntegration; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Returns the profiling integration if available, or a no-op function |
| 34 | * Note: This is now async to handle lazy loading |
| 35 | */ |
| 36 | export async function getProfilingIntegration() { |
| 37 | const integration = await loadProfilingIntegration(); |
| 38 | if (integration) { |
| 39 | return integration(); |
| 40 | } |
| 41 | // Return empty object as a no-op integration |
| 42 | return {}; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Check if profiling is available |
| 47 | * Note: This is now async to handle lazy loading |
| 48 | */ |
| 49 | export async function isProfilingAvailable(): Promise<boolean> { |
| 50 | await loadProfilingIntegration(); |
| 51 | return profilingIntegration !== null; |
| 52 | } |