Skip to content

Commit 7cd5465

Browse files
authored
feat: Remove Otel from fsIntegration (#21654)
- Closes #20750 This PR doesn't actually use orchestrion. Becuase `fs` in a Node built-in, it is CJS and can therfore be monkey patched like it's 2005.
1 parent 841b3b9 commit 7cd5465

5 files changed

Lines changed: 200 additions & 227 deletions

File tree

dev-packages/node-integration-tests/suites/fs-instrumentation/server.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ app.get('/mkdtemp', async (_, res) => {
103103
res.send('done');
104104
});
105105

106+
app.get('/exists', async (_, res) => {
107+
await new Promise<void>(resolve => {
108+
fs.exists(path.join(__dirname, 'fixtures', 'some-file.txt'), () => {
109+
resolve();
110+
});
111+
});
112+
await util.promisify(fs.exists)(path.join(__dirname, 'fixtures', 'some-file-promisify.txt'));
113+
res.send('done');
114+
});
115+
106116
app.get('/symlink', async (_, res) => {
107117
await new Promise<void>(resolve => {
108118
fs.symlink(

dev-packages/node-integration-tests/suites/fs-instrumentation/test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,42 @@ test('should create spans for fs operations that take target argument', async ()
272272
await runner.completed();
273273
});
274274

275+
test('should create spans for fs.exists callback and promisified versions', async () => {
276+
const runner = createRunner(__dirname, 'server.ts')
277+
.expect({
278+
transaction: {
279+
transaction: 'GET /exists',
280+
spans: expect.arrayContaining([
281+
expect.objectContaining({
282+
description: 'fs.exists',
283+
op: 'file',
284+
status: 'ok',
285+
data: {
286+
path_argument: expect.stringMatching('/fixtures/some-file.txt'),
287+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'file',
288+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.file.fs',
289+
},
290+
}),
291+
expect.objectContaining({
292+
description: 'fs.exists',
293+
op: 'file',
294+
status: 'ok',
295+
data: {
296+
path_argument: expect.stringMatching('/fixtures/some-file-promisify.txt'),
297+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'file',
298+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.file.fs',
299+
},
300+
}),
301+
]),
302+
},
303+
})
304+
.start();
305+
306+
const result = await runner.makeRequest('get', '/exists');
307+
expect(result).toEqual('done');
308+
await runner.completed();
309+
});
310+
275311
test('records file path but not error messages when only `recordFilePaths` is enabled', async () => {
276312
const runner = createRunner(__dirname, 'server-record-paths-only.ts')
277313
.expect({
Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineIntegration } from '@sentry/core';
2-
import { generateInstrumentOnce } from '@sentry/node-core';
3-
import { FsInstrumentation } from './vendored/instrumentation';
2+
import { enableFsInstrumentation } from './vendored/instrumentation';
3+
import type { FsInstrumentationConfig } from './vendored/types';
44

55
const INTEGRATION_NAME = 'FileSystem';
66

@@ -13,36 +13,11 @@ const INTEGRATION_NAME = 'FileSystem';
1313
*
1414
* @param options Configuration for this integration.
1515
*/
16-
export const fsIntegration = defineIntegration(
17-
(
18-
options: {
19-
/**
20-
* Setting this option to `true` will include any filepath arguments from your `fs` API calls as span attributes.
21-
*
22-
* Defaults to `false`.
23-
*/
24-
recordFilePaths?: boolean;
25-
26-
/**
27-
* Setting this option to `true` will include the error messages of failed `fs` API calls as a span attribute.
28-
*
29-
* Defaults to `false`.
30-
*/
31-
recordErrorMessagesAsSpanAttributes?: boolean;
32-
} = {},
33-
) => {
34-
return {
35-
name: INTEGRATION_NAME,
36-
setupOnce() {
37-
generateInstrumentOnce(
38-
INTEGRATION_NAME,
39-
() =>
40-
new FsInstrumentation({
41-
recordFilePaths: options.recordFilePaths,
42-
recordErrorMessagesAsSpanAttributes: options.recordErrorMessagesAsSpanAttributes,
43-
}),
44-
)();
45-
},
46-
};
47-
},
48-
);
16+
export const fsIntegration = defineIntegration((options: FsInstrumentationConfig = {}) => {
17+
return {
18+
name: INTEGRATION_NAME,
19+
setupOnce() {
20+
enableFsInstrumentation(options);
21+
},
22+
};
23+
});

0 commit comments

Comments
 (0)