-
Notifications
You must be signed in to change notification settings - Fork 172
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
PG instrumentation does not parse quoted table names in queries into the 'db.collection.name' attribute #1173
Comments
Hi @mostfunkyduck! Thank you submitting this issue and sharing what you did to get things working properly. Would you be interested in making a contribution? For testing, the file {
"name": "table_name_with_single_quotes",
"sql": "SELECT columns FROM 'test_table'"
},
{
"name": "table_name_with_double_quotes",
"sql": "SELECT columns FROM \"test_table\""
} For the updated regex, is it desirable to include the quotes in the end result? Your suggestion would take care of this (although could be updated to recognize single quotes too). If we don't want to include the quotes, and to account for both single and double quotes, we could do: TABLE_NAME = /\b(?:FROM|INTO|UPDATE|CREATE\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?|DROP\s+TABLE(?:\s+IF\s+EXISTS)?|ALTER\s+TABLE(?:\s+IF\s+EXISTS)?)\s+["']?([\w\.]+)["']?/i Would love to hear your thoughts ◡̈ |
I can take a shot at it! Just need to go through the contributor's guide. We probably should not include the quotes for consistency's sake - two queries on the same table should produce the same attribute regardless of whether quotes are used - so I'll keep them outside the capture. As far as single quotes, this SO post quotes the postgres manual as saying that single quotes are only for string constants, so they'd be a syntax error if they were wrapping the table name. |
@mostfunkyduck - excited to see your contribution come through 🎉 I agree on keeping the quotes out and its also great to learn about single quotes v double quotes in this context, thank you for sharing that. |
Hi @mostfunkyduck! Did going through the contributor's guide go okay? Seeing if you need anything ◡̈ |
👋 This issue has been marked as stale because it has been open with no activity. You can: comment on the issue or remove the stale label to hold stale off for a while, add the |
Description of the bug
The PG instrumentation library is using a regex here to extract the table name from queries in order to set the
db.collection.name
trace attribute. This regex does not match quoted table names, for instanceSELECT * from "foo"
will not return a match.Share details about your runtime
Operating system details: Linux, Ubuntu 24.04
RUBY_ENGINE: "ruby"
RUBY_VERSION: "3.3.4"
RUBY_DESCRIPTION: "ruby 3.3.4 (2024-07-09 revision be1089c8ec) [x86_64-linux]"
This also happens on various production instances, I can get that information if needed.
Share a simplified reproduction if possible
I've been reproducing this by adding this to the tests for pg on a local fork
This seems to fix it, though I'm pretty green at ruby and the inner workings of this library, so I don't know if there are knock-on effects here.
The text was updated successfully, but these errors were encountered: