go-sql-driver / go-sql-driver/mysql

Feature Request: MySQL query attributes/OpenTelemetry trace propagation

Open
#1,785 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
15.3k
Forks
2.3k
Avg merge
2h 23m
Merged PRs (30d)
10

Description

(As requested in https://github.com/go-sql-driver/mysql/pull/1784#issuecomment-5000444536)

MySQL (but not MariaDB) supports [query attributes](https://dev.mysql.com/doc/refman/8.4/en/query-attributes.html) 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](https://dev.mysql.com/doc/connector-python/en/connector-python-opentelemetry.html)) query attribute is defined, MySQL can report this metadata directly to an OpenTelemetry "collector" itself ([docs](https://dev.mysql.com/doc/refman/9.7/en/telemetry.html), [blog](https://blogs.oracle.com/mysql/a-new-era-of-mysql-monitoring-opentelemetry-metrics-with-prometheus)). (This was introduced in the enterprise version of MySQL 8 and in the community version [starting in MySQL 9.7](https://blogs.oracle.com/mysql/mysql-9-7-is-out-and-the-community-wins).)

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](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/0bfa73e6f1b5d71362fcf18ee505d4d2e78177dd/receiver/mysqlreceiver/README.md#L115-L120). But this is not documented by Oracle itself. And the comment-in-query approach is not supported regardless.)

Contributor guide

Open the contributing guide

Research direction

No implementation file or test entry point is identified. Start by reviewing the driver's database/sql integration and the MySQL query attributes documentation, then compare the propagation approaches discussed for otelsql and OpenTelemetry. Done requires an agreed scope for query-attribute support and a validated implementation path.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, mysql
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.