-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node): Add
fsInstrumentation
(#13291)
- Loading branch information
Showing
14 changed files
with
587 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
dev-packages/node-integration-tests/suites/fs-instrumentation/fixtures/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
some-file.txt.* | ||
some-file-promises.txt.* | ||
some-file-promisify.txt.* |
8 changes: 8 additions & 0 deletions
8
...packages/node-integration-tests/suites/fs-instrumentation/fixtures/some-file-promises.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
_____________________________ | ||
< gimme some fs instrumentation > | ||
----------------------------- | ||
\ ^__^ | ||
\ (oo)\_______ | ||
(__)\ )\/\\ | ||
||----w | | ||
|| || |
8 changes: 8 additions & 0 deletions
8
...ackages/node-integration-tests/suites/fs-instrumentation/fixtures/some-file-promisify.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
_____________________________ | ||
< gimme some fs instrumentation > | ||
----------------------------- | ||
\ ^__^ | ||
\ (oo)\_______ | ||
(__)\ )\/\\ | ||
||----w | | ||
|| || |
8 changes: 8 additions & 0 deletions
8
dev-packages/node-integration-tests/suites/fs-instrumentation/fixtures/some-file.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
_____________________________ | ||
< gimme some fs instrumentation > | ||
----------------------------- | ||
\ ^__^ | ||
\ (oo)\_______ | ||
(__)\ )\/\\ | ||
||----w | | ||
|| || |
137 changes: 137 additions & 0 deletions
137
dev-packages/node-integration-tests/suites/fs-instrumentation/server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
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, 'fixtures', 'some-file-that-doesnt-exist.txt'), 'utf-8'); | ||
} catch { | ||
// noop | ||
} | ||
res.send('done'); | ||
}); | ||
|
||
app.get('/readFile', async (_, res) => { | ||
await new Promise<void>(resolve => { | ||
fs.readFile(path.join(__dirname, 'fixtures', 'some-file.txt'), 'utf-8', () => { | ||
resolve(); | ||
}); | ||
}); | ||
await fs.promises.readFile(path.join(__dirname, 'fixtures', 'some-file-promises.txt'), 'utf-8'); | ||
await util.promisify(fs.readFile)(path.join(__dirname, 'fixtures', 'some-file-promisify.txt'), 'utf-8'); | ||
res.send('done'); | ||
}); | ||
|
||
app.get('/copyFile', async (_, res) => { | ||
await new Promise<void>(resolve => { | ||
fs.copyFile( | ||
path.join(__dirname, 'fixtures', 'some-file.txt'), | ||
path.join(__dirname, 'fixtures', 'some-file.txt.copy'), | ||
() => { | ||
resolve(); | ||
}, | ||
); | ||
}); | ||
await fs.promises.copyFile( | ||
path.join(__dirname, 'fixtures', 'some-file-promises.txt'), | ||
path.join(__dirname, 'fixtures', 'some-file-promises.txt.copy'), | ||
); | ||
await util.promisify(fs.copyFile)( | ||
path.join(__dirname, 'fixtures', 'some-file-promisify.txt'), | ||
path.join(__dirname, 'fixtures', 'some-file-promisify.txt.copy'), | ||
); | ||
res.send('done'); | ||
}); | ||
|
||
app.get('/link', async (_, res) => { | ||
await new Promise<void>(resolve => { | ||
fs.link( | ||
path.join(__dirname, 'fixtures', 'some-file.txt'), | ||
path.join(__dirname, 'fixtures', 'some-file.txt.link'), | ||
() => { | ||
resolve(); | ||
}, | ||
); | ||
}); | ||
await fs.promises.link( | ||
path.join(__dirname, 'fixtures', 'some-file-promises.txt'), | ||
path.join(__dirname, 'fixtures', 'some-file-promises.txt.link'), | ||
); | ||
await util.promisify(fs.link)( | ||
path.join(__dirname, 'fixtures', 'some-file-promisify.txt'), | ||
path.join(__dirname, 'fixtures', 'some-file-promisify.txt.link'), | ||
); | ||
|
||
await Promise.all([ | ||
fs.promises.unlink(path.join(__dirname, 'fixtures', 'some-file.txt.link')), | ||
fs.promises.unlink(path.join(__dirname, 'fixtures', 'some-file-promises.txt.link')), | ||
fs.promises.unlink(path.join(__dirname, 'fixtures', 'some-file-promisify.txt.link')), | ||
]); | ||
|
||
res.send('done'); | ||
}); | ||
|
||
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'); | ||
}); | ||
|
||
app.get('/symlink', async (_, res) => { | ||
await new Promise<void>(resolve => { | ||
fs.symlink( | ||
path.join(__dirname, 'fixtures', 'some-file.txt'), | ||
path.join(__dirname, 'fixtures', 'some-file.txt.symlink'), | ||
() => { | ||
resolve(); | ||
}, | ||
); | ||
}); | ||
await fs.promises.symlink( | ||
path.join(__dirname, 'fixtures', 'some-file-promises.txt'), | ||
path.join(__dirname, 'fixtures', 'some-file-promises.txt.symlink'), | ||
); | ||
await util.promisify(fs.symlink)( | ||
path.join(__dirname, 'fixtures', 'some-file-promisify.txt'), | ||
path.join(__dirname, 'fixtures', 'some-file-promisify.txt.symlink'), | ||
); | ||
|
||
await Promise.all([ | ||
fs.promises.unlink(path.join(__dirname, 'fixtures', 'some-file.txt.symlink')), | ||
fs.promises.unlink(path.join(__dirname, 'fixtures', 'some-file-promises.txt.symlink')), | ||
fs.promises.unlink(path.join(__dirname, 'fixtures', 'some-file-promisify.txt.symlink')), | ||
]); | ||
|
||
res.send('done'); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
||
startExpressServerAndSendPortToRunner(app); |
Oops, something went wrong.