Skip to content

Commit e6216e4

Browse files
authored
Merge branch 'main' into addingEmbeddingMetric
2 parents df63d17 + d22bf39 commit e6216e4

File tree

20 files changed

+1562
-106
lines changed

20 files changed

+1562
-106
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
([#4212](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4212))
2222
- `opentelemetry-instrumentation-botocore`: Add support for instrumenting `aiobotocore`
2323
([#4049](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4049))
24+
- `opentelemetry-instrumentation-sqlalchemy`: implement new semantic convention opt-in migration
25+
([#4110](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4110))
2426

2527
### Fixed
2628

@@ -32,6 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3234
([#4305](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4305))
3335
- Don't import module in unwrap if not already imported
3436
([#4321](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4321))
37+
- `opentelemetry-instrumentation-logging`: Map Python `CRITICAL` log level to OTel `FATAL` severity text and `WARNING` to `WARN`
38+
([#4365](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4365))
3539
- `opentelemetry-instrumentation-logging`: Add recursion guard in LoggingHandler.emit to prevent deadlock
3640
([#4302](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4302))
3741
- `opentelemetry-instrumentation-grpc`: Fix bidirectional streaming RPCs raising `AttributeError: 'generator' object has no attribute 'add_done_callback'`

instrumentation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
| [opentelemetry-instrumentation-redis](./opentelemetry-instrumentation-redis) | redis >= 2.6 | No | development
4242
| [opentelemetry-instrumentation-remoulade](./opentelemetry-instrumentation-remoulade) | remoulade >= 0.50 | No | development
4343
| [opentelemetry-instrumentation-requests](./opentelemetry-instrumentation-requests) | requests ~= 2.0 | Yes | migration
44-
| [opentelemetry-instrumentation-sqlalchemy](./opentelemetry-instrumentation-sqlalchemy) | sqlalchemy >= 1.0.0, < 2.1.0 | Yes | development
44+
| [opentelemetry-instrumentation-sqlalchemy](./opentelemetry-instrumentation-sqlalchemy) | sqlalchemy >= 1.0.0, < 2.1.0 | Yes | migration
4545
| [opentelemetry-instrumentation-sqlite3](./opentelemetry-instrumentation-sqlite3) | sqlite3 | No | development
4646
| [opentelemetry-instrumentation-starlette](./opentelemetry-instrumentation-starlette) | starlette >= 0.13 | Yes | development
4747
| [opentelemetry-instrumentation-system-metrics](./opentelemetry-instrumentation-system-metrics) | psutil >= 5 | No | development

instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/handler.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,14 @@ def _translate(self, record: logging.LogRecord) -> LogRecord:
188188
else:
189189
body = record.getMessage()
190190

191-
# related to https://github.com/open-telemetry/opentelemetry-python/issues/3548
192-
# Severity Text = WARN as defined in https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#displaying-severity.
193-
level_name = (
194-
"WARN" if record.levelname == "WARNING" else record.levelname
191+
# Map Python log level names to OTel severity text as defined in
192+
# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#displaying-severity
193+
_python_to_otel_severity_text = {
194+
"WARNING": "WARN",
195+
"CRITICAL": "FATAL",
196+
}
197+
level_name = _python_to_otel_severity_text.get(
198+
record.levelname, record.levelname
195199
)
196200

197201
return LogRecord(

instrumentation/opentelemetry-instrumentation-logging/tests/test_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def test_log_record_trace_correlation(self):
357357
record.log_record.body,
358358
"Critical message within span",
359359
)
360-
self.assertEqual(record.log_record.severity_text, "CRITICAL")
360+
self.assertEqual(record.log_record.severity_text, "FATAL")
361361
self.assertEqual(
362362
record.log_record.severity_number,
363363
SeverityNumber.FATAL,
@@ -390,7 +390,7 @@ def test_log_record_trace_correlation_deprecated(self):
390390
self.assertEqual(
391391
record.log_record.body, "Critical message within span"
392392
)
393-
self.assertEqual(record.log_record.severity_text, "CRITICAL")
393+
self.assertEqual(record.log_record.severity_text, "FATAL")
394394
self.assertEqual(
395395
record.log_record.severity_number, SeverityNumber.FATAL
396396
)

instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/__init__.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,24 @@
110110
SQLComment in span attribute
111111
****************************
112112
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.
116116
117117
.. code:: python
118118
119119
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
120120
121121
# 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.
123123
SQLAlchemyInstrumentor().instrument(
124124
enable_commenter=True,
125125
commenter_options={},
126126
enable_attribute_commenter=True,
127127
)
128128
129129
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.
131131
132132
API
133133
---
@@ -141,6 +141,11 @@
141141
from sqlalchemy.engine.base import Engine
142142
from wrapt import wrap_function_wrapper as _w
143143

144+
from opentelemetry.instrumentation._semconv import (
145+
_get_schema_url_for_signal_types,
146+
_OpenTelemetrySemanticConventionStability,
147+
_OpenTelemetryStabilitySignalType,
148+
)
144149
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
145150
from opentelemetry.instrumentation.sqlalchemy.engine import (
146151
EngineTracer,
@@ -181,20 +186,32 @@ def _instrument(self, **kwargs):
181186
Returns:
182187
An instrumented engine if passed in as an argument or list of instrumented engines, None otherwise.
183188
"""
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+
184201
tracer_provider = kwargs.get("tracer_provider")
185202
tracer = get_tracer(
186203
__name__,
187204
__version__,
188205
tracer_provider,
189-
schema_url="https://opentelemetry.io/schemas/1.11.0",
206+
schema_url=schema_url,
190207
)
191208

192209
meter_provider = kwargs.get("meter_provider")
193210
meter = get_meter(
194211
__name__,
195212
__version__,
196213
meter_provider,
197-
schema_url="https://opentelemetry.io/schemas/1.11.0",
214+
schema_url=schema_url,
198215
)
199216

200217
connections_usage = meter.create_up_down_counter(

0 commit comments

Comments
 (0)