dd-trace-go
dd-trace-go copied to clipboard
Full DBM propagation for pgx
pgx needs support for DBM trace propagation (https://docs.datadoghq.com/database_monitoring/connect_dbm_and_apm/?tab=go) like lib/pq
👋 Thanks for submitting this and sorry for the delay. I've pinged the internal team owning this, hopefully they'll get to it ASAP.
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!
Apologies, that was I typo. I updated it to be pgx.
Hi @ewhauser, which DBMS types would you want this for? (Postgres, MySQL, SQL Server, Oracle)
Postgres
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
any update about it, it is a great feature for us
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
Any update regarding this?
any updates on this one?
👋 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).
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.
@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.
@rarguelloF pgx supports adding QueryRewriter interface which gets passed as an arg. RewriteQuery is called after TraceQueryEnd as seen here so you could create a wrapper for pgx.Conn that inserts a QueryRewriter that injects trace information as the first arg to method calls to the underlying pgx.Conn
@rarguelloF @ennyjfrick any update about it ?