Skip to content

sqlalchemy instrumentation wrappers don't use sqlcommenter options #1872

@tammy-baylis-swi

Description

@tammy-baylis-swi

Describe your environment

I have a custom distro that extends BaseDistro and overrides load_instrumentor so that I can pass in custom args during auto-instrumentation such as enable_commenter and commenter_options for sqlalchemy instrumentation (described here). This is with OTel 1.18.0/0.39b0. I am instrumenting a simple Flask app that uses sqlalchemy to query a MySQL database, all running in Docker.

I found that _wrap_create_engine and _wrap_create_async_engine do accept enable_commenter but not commenter_options. This means sqlcommenting can be enabled but not customized. This is an issue during auto-instrumentation, but not during all manual instrumentation scenarios because sometimes the latter uses EngineTracer which does accept and use both configs.

Steps to reproduce

  1. Create a custom distro that extends BaseDistro.
  2. Implement load_instrumentor so that kwargs at instrumentor().instrument(**kwargs) includes "enable_commenter": True and "commenter_options": {"opentelemetry_values": False}.
  3. Install the custom distro and auto-instrument a service with opentelemetry-instrument.
  4. Request the service to use sqlalchemy to query a MySQL database.
  5. Check mysqld general logs for record of the query, which will include the comments added by OTel instrumentation.

What is the expected behavior?

The query log should not include OTel values because of "commenter_options": {"opentelemetry_values": False}.

2023-06-23T23:26:12.022041Z	   13 Query	SELECT city.id, city.name, city.district, city.population, city.countrycode
FROM city
WHERE city.id = 1818 /*controller='request_manual',db_driver='mysqldb',db_framework='sqlalchemy%3A0.39b0.dev',framework='flask%3A2.2.5',route='/manual/'*/

What is the actual behavior?

OTel values are included despite config. There is traceparent included in the comment:

2023-06-23T21:49:04.124802Z	   10 Query	SELECT city.id, city.name, city.district, city.population, city.countrycode
FROM city
WHERE city.id = 1818 /*controller='request_manual',db_driver='mysqldb',db_framework='sqlalchemy%3A0.39b0',framework='flask%3A2.2.5',route='/manual/',traceparent='00-a660c32a7b8b72ece19376208a0afe36-be03b8409682a4c6-01'*/

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions