|
42 | 42 | wrap_connect, |
43 | 43 | ) |
44 | 44 |
|
45 | | - # Ex: mysql.connector |
| 45 | + # Example: mysql.connector |
46 | 46 | trace_integration(mysql.connector, "connect", "mysql") |
47 | | - # Ex: pyodbc |
| 47 | + # Example: pyodbc |
48 | 48 | trace_integration(pyodbc, "Connection", "odbc") |
49 | 49 |
|
50 | 50 | # Or, directly call wrap_connect for more configurability |
|
60 | 60 | You can optionally configure DB-API instrumentation to enable sqlcommenter which |
61 | 61 | enriches the query with contextual information. Queries made after setting up |
62 | 62 | trace integration with sqlcommenter enabled will have configurable key-value pairs |
63 | | -appended to them, e.g. ``"select * from auth_users; /*metrics=value*/"``. For |
64 | | -more information, see: |
| 63 | +appended to them, e.g. ``"select * from auth_users; /*metrics=value*/"``. This |
| 64 | +supports context propagation between database client and server when database log |
| 65 | +records are enabled. For more information, see: |
65 | 66 |
|
66 | 67 | * `Semantic Conventions - Database Spans <https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md#sql-commenter>`_ |
67 | 68 | * `sqlcommenter <https://google.github.io/sqlcommenter/>`_ |
68 | 69 |
|
69 | 70 | .. code:: python |
70 | 71 |
|
71 | 72 | import mysql.connector |
72 | | - import pyodbc |
73 | 73 |
|
74 | 74 | from opentelemetry.instrumentation.dbapi import wrap_connect |
75 | 75 |
|
76 | 76 |
|
77 | | - # Ex: mysql.connector |
| 77 | + # Opts into sqlcomment for MySQL trace integration |
| 78 | + wrap_connect( |
| 79 | + __name__, |
| 80 | + mysql.connector, |
| 81 | + "connect", |
| 82 | + "mysql", |
| 83 | + enable_commenter=True, |
| 84 | + ) |
| 85 | +
|
| 86 | +
|
| 87 | +SQLCommenter Configurations |
| 88 | +*************************** |
| 89 | +When using ``wrap_connect`` for DB-API trace integration, the key-value pairs appended to the query can be configured using ``commenter_options``. When sqlcommenter is enabled, all available KVs/tags calculated by default. ``commenter_options`` supports opting out of specific KVs. |
| 90 | +
|
| 91 | +.. code:: python |
| 92 | +
|
| 93 | + import mysql.connector |
| 94 | +
|
| 95 | + from opentelemetry.instrumentation.dbapi import wrap_connect |
| 96 | +
|
| 97 | +
|
| 98 | + # Opts into sqlcomment for MySQL trace integration |
| 99 | + # Opts out of tags for libpq_version |
78 | 100 | wrap_connect( |
79 | 101 | __name__, |
80 | 102 | mysql.connector, |
81 | 103 | "connect", |
82 | 104 | "mysql", |
83 | 105 | enable_commenter=True, |
| 106 | + commenter_options={ |
| 107 | + "libpq_version": False, |
| 108 | + "db_driver": False, |
| 109 | + } |
84 | 110 | ) |
85 | 111 |
|
| 112 | +Available commenter options |
| 113 | +########################### |
| 114 | +
|
| 115 | +The following options can be configured through ``commenter_options``: |
| 116 | +
|
| 117 | +#. ``db_driver`` - Database driver name with version. |
| 118 | + Example: ``mysql.connector=2.2.9`` |
| 119 | +
|
| 120 | +#. ``dbapi_threadsafety`` - DB-API's threadsafety value. |
| 121 | + Example: ``dbapi_threadsafety=2`` |
| 122 | +
|
| 123 | +#. ``dbapi_level`` - DB-API's API level. |
| 124 | + Example: ``dbapi_level=2.0`` |
| 125 | +
|
| 126 | +#. ``driver_paramstyle`` - DB-API's paramstyle for SQL statement parameters. |
| 127 | + Example: ``driver_paramstyle='pyformat'`` |
| 128 | +
|
| 129 | +#. ``libpq_version`` - PostgreSQL's libpq version (checked for PostgreSQL only). |
| 130 | + Example: ``libpq_version=140001`` |
| 131 | +
|
| 132 | +#. ``mysql_client_version`` - MySQL client version (checked for MySQL only). |
| 133 | + Example: ``mysql_client_version='123'`` |
| 134 | +
|
| 135 | +#. ``opentelemetry_values`` - OpenTelemetry context values. |
| 136 | + Example: ``traceparent='00-03afa25236b8cd948fa853d67038ac79-405ff022e8247c46-01'`` |
| 137 | +
|
86 | 138 | API |
87 | 139 | --- |
88 | 140 | """ |
|
0 commit comments