|
110 | 110 | SQLComment in span attribute |
111 | 111 | **************************** |
112 | 112 | If sqlcommenter is enabled, you can opt into the inclusion of sqlcomment in |
113 | | -the query span ``db.statement`` attribute for your needs. If ``commenter_options`` |
114 | | -have been set, the span attribute comment will also be configured by this |
115 | | -setting. |
| 113 | +the query span ``db.statement`` and/or ``db.query.text`` attribute for your |
| 114 | +needs. If ``commenter_options`` have been set, the span attribute comment |
| 115 | +will also be configured by this setting. |
116 | 116 |
|
117 | 117 | .. code:: python |
118 | 118 |
|
119 | 119 | from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor |
120 | 120 |
|
121 | 121 | # Opts into sqlcomment for SQLAlchemy trace integration. |
122 | | - # Opts into sqlcomment for `db.statement` span attribute. |
| 122 | + # Opts into sqlcomment for `db.statement` and/or `db.query.text` span attribute. |
123 | 123 | SQLAlchemyInstrumentor().instrument( |
124 | 124 | enable_commenter=True, |
125 | 125 | commenter_options={}, |
126 | 126 | enable_attribute_commenter=True, |
127 | 127 | ) |
128 | 128 |
|
129 | 129 | Warning: |
130 | | - Capture of sqlcomment in ``db.statement`` may have high cardinality without platform normalization. See `Semantic Conventions for database spans <https://opentelemetry.io/docs/specs/semconv/database/database-spans/#generating-a-summary-of-the-query-text>`_ for more information. |
| 130 | + Capture of sqlcomment in ``db.statement``/``db.query.text`` may have high cardinality without platform normalization. See `Semantic Conventions for database spans <https://opentelemetry.io/docs/specs/semconv/database/database-spans/#generating-a-summary-of-the-query-text>`_ for more information. |
131 | 131 |
|
132 | 132 | API |
133 | 133 | --- |
|
141 | 141 | from sqlalchemy.engine.base import Engine |
142 | 142 | from wrapt import wrap_function_wrapper as _w |
143 | 143 |
|
| 144 | +from opentelemetry.instrumentation._semconv import ( |
| 145 | + _get_schema_url_for_signal_types, |
| 146 | + _OpenTelemetrySemanticConventionStability, |
| 147 | + _OpenTelemetryStabilitySignalType, |
| 148 | +) |
144 | 149 | from opentelemetry.instrumentation.instrumentor import BaseInstrumentor |
145 | 150 | from opentelemetry.instrumentation.sqlalchemy.engine import ( |
146 | 151 | EngineTracer, |
@@ -181,20 +186,32 @@ def _instrument(self, **kwargs): |
181 | 186 | Returns: |
182 | 187 | An instrumented engine if passed in as an argument or list of instrumented engines, None otherwise. |
183 | 188 | """ |
| 189 | + # Initialize semantic conventions opt-in if needed |
| 190 | + _OpenTelemetrySemanticConventionStability._initialize() |
| 191 | + |
| 192 | + # Determine schema URL based on both DATABASE and HTTP signal types |
| 193 | + # and semconv opt-in mode |
| 194 | + schema_url = _get_schema_url_for_signal_types( |
| 195 | + [ |
| 196 | + _OpenTelemetryStabilitySignalType.DATABASE, |
| 197 | + _OpenTelemetryStabilitySignalType.HTTP, |
| 198 | + ] |
| 199 | + ) |
| 200 | + |
184 | 201 | tracer_provider = kwargs.get("tracer_provider") |
185 | 202 | tracer = get_tracer( |
186 | 203 | __name__, |
187 | 204 | __version__, |
188 | 205 | tracer_provider, |
189 | | - schema_url="https://opentelemetry.io/schemas/1.11.0", |
| 206 | + schema_url=schema_url, |
190 | 207 | ) |
191 | 208 |
|
192 | 209 | meter_provider = kwargs.get("meter_provider") |
193 | 210 | meter = get_meter( |
194 | 211 | __name__, |
195 | 212 | __version__, |
196 | 213 | meter_provider, |
197 | | - schema_url="https://opentelemetry.io/schemas/1.11.0", |
| 214 | + schema_url=schema_url, |
198 | 215 | ) |
199 | 216 |
|
200 | 217 | connections_usage = meter.create_up_down_counter( |
|
0 commit comments