Skip to content

fix(application-generic): improve LaunchDarkly client initialization and error handling#10392

Open
merrcury wants to merge 1 commit intonextfrom
fix/LDTimeout
Open

fix(application-generic): improve LaunchDarkly client initialization and error handling#10392
merrcury wants to merge 1 commit intonextfrom
fix/LDTimeout

Conversation

@merrcury
Copy link
Copy Markdown
Member

@merrcury merrcury commented Mar 19, 2026

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 isEnabled flag that starts as false and is only set to true after 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

  • Changed error handling strategy from throwing exceptions to logging errors and gracefully degrading — when LaunchDarkly fails to initialize, the service continues operation and returns default values for all flag checks instead of crashing.
  • Introduced INITIALIZATION_TIMEOUT_SECONDS constant (10 seconds) to replace hard-coded timeout value, making the initialization timeout configurable.
  • Added early exit in getFlag() to immediately return default values when isEnabled is 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

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 19, 2026

Deploy Preview for dashboard-v2-novu-staging canceled.

Name Link
🔨 Latest commit 5f8eab7
🔍 Latest deploy log https://app.netlify.com/projects/dashboard-v2-novu-staging/deploys/69bba68df19cd6000844e7d4

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 19, 2026

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: fix(application-generic): improve LaunchDarkly client initialization and error handling

Requirements:

  1. Follow the Conventional Commits specification
  2. As a team member, include Linear ticket ID at the end: fixes TICKET-ID or include it in your branch name

Expected format: feat(scope): Add fancy new feature fixes NOV-123

Details:

PR title must end with 'fixes TICKET-ID' (e.g., 'fixes NOV-123') or include ticket ID in branch name

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 19, 2026

📝 Walkthrough

Walkthrough

Modified the LaunchDarkly feature flags service to improve initialization error handling and resilience. Added try/catch exception handling during SDK initialization, set isEnabled to false by default, and implemented short-circuit logic in getFlag() to return default values when the service is disabled.

Changes

Cohort / File(s) Summary
LaunchDarkly Service Initialization
libs/application-generic/src/services/feature-flags/launch-darkly.service.ts
Added logging context and timeout constants; changed isEnabled to initialize as false; wrapped initialization in try/catch to gracefully handle missing SDK key and initialization failures without throwing; updated getFlag() to short-circuit when service is disabled.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title follows the Conventional Commits format with a valid type (fix), valid scope (application-generic), and a clear, descriptive message that accurately reflects the main changes in the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

if (!launchDarklySdkKey) {
throw new Error('Missing Launch Darkly SDK key');
try {
this.client = init(process.env.LAUNCH_DARKLY_SDK_KEY as string);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for SDK Key is dead code. Already handled here ->

public async initialize(): Promise<void> {
const Service = process.env.LAUNCH_DARKLY_SDK_KEY ? LaunchDarklyFeatureFlagsService : ProcessEnvFeatureFlagsService;
this.service = new Service();

@merrcury merrcury requested a review from scopsy March 19, 2026 07:34
import type { FeatureFlagContext, FeatureFlagContextBase, IFeatureFlagsService } from './types';

const LOG_CONTEXT = 'LaunchDarklyFeatureFlagsService';
const INITIALIZATION_TIMEOUT_SECONDS = 10;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LaunchDarkly timeout is in seconds. We were waiting 2.7 hours. Now SDK will retry in 10 seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant