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

Added enable commenter #1834

Draft
wants to merge 49 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
92782da
Added enable commenter
rahuldimri Jun 2, 2023
a9aad62
CHANGELOG.MD updated.
rahuldimri Jun 2, 2023
e37cccb
Merge branch 'main' into patch-5
shalevr Jun 11, 2023
36d0c72
lint issue.
rahuldimri Jun 12, 2023
4d4a7d3
rahuldimri Jun 12, 2023
3c86278
rahuldimri Jun 12, 2023
e0f4556
Remove new line
rahuldimri Jun 12, 2023
927f2c0
Lint issue
rahuldimri Jun 12, 2023
9dec864
Lint
rahuldimri Jun 12, 2023
3af0bbc
Update test_mysql_integration.py
rahuldimri Jun 12, 2023
1e642a4
Update test_mysql_integration.py
rahuldimri Jun 12, 2023
3b905e2
Update test_mysql_integration.py
rahuldimri Jun 12, 2023
876b04a
Update test_mysql_integration.py
rahuldimri Jun 12, 2023
06501e0
Update test_mysql_integration.py
rahuldimri Jun 12, 2023
e4c96b2
Update test_mysql_integration.py
rahuldimri Jun 14, 2023
0ee14d2
Update test_mysql_integration.py
rahuldimri Jun 14, 2023
fdcf003
updating changelog.md
rahuldimri Jun 14, 2023
557bf73
Update test_mysql_integration.py
rahuldimri Jun 14, 2023
9c6edbc
Merge branch 'main' into patch-5
rahuldimri Jun 14, 2023
1fef965
Update test_mysql_integration.py
rahuldimri Jun 14, 2023
da27075
Update test_mysql_integration.py
rahuldimri Jun 14, 2023
b00d1b5
Update test_mysql_integration.py
rahuldimri Jun 14, 2023
b156583
Merge branch 'main' into patch-5
rahuldimri Jun 16, 2023
3d09350
Merge branch 'main' into patch-5
shalevr Jun 16, 2023
53508ec
Update CHANGELOG.md
rahuldimri Jun 19, 2023
e94831a
Update test_mysql_integration.py
rahuldimri Jun 19, 2023
a3b235e
Update __init__.py
rahuldimri Jun 19, 2023
fdfd961
Update CHANGELOG.md
rahuldimri Jun 19, 2023
905db61
Update __init__.py
rahuldimri Jun 19, 2023
7c15377
Update instrumentation/opentelemetry-instrumentation-mysql/src/opente…
rahuldimri Jun 19, 2023
8c31902
Update __init__.py
shalevr Jun 19, 2023
7fe6ed7
Merge branch 'main' into patch-5
shalevr Jun 19, 2023
5773c0c
Update test_mysql_integration.py
rahuldimri Jul 3, 2023
7bf8d17
Merge branch 'main' into patch-5
shalevr Jul 3, 2023
c71b4fd
Merge branch 'main' into patch-5
shalevr Jul 11, 2023
bad72af
Merge branch 'main' into patch-5
rahuldimri Jul 18, 2023
5fcb24e
Merge branch 'main' into patch-5
ocelotl Aug 7, 2023
453d0a0
Merge branch 'main' into patch-5
ocelotl Aug 30, 2023
f448d8a
Fix docs
ocelotl Aug 30, 2023
d36f01e
Merge branch 'main' into patch-5
rahuldimri Sep 7, 2023
ef78d6e
Merge branch 'main' into patch-5
ocelotl Oct 1, 2023
a39ef31
Merge branch 'main' into patch-5
ocelotl Nov 6, 2023
bc4b819
Merge branch 'main' into patch-5
tammy-baylis-swi Mar 7, 2024
eb889d4
Merge branch 'main' into patch-5
lzchen Mar 7, 2024
dbbb145
Merge branch 'main' into patch-5
ocelotl Jun 28, 2024
bacee50
Merge branch 'main' into patch-5
rahuldimri Jul 10, 2024
3d70416
Merge branch 'main' into patch-5
rahuldimri Jul 26, 2024
0d480c3
Merge branch 'main' into patch-5
rahuldimri Sep 11, 2024
eb10c7c
Merge branch 'main' into patch-5
tammy-baylis-swi Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1298,3 +1298,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `opentelemetry-ext-wsgi` Initial release
- `opentelemetry-ext-http-requests` Initial release

### Added

- 'Added Enable_commenter for mysql
rahuldimri marked this conversation as resolved.
Show resolved Hide resolved
([[#1387](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1387)])
rahuldimri marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,47 @@

.. _mysql-connector: https://pypi.org/project/mysql-connector/

SQLCOMMENTER
*****************************************
You can optionally configure Psycopg2 instrumentation to enable sqlcommenter which enriches
rahuldimri marked this conversation as resolved.
Show resolved Hide resolved
the query with contextual information.
Usage
-----
.. code:: python
from opentelemetry.instrumentation.mysql import MySQLInstrumentor()
MySQLInstrumentor().instrument(enable_commenter=True, commenter_options={})
For example,
::
Invoking cursor.execute("select * from auth_users") will lead to sql query "select * from auth_users" but when SQLCommenter is enabled
the query will get appended with some configurable tags like "select * from auth_users /*tag=value*/;"
SQLCommenter Configurations
***************************
We can configure the tags to be appended to the sqlquery log by adding configuration inside commenter_options(default:{}) keyword
db_driver = True(Default) or False
For example,
::
Enabling this flag will add mysql and its version.
dbapi_threadsafety = True(Default) or False
For example,
::
Enabling this flag will add threadsafety /*dbapi_threadsafety=2*/
dbapi_level = True(Default) or False
For example,
::
Enabling this flag will add dbapi_level /*dbapi_level='2.0'*/
libpq_version = True(Default) or False
For example,
::
Enabling this flag will add libpq_version /*libpq_version=140001*/
driver_paramstyle = True(Default) or False
For example,
::
Enabling this flag will add driver_paramstyle /*driver_paramstyle='pyformat'*/
opentelemetry_values = True(Default) or False
For example,
::
Enabling this flag will add traceparent values /*traceparent='00-03afa25236b8cd948fa853d67038ac79-405ff022e8247c46-01'*/

Usage
-----

Expand Down Expand Up @@ -66,6 +107,8 @@ def _instrument(self, **kwargs):
https://dev.mysql.com/doc/connector-python/en/
"""
tracer_provider = kwargs.get("tracer_provider")
enable_sqlcommenter = kwargs.get("enable_commenter", False)
commenter_options = kwargs.get("commenter_options", {})

dbapi.wrap_connect(
__name__,
Expand All @@ -75,6 +118,8 @@ def _instrument(self, **kwargs):
self._CONNECTION_ATTRIBUTES,
version=__version__,
tracer_provider=tracer_provider,
enable_commenter=enable_sqlcommenter,
commenter_options=commenter_options,
)

def _uninstrument(self, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,27 @@ def test_uninstrument_connection(self, mock_connect):

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)

@patch("mysql.connector.connect", new=mock_connect)
@patch("opentelemetry.instrumentation.dbapi.wrap_connect")
# pylint: disable=unused-argument
def test_sqlcommenter_enabled(self, event_mocked):
rahuldimri marked this conversation as resolved.
Show resolved Hide resolved
cnx = mysql.connector.connect(database="test")
MySQLInstrumentor().instrument(enable_commenter=True)
rahuldimri marked this conversation as resolved.
Show resolved Hide resolved
query = "SELECT * FROM test"
cursor = cnx.cursor()
cursor.execute(query)
kwargs = event_mocked.call_args[1]
self.assertEqual(kwargs["enable_commenter"], True)

@patch("mysql.connector.connect", new=mock_connect)
@patch("opentelemetry.instrumentation.dbapi.wrap_connect")
# pylint: disable=unused-argument
def test_sqlcommenter_disabled(self, event_mocked):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rahuldimri these tests are failing, please take a look. This PR has enough approvals, we only need these tests to pass in order to merge it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure let me work on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rahuldimri I fixed the failing docs tests, we only need this test case to pass and we can merge this PR ✌️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ocelotl let me have a look !!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rahuldimri

Are you still working on this? Still seems like there are test cases that are failing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rahuldimri , are you still working on this PR?

cnx = mysql.connector.connect(database="test")
MySQLInstrumentor().instrument(enable_commenter=False)
query = "SELECT * FROM test"
cursor = cnx.cursor()
cursor.execute(query)
kwargs = event_mocked.call_args[1]
self.assertEqual(kwargs["enable_commenter"], False)