fix(application-generic): improve LaunchDarkly client initialization and error handling#10392
fix(application-generic): improve LaunchDarkly client initialization and error handling#10392
Conversation
…and error handling
✅ Deploy Preview for dashboard-v2-novu-staging canceled.
|
|
Hey there and thank you for opening this pull request! 👋 We require pull request titles to follow specific formatting rules and it looks like your proposed title needs to be adjusted. Your PR title is: Requirements:
Expected format: Details: PR title must end with 'fixes TICKET-ID' (e.g., 'fixes NOV-123') or include ticket ID in branch name |
📝 WalkthroughWalkthroughModified the LaunchDarkly feature flags service to improve initialization error handling and resilience. Added try/catch exception handling during SDK initialization, set Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| if (!launchDarklySdkKey) { | ||
| throw new Error('Missing Launch Darkly SDK key'); | ||
| try { | ||
| this.client = init(process.env.LAUNCH_DARKLY_SDK_KEY as string); |
There was a problem hiding this comment.
Checking for SDK Key is dead code. Already handled here ->
| import type { FeatureFlagContext, FeatureFlagContextBase, IFeatureFlagsService } from './types'; | ||
|
|
||
| const LOG_CONTEXT = 'LaunchDarklyFeatureFlagsService'; | ||
| const INITIALIZATION_TIMEOUT_SECONDS = 10; |
There was a problem hiding this comment.
LaunchDarkly timeout is in seconds. We were waiting 2.7 hours. Now SDK will retry in 10 seconds.
What changed
The LaunchDarkly feature flags service was refactored to improve error resilience and initialization handling. Instead of throwing errors when the LaunchDarkly client fails to initialize, the service now logs the error and gracefully degrades by using default flag values. The initialization status is tracked via an
isEnabledflag that starts asfalseand is only set totrueafter successful initialization, with a configurable 10-second timeout.Affected areas
application-generic: Updated the LaunchDarkly feature flags service to handle initialization failures gracefully, logging errors without throwing and allowing the system to fall back to default values when the service is unavailable.
Key technical decisions
INITIALIZATION_TIMEOUT_SECONDSconstant (10 seconds) to replace hard-coded timeout value, making the initialization timeout configurable.getFlag()to immediately return default values whenisEnabledis false, avoiding unnecessary client calls.Testing
No new tests were mentioned in the PR. Testing should verify that the service gracefully handles missing or invalid SDK keys, that initialization failures are logged appropriately, and that flag checks return default values when the service is disabled.
Screenshots
Expand for optional sections
Related enterprise PR
Special notes for your reviewer