-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(node): Add integration test for Postgres auto-instrumentation. #4804
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
Merged
AbhiPrasad
merged 3 commits into
master
from
onur/node-int-tests-postgres-auto-instrument
Mar 28, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
26 changes: 26 additions & 0 deletions
26
packages/node-integration-tests/suites/tracing/auto-instrument/pg/scenario.ts
This file contains hidden or 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,26 @@ | ||
import '@sentry/tracing'; | ||
|
||
import * as Sentry from '@sentry/node'; | ||
import pg from 'pg'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
const transaction = Sentry.startTransaction({ | ||
op: 'transaction', | ||
name: 'Test Transaction', | ||
}); | ||
|
||
Sentry.configureScope(scope => { | ||
scope.setSpan(transaction); | ||
}); | ||
|
||
const client = new pg.Client(); | ||
client.query('SELECT * FROM foo where bar ilike "baz%"', ['a', 'b'], () => | ||
client.query('SELECT * FROM bazz', () => { | ||
client.query('SELECT NOW()', () => transaction.finish()); | ||
}), | ||
); |
54 changes: 54 additions & 0 deletions
54
packages/node-integration-tests/suites/tracing/auto-instrument/pg/test.ts
This file contains hidden or 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,54 @@ | ||
import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../../utils'; | ||
|
||
class PgClient { | ||
// https://node-postgres.com/api/client#clientquery | ||
public query(_text: unknown, values: unknown, callback?: () => void) { | ||
if (typeof callback === 'function') { | ||
callback(); | ||
return; | ||
} | ||
|
||
if (typeof values === 'function') { | ||
values(); | ||
return; | ||
} | ||
|
||
return Promise.resolve(); | ||
} | ||
} | ||
|
||
beforeAll(() => { | ||
jest.mock('pg', () => { | ||
return { | ||
Client: PgClient, | ||
native: { | ||
Client: PgClient, | ||
}, | ||
}; | ||
}); | ||
}); | ||
|
||
test('should auto-instrument `pg` package.', async () => { | ||
const url = await runServer(__dirname); | ||
const envelope = await getEnvelopeRequest(url); | ||
|
||
expect(envelope).toHaveLength(3); | ||
|
||
assertSentryTransaction(envelope[2], { | ||
transaction: 'Test Transaction', | ||
spans: [ | ||
{ | ||
description: 'SELECT * FROM foo where bar ilike "baz%"', | ||
op: 'db', | ||
}, | ||
{ | ||
description: 'SELECT * FROM bazz', | ||
op: 'db', | ||
}, | ||
{ | ||
description: 'SELECT NOW()', | ||
op: 'db', | ||
}, | ||
], | ||
}); | ||
}); |
This file contains hidden or 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 |
---|---|---|
|
@@ -3842,6 +3842,15 @@ | |
resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-6.0.0.tgz#38590dc2c3cf5717154064e3ee9b6947ee21b299" | ||
integrity sha512-oPwPSj4a1wu9rsXTEGIJz91ISU725t0BmSnUhb57sI+M8XEmvUop84lzuiYdq0Y5M6xLY8DBPg0C2xEQKLyvBA== | ||
|
||
"@types/pg@^8.6.5": | ||
version "8.6.5" | ||
resolved "https://registry.yarnpkg.com/@types/pg/-/pg-8.6.5.tgz#2dce9cb468a6a5e0f1296a59aea3ac75dd27b702" | ||
integrity sha512-tOkGtAqRVkHa/PVZicq67zuujI4Oorfglsr2IbKofDwBSysnaqSx7W1mDqFqdkGE6Fbgh+PZAl0r/BWON/mozw== | ||
dependencies: | ||
"@types/node" "*" | ||
pg-protocol "*" | ||
pg-types "^2.2.0" | ||
|
||
"@types/prop-types@*": | ||
version "15.7.3" | ||
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7" | ||
|
@@ -6841,6 +6850,11 @@ [email protected], buffer-from@^1.0.0: | |
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef" | ||
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A== | ||
|
||
[email protected]: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/buffer-writer/-/buffer-writer-2.0.0.tgz#ce7eb81a38f7829db09c873f2fbb792c0c98ec04" | ||
integrity sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw== | ||
|
||
buffer-xor@^1.0.3: | ||
version "1.0.3" | ||
resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9" | ||
|
@@ -16727,6 +16741,11 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/package-name-regex/-/package-name-regex-2.0.5.tgz#5e3548ffe3dba340b9779d28a024bdb4a19f055b" | ||
integrity sha512-F0lX+FBs/Bo7KWY6EuUXj+oarXU0Og1R2Zdg3F/fVcNw3pPQAKFKxUrugno0Ds5NUztlx/gRLnQW9MF+7VTqAw== | ||
|
||
[email protected]: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/packet-reader/-/packet-reader-1.0.0.tgz#9238e5480dedabacfe1fe3f2771063f164157d74" | ||
integrity sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ== | ||
|
||
pacote@^9.5.0: | ||
version "9.5.12" | ||
resolved "https://registry.yarnpkg.com/pacote/-/pacote-9.5.12.tgz#1e11dd7a8d736bcc36b375a9804d41bb0377bf66" | ||
|
@@ -17074,6 +17093,57 @@ performance-now@^2.1.0: | |
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" | ||
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= | ||
|
||
pg-connection-string@^2.5.0: | ||
version "2.5.0" | ||
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.5.0.tgz#538cadd0f7e603fc09a12590f3b8a452c2c0cf34" | ||
integrity sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ== | ||
|
||
[email protected]: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/pg-int8/-/pg-int8-1.0.1.tgz#943bd463bf5b71b4170115f80f8efc9a0c0eb78c" | ||
integrity sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw== | ||
|
||
pg-pool@^3.5.1: | ||
version "3.5.1" | ||
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-3.5.1.tgz#f499ce76f9bf5097488b3b83b19861f28e4ed905" | ||
integrity sha512-6iCR0wVrro6OOHFsyavV+i6KYL4lVNyYAB9RD18w66xSzN+d8b66HiwuP30Gp1SH5O9T82fckkzsRjlrhD0ioQ== | ||
|
||
pg-protocol@*, pg-protocol@^1.5.0: | ||
version "1.5.0" | ||
resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.5.0.tgz#b5dd452257314565e2d54ab3c132adc46565a6a0" | ||
integrity sha512-muRttij7H8TqRNu/DxrAJQITO4Ac7RmX3Klyr/9mJEOBeIpgnF8f9jAfRz5d3XwQZl5qBjF9gLsUtMPJE0vezQ== | ||
|
||
pg-types@^2.1.0, pg-types@^2.2.0: | ||
version "2.2.0" | ||
resolved "https://registry.yarnpkg.com/pg-types/-/pg-types-2.2.0.tgz#2d0250d636454f7cfa3b6ae0382fdfa8063254a3" | ||
integrity sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA== | ||
dependencies: | ||
pg-int8 "1.0.1" | ||
postgres-array "~2.0.0" | ||
postgres-bytea "~1.0.0" | ||
postgres-date "~1.0.4" | ||
postgres-interval "^1.1.0" | ||
|
||
pg@^8.7.3: | ||
version "8.7.3" | ||
resolved "https://registry.yarnpkg.com/pg/-/pg-8.7.3.tgz#8a5bdd664ca4fda4db7997ec634c6e5455b27c44" | ||
integrity sha512-HPmH4GH4H3AOprDJOazoIcpI49XFsHCe8xlrjHkWiapdbHK+HLtbm/GQzXYAZwmPju/kzKhjaSfMACG+8cgJcw== | ||
dependencies: | ||
buffer-writer "2.0.0" | ||
packet-reader "1.0.0" | ||
pg-connection-string "^2.5.0" | ||
pg-pool "^3.5.1" | ||
pg-protocol "^1.5.0" | ||
pg-types "^2.1.0" | ||
pgpass "1.x" | ||
|
||
[email protected]: | ||
version "1.0.5" | ||
resolved "https://registry.yarnpkg.com/pgpass/-/pgpass-1.0.5.tgz#9b873e4a564bb10fa7a7dbd55312728d422a223d" | ||
integrity sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug== | ||
dependencies: | ||
split2 "^4.1.0" | ||
|
||
picocolors@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" | ||
|
@@ -17617,6 +17687,28 @@ postcss@^8.2.15: | |
picocolors "^1.0.0" | ||
source-map-js "^1.0.1" | ||
|
||
postgres-array@~2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/postgres-array/-/postgres-array-2.0.0.tgz#48f8fce054fbc69671999329b8834b772652d82e" | ||
integrity sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA== | ||
|
||
postgres-bytea@~1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/postgres-bytea/-/postgres-bytea-1.0.0.tgz#027b533c0aa890e26d172d47cf9ccecc521acd35" | ||
integrity sha1-AntTPAqokOJtFy1Hz5zOzFIazTU= | ||
|
||
postgres-date@~1.0.4: | ||
version "1.0.7" | ||
resolved "https://registry.yarnpkg.com/postgres-date/-/postgres-date-1.0.7.tgz#51bc086006005e5061c591cee727f2531bf641a8" | ||
integrity sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q== | ||
|
||
postgres-interval@^1.1.0: | ||
version "1.2.0" | ||
resolved "https://registry.yarnpkg.com/postgres-interval/-/postgres-interval-1.2.0.tgz#b460c82cb1587507788819a06aa0fffdb3544695" | ||
integrity sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ== | ||
dependencies: | ||
xtend "^4.0.0" | ||
|
||
precinct@^7.0.0: | ||
version "7.1.0" | ||
resolved "https://registry.yarnpkg.com/precinct/-/precinct-7.1.0.tgz#a0311e0b59029647eaf57c2d30b8efa9c85d129a" | ||
|
@@ -19920,6 +20012,11 @@ split2@^3.0.0: | |
dependencies: | ||
readable-stream "^3.0.0" | ||
|
||
split2@^4.1.0: | ||
version "4.1.0" | ||
resolved "https://registry.yarnpkg.com/split2/-/split2-4.1.0.tgz#101907a24370f85bb782f08adaabe4e281ecf809" | ||
integrity sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ== | ||
|
||
[email protected]: | ||
version "0.3.3" | ||
resolved "https://registry.yarnpkg.com/split/-/split-0.3.3.tgz#cd0eea5e63a211dfff7eb0f091c4133e2d0dd28f" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we assert a proper parent-child relationship between the spans?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked again and looks like these are not really nested queries, just serialized. So, each is a child of the main transaction. Sub-queries seem to be handled on query level, and our integration is not covering it.