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

fix: support pg tracing in dd-trace-js #10424

Merged
merged 7 commits into from
Oct 28, 2024
Merged

fix: support pg tracing in dd-trace-js #10424

merged 7 commits into from
Oct 28, 2024

Conversation

mattkrick
Copy link
Member

@mattkrick mattkrick commented Oct 28, 2024

Description

dd-trace-js only works by monkeypatching the require statement. https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#bundling
No 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's package.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. Since pg.d.ts already existed in that directory, I had to move it to ./types since pg.ts has nothing to do with pg.d.ts

Copy link
Contributor

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.

Copy link
Contributor

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]>
Copy link
Contributor

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]>
Copy link
Contributor

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]>
@github-actions github-actions bot added size/m and removed size/xl labels Oct 28, 2024
Signed-off-by: Matt Krick <[email protected]>
@mattkrick mattkrick merged commit e963369 into master Oct 28, 2024
6 checks passed
@mattkrick mattkrick deleted the fix/dd-pg branch October 28, 2024 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant