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

Full DBM propagation for pgx #2711

Open
ewhauser opened this issue May 25, 2024 · 13 comments
Open

Full DBM propagation for pgx #2711

ewhauser opened this issue May 25, 2024 · 13 comments
Assignees
Labels
apm:ecosystem contrib/* related feature requests or bugs proposal/accepted Accepted proposals proposal more in depth change that requires full team approval

Comments

@ewhauser
Copy link

ewhauser commented May 25, 2024

pgx needs support for DBM trace propagation (https://docs.datadoghq.com/database_monitoring/connect_dbm_and_apm/?tab=go) like lib/pq

@ewhauser ewhauser added the enhancement quick change/addition that does not need full team approval label May 25, 2024
@github-actions github-actions bot added the needs-triage New issues that have not yet been triaged label May 25, 2024
@felixge felixge removed the needs-triage New issues that have not yet been triaged label Jun 6, 2024
@felixge
Copy link
Member

felixge commented Jun 6, 2024

👋 Thanks for submitting this and sorry for the delay. I've pinged the internal team owning this, hopefully they'll get to it ASAP.

@rarguelloF
Copy link
Contributor

Hello @ewhauser, thanks for opening an issue!

What instrumentation are you referring to? We currently don't have any instrumentation named dbx.

If your issue is about supporting a new instrumentation, please feel free to open a new issue with more details about your request, including a link to the github repository of the library.

We accept external PRs from external contributors, but if you want us to tackle the work feel free to reach out Datadog Support so we can best prioritize that work!

@rarguelloF rarguelloF added waiting-for-info waiting for answer from issue creator proposal more in depth change that requires full team approval and removed enhancement quick change/addition that does not need full team approval labels Jun 6, 2024
@rarguelloF rarguelloF self-assigned this Jun 6, 2024
@ewhauser ewhauser changed the title Full DBM propagation for dbx Full DBM propagation for pgx Jun 6, 2024
@ewhauser
Copy link
Author

ewhauser commented Jun 6, 2024

Apologies, that was I typo. I updated it to be pgx.

@caseycull
Copy link

caseycull commented Jun 6, 2024

Hi @ewhauser, which DBMS types would you want this for?
(Postgres, MySQL, SQL Server, Oracle)

@ewhauser
Copy link
Author

ewhauser commented Jun 6, 2024

Postgres

@rarguelloF rarguelloF added proposal/accepted Accepted proposals apm:ecosystem contrib/* related feature requests or bugs and removed waiting-for-info waiting for answer from issue creator labels Jun 7, 2024
@doron-cohen
Copy link
Contributor

Hey, correlating queries to traces and seeing calling services in the advanced DB monitoring in Datadog could be really beneficial to us. Is there a plan to support this? Is there a custom way to add a comment to the query so it will be picked up? Thanks

@fcarrero
Copy link

any update about it, it is a great feature for us

@callmemc
Copy link

callmemc commented Sep 4, 2024

Hi @caseycull and @rarguelloF, thanks for getting the ball rolling on this! Any updates you can share? Would also find this really useful. We use Postgres

@taltcher
Copy link

Any update regarding this?

@leszczynskimikolaj
Copy link

any updates on this one?

@rarguelloF
Copy link
Contributor

rarguelloF commented Feb 14, 2025

👋 Sorry for the late reply, and thanks for showing interest in this feature!

We would be interested on implementing this, however there are some limitations from pgx.

Our integration is based on the pgx.QueryTracer interfaces, which don't allow to intercept/modify the query. This is necessary for DBM to work, which uses sqlcommenter to inject comments in queries and correlate those with traces. There's an old issue requesting support for this, but it is closed as not planned.

A workaround that you could use for now, if you are not using any postgres specific functionality, is to use the database/sql interface of pgx (see https://github.com/jackc/pgx/wiki/Getting-started-with-pgx-through-database-sql) and switch to use the dd-trace-go database/sql integration.

Also, I encourage everyone interested in this feature to:

  • Comment on the above issue (or create a new one) in pgx showing your interest in this feature (sqlcommenter support). This would probably require to disable prepared statements when the feature is enabled, which depends on whether @jackc would be interested or not.
  • Create a feature request in Datadog using this form (no login required) - this will help us with prioritization to implement this feature, whether we go with a "pgx native" approach or a custom one (an alternative integration wrapping pgx types).

@doron-cohen
Copy link
Contributor

Hey @rarguelloF thanks for the answer. I am pretty sure we have some way to use sqlcommenter in some hook of our ORM library. Is there an API to dd-trace-go to allow commenting the query with sqlcommenter from the current span? That would actually solve that for us.

@rarguelloF
Copy link
Contributor

@doron-cohen you would need to comment the query itself (which in this case created/managed by pgx) adding information from the span. The limitation of our pgx integration is that is based on the pgx.QueryTracer hooks, which allows us to create and close spans before / after the query is executed, but does not allow to modify them.

What we would need concretely is a way to modify the query after the span is created, but before the query is sent to the server. You can check this code from the database/sql integration to see an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:ecosystem contrib/* related feature requests or bugs proposal/accepted Accepted proposals proposal more in depth change that requires full team approval
Projects
None yet
Development

No branches or pull requests

9 participants