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

chore: Use tracing's fields to get structured logs #2373

Conversation

jaysonsantos
Copy link
Contributor

@jaysonsantos jaysonsantos commented Feb 24, 2023

This also enables on services that can query this data to get useful metrics.
Also note that I chose db.statement to having a standard to follow even though this does not use opentelemetry, but the latter can benefit from it [1].

Running the tests with that would log something like this:

[2023-02-24T17:14:00Z INFO  sqlx::query] summary="select 1 as \"foo?\"" db.statement="" rows_affected=0 rows_returned=1 elapsed=24.75µs sql=""
[2023-02-24T17:14:00Z INFO  sqlx::query] summary="select 1 as \"foo: …" db.statement="\n\nselect\n  1 as \"foo: MyInt\"\n" rows_affected=0 rows_returned=1 elapsed=44.5µs sql="\n\nselect\n  1 as \"foo: MyInt\"\n"
[2023-02-24T17:14:00Z INFO  sqlx::query] summary="select 1 as \"foo?: …" db.statement="\n\nselect\n  1 as \"foo?: MyInt\"\n" rows_affected=0 rows_returned=1 elapsed=26.208µs sql="\n\nselect\n  1 as \"foo?: MyInt\"\n"
[2023-02-24T17:14:00Z INFO  sqlx::query] summary="select 1 as \"foo!: …" db.statement="\n\nselect\n  1 as \"foo!: MyInt\"\n" rows_affected=0 rows_returned=1 elapsed=22.625µs sql="\n\nselect\n  1 as \"foo!: MyInt\"\n"

[1] https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/database/#call-level-attributes

This also enables on services that can query this data to get useful metrics
@jaysonsantos jaysonsantos force-pushed the use-tracings-fields-for-logged-queries branch from 4807087 to 7daa9ea Compare February 24, 2023 17:25
@abonander abonander merged commit 82ff8d9 into launchbadge:main Mar 3, 2023
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

Successfully merging this pull request may close these issues.

2 participants