-
Notifications
You must be signed in to change notification settings - Fork 921
Add DB-API sqlcomment mysql_client_version fallback #3729
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
Merged
xrmx
merged 20 commits into
open-telemetry:main
from
tammy-baylis-swi:mysql-client-comment-field-fallback
Jan 26, 2026
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
340b6e1
Add dbapi comment mysql_client_version fallback
tammy-baylis-swi ff9f01c
Changelog
tammy-baylis-swi 8734f32
Merge branch 'main' into mysql-client-comment-field-fallback
tammy-baylis-swi 50d510c
Merge branch 'main' into mysql-client-comment-field-fallback
tammy-baylis-swi e873ea0
Add docker test_mysql_sqlcommenter
tammy-baylis-swi 7fa0d60
Update dbapi docker-tests
tammy-baylis-swi d0508f3
Add test fetchall
tammy-baylis-swi 5d89ace
Add test case for cmysql unknown
tammy-baylis-swi d3add81
Change to patch
tammy-baylis-swi a9642ae
Rm test attempt
tammy-baylis-swi f6e5f4d
Merge branch 'main' into mysql-client-comment-field-fallback
tammy-baylis-swi 7d96baf
Merge branch 'main' into mysql-client-comment-field-fallback
tammy-baylis-swi 87f6415
Merge branch 'main' into mysql-client-comment-field-fallback
tammy-baylis-swi b83b21f
Merge branch 'main' into mysql-client-comment-field-fallback
tammy-baylis-swi 961c5fe
Changelog
tammy-baylis-swi adc5cc1
Merge branch 'main' into mysql-client-comment-field-fallback
tammy-baylis-swi a8ecf3e
simplify commenter_data assn
tammy-baylis-swi 3249647
Add Pure Python mysql_client_version unknown test
tammy-baylis-swi a2b8cd0
Merge branch 'main' into mysql-client-comment-field-fallback
emdneto dc24eda
Merge branch 'main' into mysql-client-comment-field-fallback
xrmx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
tests/opentelemetry-docker-tests/tests/mysql/test_mysql_sqlcommenter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Copyright 2025, OpenTelemetry Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import os | ||
|
|
||
| import mysql.connector | ||
|
|
||
| from opentelemetry.instrumentation.mysql import MySQLInstrumentor | ||
| from opentelemetry.test.test_base import TestBase | ||
|
|
||
| MYSQL_USER = os.getenv("MYSQL_USER", "testuser") | ||
| MYSQL_PASSWORD = os.getenv("MYSQL_PASSWORD", "testpassword") | ||
| MYSQL_HOST = os.getenv("MYSQL_HOST", "localhost") | ||
| MYSQL_PORT = int(os.getenv("MYSQL_PORT", "3306")) | ||
| MYSQL_DB_NAME = os.getenv("MYSQL_DB_NAME", "opentelemetry-tests") | ||
|
|
||
|
|
||
| class TestFunctionalMySqlCommenter(TestBase): | ||
xrmx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_commenter_enabled_direct_reference(self): | ||
| MySQLInstrumentor().instrument(enable_commenter=True) | ||
| cnx = mysql.connector.connect( | ||
| user=MYSQL_USER, | ||
| password=MYSQL_PASSWORD, | ||
| host=MYSQL_HOST, | ||
| port=MYSQL_PORT, | ||
| database=MYSQL_DB_NAME, | ||
| ) | ||
| cursor = cnx.cursor() | ||
|
|
||
| cursor.execute("SELECT 1;") | ||
| cursor.fetchall() | ||
| self.assertRegex( | ||
| cursor.statement, | ||
| r"SELECT 1 /\*db_driver='mysql\.connector[^']*',dbapi_level='\d\.\d',dbapi_threadsafety=\d,driver_paramstyle='[^']*',mysql_client_version='[^']*',traceparent='[^']*'\*/;", | ||
| ) | ||
| self.assertRegex( | ||
| cursor.statement, r"mysql_client_version='(?!unknown)[^']+" | ||
| ) | ||
|
|
||
| cursor.close() | ||
| cnx.close() | ||
| MySQLInstrumentor().uninstrument() | ||
|
|
||
| def test_commenter_enabled_connection_proxy(self): | ||
| cnx = mysql.connector.connect( | ||
| user=MYSQL_USER, | ||
| password=MYSQL_PASSWORD, | ||
| host=MYSQL_HOST, | ||
| port=MYSQL_PORT, | ||
| database=MYSQL_DB_NAME, | ||
| ) | ||
| instrumented_cnx = MySQLInstrumentor().instrument_connection( | ||
| connection=cnx, | ||
| enable_commenter=True, | ||
| ) | ||
| cursor = instrumented_cnx.cursor() | ||
|
|
||
| cursor.execute("SELECT 1;") | ||
| cursor.fetchall() | ||
| self.assertRegex( | ||
| cursor.statement, | ||
| r"SELECT 1 /\*db_driver='mysql\.connector[^']*',dbapi_level='\d\.\d',dbapi_threadsafety=\d,driver_paramstyle='[^']*',mysql_client_version='[^']*',traceparent='[^']*'\*/;", | ||
| ) | ||
| self.assertRegex( | ||
| cursor.statement, r"mysql_client_version='(?!unknown)[^']+" | ||
| ) | ||
|
|
||
| cursor.close() | ||
| MySQLInstrumentor().uninstrument_connection(instrumented_cnx) | ||
| cnx.close() | ||
|
|
||
| def test_commenter_mysql_client_version_fallback_to_unknown(self): | ||
| """Test that mysql_client_version falls back to 'unknown' with pure Python implementation""" | ||
| MySQLInstrumentor().instrument(enable_commenter=True) | ||
| cnx = mysql.connector.connect( | ||
| user=MYSQL_USER, | ||
| password=MYSQL_PASSWORD, | ||
| host=MYSQL_HOST, | ||
| port=MYSQL_PORT, | ||
| database=MYSQL_DB_NAME, | ||
| use_pure=True, # Use pure Python - no _cmysql module | ||
| ) | ||
| cursor = cnx.cursor() | ||
|
|
||
| cursor.execute("SELECT 1;") | ||
| cursor.fetchall() | ||
|
|
||
| # With use_pure=True, _cmysql is not available, should fall back to 'unknown' | ||
| self.assertRegex(cursor.statement, r"mysql_client_version='unknown'") | ||
|
|
||
| cursor.close() | ||
| cnx.close() | ||
| MySQLInstrumentor().uninstrument() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.