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

Feature Request: Support SqlComemnter #39

Open
StevenACoffman opened this issue Jul 28, 2024 · 2 comments
Open

Feature Request: Support SqlComemnter #39

StevenACoffman opened this issue Jul 28, 2024 · 2 comments

Comments

@StevenACoffman
Copy link

A while back, OTEL merged SqlCommenter (seeSqlCommenter merged into OpenTelemetry).

SqlCommenter works on the driver/ORM layer, by injecting metadata containing comments as part of the SQL statements sent to the database. These logs are then ingested on the database side (with support from Cloud SQL Insights, a proprietary Google Cloud offering). I am not aware of OSS solutions that do this ingestion and expose this data to the user yet, but I'm sure with this becoming part of otel we will begin seeing something like that.

I would like otelpgx to add the de facto standardized fields traceparent and tracestate to the SQL as comments sent to the database. For example:

select * from widgets /*traceparent='00-5bd66ef5095369c7b0d1f8f4bd33716a-c532cb4098ac3dd2-01',tracestate='congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7'*/

I want to be able to use both Cloud SQL Insights and Cloud Trace in my application, and I think otelpgx could do it for me.

Currently, XSAM/otelsql offers this as an experimental feature.
WithSQLCommenter will enable or disable context propagation for the database by injecting a comment into SQL statements.

e.g., a SQL query:

SELECT * from FOO

will become

SELECT * from FOO /*traceparent='00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01',tracestate='congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7'*/
@StevenACoffman
Copy link
Author

Also worth mentioning that https://github.com/jbub/sqlcommenter allows sqlcommeter support for pgx driver.

@mfrister
Copy link
Contributor

In addition to cloud services supporting this directly, this would also be useful for self-managed Postgres instances to associate queries in Postgres server logs (e.g. for deadlocks and slow queries) with traces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants