Skip to content

Conversation

JealousGx
Copy link

This commit addresses an issue where local variables were not being captured for out-of-app frames.

The localVariablesSyncIntegration had a race condition where it would process events before the debugger session was fully initialized. This was fixed by awaiting the session creation in setupOnce.

Additionally, this PR adds tests for the localVariablesAsyncIntegration to ensure it correctly handles the includeOutOfAppFrames option.

--
Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • [] Ensure your code lints and the test suite passes (yarn lint) & (yarn test): The tests fail Error: Failed to resolve entry for package "@sentry/browser". The package may have incorrect main/module/exports specified in its package.json.

…etsentry#12588)

This commit addresses an issue where local variables were not being captured for out-of-app frames, even when the `includeOutOfAppFrames` option was enabled.

The `localVariablesSyncIntegration` had a race condition where it would process events before the debugger session was fully initialized. This was fixed by awaiting the session creation in `setupOnce`.

The tests for this integration were failing because they were not setting up a Sentry client, which is required for the integration to be enabled. This has been corrected by adding a client to the test setup.

Additionally, this commit adds tests for the `localVariablesAsyncIntegration` to ensure it correctly handles the `includeOutOfAppFrames` option.
cursor[bot]

This comment was marked as outdated.

Comment on lines 294 to 295
return {
name: INTEGRATION_NAME,
Copy link

Choose a reason for hiding this comment

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

Potential bug: Changing setupOnce to async violates the integration interface contract. The framework calls it synchronously, reintroducing a race condition where events are silently ignored during initialization.
  • Description: The Integration interface defines setupOnce as a synchronous method, but it was changed to be async. The integration framework calls this method without await, causing the initialization logic inside to run in the background. While this async operation is pending, a shouldProcessEvent flag remains false. Consequently, any events received by processEvent during this startup window are silently ignored instead of being processed. This reintroduces the exact race condition the change was intended to fix, causing the integration to silently fail to capture variables for an indeterminate period.

  • Suggested fix: Revert setupOnce to a synchronous function to adhere to the interface contract. If asynchronous initialization is required, consider an alternative approach, such as queuing events within the integration until the async setup is complete, rather than making the setupOnce hook itself asynchronous.
    severity: 0.85, confidence: 0.98

Did we get this right? 👍 / 👎 to inform future reviews.

The `LocalVariables` integrations `setupOnce` method was `async`, which violates the `Integration` interface. This caused a race condition where events could be processed before the integration was fully initialized, leading to missed local variables.

This commit fixes the race condition by:
- Making `setupOnce` synchronous to adhere to the interface contract.
- Moving the asynchronous initialization logic to a separate `setup` function.
- Making `processEvent` asynchronous and awaiting the result of the `setup` function, ensuring that the integration is fully initialized before processing any events.
- Updating the tests to correctly `await` the `processEvent` method.
@mydea mydea changed the title Fix local variables capturing for out-of-app frames fix(node): Fix local variables capturing for out-of-app frames Sep 8, 2025
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