Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node): Add fsInstrumentation #13291

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
some-file.txt.copy
Copy link
Member

Choose a reason for hiding this comment

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

Can we just make this: some-file.txt.* ?

Copy link
Member

Choose a reason for hiding this comment

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

and maybe move them out of the root of the package, into e.g. fixtures/ or something like this?

some-file-promises.txt.copy
some-file-promisify.txt.copy

some-file.txt.link
some-file-promises.txt.link
some-file-promisify.txt.link

some-file.txt.symlink
some-file-promises.txt.symlink
some-file-promisify.txt.symlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
transport: loggingTransport,
tracesSampleRate: 1,
integrations: [
Sentry.fsIntegration({
recordFilePaths: true,
recordErrorMessagesAsSpanAttributes: true,
}),
],
});

import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as util from 'util';
import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import express from 'express';

const app = express();

app.get('/readFile-error', async (_, res) => {
try {
await fs.promises.readFile(path.join(__dirname, 'some-file-that-doesnt-exist.txt'), 'utf-8');
} catch {
// noop
}
res.send('done');
});
Fixed Show fixed Hide fixed

app.get('/readFile', async (_, res) => {
await new Promise<void>(resolve => {
fs.readFile(path.join(__dirname, 'some-file.txt'), 'utf-8', () => {
resolve();
});
});
await fs.promises.readFile(path.join(__dirname, 'some-file-promises.txt'), 'utf-8');
await util.promisify(fs.readFile)(path.join(__dirname, 'some-file-promisify.txt'), 'utf-8');
res.send('done');
});
Dismissed Show dismissed Hide dismissed

app.get('/copyFile', async (_, res) => {
await new Promise<void>(resolve => {
fs.copyFile(path.join(__dirname, 'some-file.txt'), path.join(__dirname, 'some-file.txt.copy'), () => {
resolve();
});
});
await fs.promises.copyFile(
path.join(__dirname, 'some-file-promises.txt'),
path.join(__dirname, 'some-file-promises.txt.copy'),
);
await util.promisify(fs.copyFile)(
path.join(__dirname, 'some-file-promisify.txt'),
path.join(__dirname, 'some-file-promisify.txt.copy'),
);
res.send('done');
});
Fixed Show fixed Hide fixed

app.get('/link', async (_, res) => {
await new Promise<void>(resolve => {
fs.link(path.join(__dirname, 'some-file.txt'), path.join(__dirname, 'some-file.txt.link'), () => {
resolve();
});
});
await fs.promises.link(
path.join(__dirname, 'some-file-promises.txt'),
path.join(__dirname, 'some-file-promises.txt.link'),
);
await util.promisify(fs.link)(
path.join(__dirname, 'some-file-promisify.txt'),
path.join(__dirname, 'some-file-promisify.txt.link'),
);

await Promise.all([
fs.promises.unlink(path.join(__dirname, 'some-file.txt.link')),
fs.promises.unlink(path.join(__dirname, 'some-file-promises.txt.link')),
fs.promises.unlink(path.join(__dirname, 'some-file-promisify.txt.link')),
]);

res.send('done');
});
Fixed Show fixed Hide fixed

app.get('/mkdtemp', async (_, res) => {
await new Promise<void>(resolve => {
fs.mkdtemp(path.join(os.tmpdir(), 'foo-'), () => {
resolve();
});
});
await fs.promises.mkdtemp(path.join(os.tmpdir(), 'foo-'));
await util.promisify(fs.mkdtemp)(path.join(os.tmpdir(), 'foo-'));

res.send('done');
});
Dismissed Show dismissed Hide dismissed

app.get('/symlink', async (_, res) => {
await new Promise<void>(resolve => {
fs.symlink(path.join(__dirname, 'some-file.txt'), path.join(__dirname, 'some-file.txt.symlink'), () => {
resolve();
});
});
await fs.promises.symlink(
path.join(__dirname, 'some-file-promises.txt'),
path.join(__dirname, 'some-file-promises.txt.symlink'),
);
await util.promisify(fs.symlink)(
path.join(__dirname, 'some-file-promisify.txt'),
path.join(__dirname, 'some-file-promisify.txt.symlink'),
);

await Promise.all([
fs.promises.unlink(path.join(__dirname, 'some-file.txt.symlink')),
fs.promises.unlink(path.join(__dirname, 'some-file-promises.txt.symlink')),
fs.promises.unlink(path.join(__dirname, 'some-file-promisify.txt.symlink')),
]);

res.send('done');
});
Fixed Show fixed Hide fixed

Sentry.setupExpressErrorHandler(app);

startExpressServerAndSendPortToRunner(app);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_____________________________
< gimme some fs instrumentation >
-----------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\\
||----w |
|| ||
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_____________________________
< gimme some fs instrumentation >
-----------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\\
||----w |
|| ||
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_____________________________
< gimme some fs instrumentation >
-----------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\\
||----w |
|| ||
Loading
Loading