Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions packages/node/src/integrations/fs/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { defineIntegration } from '@sentry/core';
import { generateInstrumentOnce } from '@sentry/node-core';
import { FsInstrumentation } from './vendored/instrumentation';
import { enableFsInstrumentation } from './vendored/instrumentation';

const INTEGRATION_NAME = 'FileSystem';

let _isEnabled = false;

/**
* This integration will create spans for `fs` API operations, like reading and writing files.
*
Expand All @@ -16,6 +17,11 @@ const INTEGRATION_NAME = 'FileSystem';
export const fsIntegration = defineIntegration(
(
options: {
/**
* Whether to enable the plugin.
* @default true
*/
enabled?: boolean;
/**
* Setting this option to `true` will include any filepath arguments from your `fs` API calls as span attributes.
*
Expand All @@ -34,14 +40,10 @@ export const fsIntegration = defineIntegration(
return {
name: INTEGRATION_NAME,
setupOnce() {
generateInstrumentOnce(
INTEGRATION_NAME,
() =>
new FsInstrumentation({
recordFilePaths: options.recordFilePaths,
recordErrorMessagesAsSpanAttributes: options.recordErrorMessagesAsSpanAttributes,
}),
)();
if (options.enabled === false) return;
if (_isEnabled) return;
_isEnabled = true;
Comment on lines +43 to +45

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: If fsIntegration is initialized with { enabled: false }, subsequent calls to enable it will fail because setupOnce is not re-executed.
Severity: HIGH

Suggested Fix

The logic in setupOnce should be adjusted to handle re-enabling. Instead of just checking if the integration is installed, it should also check if it's currently enabled. If it's installed but disabled, the setup logic should proceed to enable it. Alternatively, do not add the integration to installedIntegrations if it's being initialized as disabled.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/node/src/integrations/fs/index.ts#L43-L45

Potential issue: When `fsIntegration({ enabled: false })` is called, the integration is
marked as installed but returns early before instrumentation is applied. Because the
integration name is now in `installedIntegrations`, any subsequent call to
`fsIntegration()` (e.g., with the default `enabled: true`) will not re-run `setupOnce`.
This prevents `enableFsInstrumentation` from ever being called, permanently disabling
`fs` instrumentation for the application's lifecycle.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The same issue existed with the previous iteration on the intrumentation

enableFsInstrumentation(options);
},
};
},
Expand Down
Loading
Loading