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

Add enable_commenter support to mysql #1387

Open
clesleycode opened this issue Oct 17, 2022 · 3 comments · May be fixed by #1834
Open

Add enable_commenter support to mysql #1387

clesleycode opened this issue Oct 17, 2022 · 3 comments · May be fixed by #1834
Assignees

Comments

@clesleycode
Copy link

clesleycode commented Oct 17, 2022

Before opening a feature request against this repo, consider whether the feature should/could be implemented in the other OpenTelemetry client libraries. If so, please open an issue on opentelemetry-specification first.

Is your feature request related to a problem? Describe the solution you'd like.
Other SQL packages (like psycopg2) support SQL commenters for adding additional context -- I'd like to see this feature added to mysql

Describe alternatives you've considered
Which alternative solutions or features have you considered?
I didn't consider other alternatives since this feature already exists in other modules!

Additional context
Add any other context about the feature request here.
I think it'd be a simple change since it's already supported elsewhere. I have a potential draft PR here.

@rahuldimri
Copy link
Contributor

@clesleycode can I give a try on this ?.

@rahuldimri rahuldimri linked a pull request Jun 2, 2023 that will close this issue
11 tasks
@tammy-baylis-swi
Copy link
Contributor

Could trace context uniqueness in comments become an issue if mysql-connector supports prepared statements?: https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursorprepared.html

For example: if a parameterized statement is created then used for 3 queries (3 separate requests), then MySQL server may perform a PREPARE and EXECUTE the first time, then one EXECUTE for each subsequent query. Would the trace from each query be the same number of spans with correct parents?

A similar concern was brought up for Otel Java: open-telemetry/opentelemetry-sqlcommenter#32

@tammy-baylis-swi
Copy link
Contributor

A correction to my previous comment: the number of spans isn't the issue!

I've experimented more with MySQL server-side prepared statements via mysql-connector-python and it might be that enabling sqlcommenter in instrumentation would have the same resource concerns are Marginalia and ActiveRecord: /~https://github.com/basecamp/marginalia/blob/master/README.md#prepared-statements

For example, I set up an application (db client) to use mysql-connector's cursor and use the same parameterized statement for 3 queries with different id param and a comment with unique timestamp added at each query. This would be similar to adding a unique traceparent comment each time:

SELECT * FROM city WHERE id = %s /* 1689198539.3315277 */
SELECT * FROM city WHERE id = %s /* 1689198539.3339512 */
SELECT * FROM city WHERE id = %s /* 1689198539.3353686 */

After queries, the MySQL general logs included these:

2023-07-12T21:48:59.333069Z	   15 Prepare	SELECT * FROM city WHERE id = ? /* 1689198539.3315277 */
2023-07-12T21:48:59.333236Z	   15 Reset stmt
2023-07-12T21:48:59.333563Z	   15 Execute	SELECT * FROM city WHERE id = 1818 /* 1689198539.3315277 */
2023-07-12T21:48:59.334429Z	   15 Close stmt
2023-07-12T21:48:59.334586Z	   15 Prepare	SELECT * FROM city WHERE id = ? /* 1689198539.3339512 */
2023-07-12T21:48:59.334777Z	   15 Reset stmt
2023-07-12T21:48:59.335062Z	   15 Execute	SELECT * FROM city WHERE id = 1819 /* 1689198539.3339512 */
2023-07-12T21:48:59.335743Z	   15 Close stmt
2023-07-12T21:48:59.335869Z	   15 Prepare	SELECT * FROM city WHERE id = ? /* 1689198539.3353686 */
2023-07-12T21:48:59.336064Z	   15 Reset stmt
2023-07-12T21:48:59.336268Z	   15 Execute	SELECT * FROM city WHERE id = 1820 /* 1689198539.3353686 */
2023-07-12T21:48:59.336887Z	   15 Close stmt

Since there is a Prepare for every Execute, there should be no issue with mismatched traceparent in logs and traces. But if the query were repeated many times with a unique traceparent, then system resources could become exhausted if prepared statements are used. Just something to keep in mind!

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

Successfully merging a pull request may close this issue.

3 participants