(As requested in #1784 (comment))
MySQL (but not MariaDB) supports query attributes which are essentially key-value metadata associated with a single query execution. They must be enabled on the server and are only supported starting from MySQL 8~.
The motivation is support for propagating OpenTelemetry traces, which requires attaching some metadata to a query execution so it can be later correlated with other activity. MySQL has native support for OpenTelemetry, and if the (traceparent) query attribute is defined, MySQL can report this metadata directly to an OpenTelemetry "collector" itself (docs, blog). (This was introduced in the enterprise version of MySQL 8 and in the community version starting in MySQL 9.7.)
Because of this, I think there needs to be some support in the database/sql driver itself, at least for query attributes.
I believe the standard way to instrument database/sql with OpenTelemetry in Go is https://github.com/XSAM/otelsql, which is maintained by one of the OpenTelemetry maintainers. From looking around, I think it does not implement trace propagation for MySQL. The "standard" way is to inject a comment into SQL queries, which otelsql can do by wrapping any database/sql driver. But I don't believe this works for MySQL.
(It seems other parts of the OTel ecosystem use user variables instead of query attributes. But this is not documented by Oracle itself. And the comment-in-query approach is not supported regardless.)
(As requested in #1784 (comment))
MySQL (but not MariaDB) supports query attributes which are essentially key-value metadata associated with a single query execution. They must be enabled on the server and are only supported starting from MySQL 8~.
The motivation is support for propagating OpenTelemetry traces, which requires attaching some metadata to a query execution so it can be later correlated with other activity. MySQL has native support for OpenTelemetry, and if the (traceparent) query attribute is defined, MySQL can report this metadata directly to an OpenTelemetry "collector" itself (docs, blog). (This was introduced in the enterprise version of MySQL 8 and in the community version starting in MySQL 9.7.)
Because of this, I think there needs to be some support in the database/sql driver itself, at least for query attributes.
I believe the standard way to instrument database/sql with OpenTelemetry in Go is https://github.com/XSAM/otelsql, which is maintained by one of the OpenTelemetry maintainers. From looking around, I think it does not implement trace propagation for MySQL. The "standard" way is to inject a comment into SQL queries, which otelsql can do by wrapping any database/sql driver. But I don't believe this works for MySQL.
(It seems other parts of the OTel ecosystem use user variables instead of query attributes. But this is not documented by Oracle itself. And the comment-in-query approach is not supported regardless.)