-
Notifications
You must be signed in to change notification settings - Fork 336
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
fix: support pg tracing in dd-trace-js #10424
Conversation
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick <[email protected]>
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR will be delayed and might be rejected due to its size. |
Signed-off-by: Matt Krick <[email protected]>
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR will be delayed and might be rejected due to its size. |
Signed-off-by: Matt Krick <[email protected]>
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR will be delayed and might be rejected due to its size. |
Signed-off-by: Matt Krick <[email protected]>
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR will be delayed and might be rejected due to its size. |
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick <[email protected]>
Description
dd-trace-js only works by monkeypatching the
require
statement. https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#bundlingNo shade to the authors, but it's really hacky & there's no workaround.
That means if we want tracing for PG, we need a native
require
statement in our webpack bundle.We could exclude
pg
from the bundle, but that means we'd have to ship the entirety of node_modules, adding gigabytes to our docker image.We have to include all of node_modules because pg has dependencies that must also be included. And those dependencies have dependencies, and it's turtles all the way down.
The solution in this PR bundles pg and all its dependencies into a single file and outputs it to
/dist/node_modules/pg/lib/index.js
, alongside pg'spackage.json
. In doing so, we're tricking dd-trace-js into thinking that our custom pg entrypoint is actually a node module. The result is an extra entrypoint, but no increase in this size of the output. In development,require('pg')
resolves to./pg.ts
, so there is no change.Since we use
require('pg')
,pg.ts
must exist in the same directory. Sincepg.d.ts
already existed in that directory, I had to move it to./types
sincepg.ts
has nothing to do withpg.d.ts