Skip to content

Commit efe9b8d

Browse files
committed
Merge branch 'main' into fix-flask-multithread-context-bug
2 parents 933a15c + 3bcc043 commit efe9b8d

File tree

11 files changed

+81
-13
lines changed

11 files changed

+81
-13
lines changed

CHANGELOG.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Added
11+
12+
- Add connection attributes to sqlalchemy connect span
13+
([#1608](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1608))
14+
15+
### Fixed
16+
17+
- Fix Flask instrumentation to only close the span if it was created by the same thread.
18+
([#1654](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1654))
19+
1020
## Version 1.16.0/0.37b0 (2023-02-17)
1121

1222
### Added
1323

1424
- Support `aio_pika` 9.x (([#1670](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1670])
1525
- `opentelemetry-instrumentation-redis` Add `sanitize_query` config option to allow query sanitization. ([#1572](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1572))
16-
- `opentelemetry-instrumentation-elasticsearch` Add optional db.statement query sanitization.
26+
- `opentelemetry-instrumentation-elasticsearch` Add optional db.statement query sanitization.
1727
([#1598](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1598))
1828
- `opentelemetry-instrumentation-celery` Record exceptions as events on the span.
1929
([#1573](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1573))
@@ -32,8 +42,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3242

3343
### Fixed
3444

35-
- Fix Flask instrumentation to only close the span if it was created by the same thread.
36-
([#1654](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1654))
3745
- Fix TortoiseORM instrumentation `AttributeError: type object 'Config' has no attribute 'title'`
3846
([#1575](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1575))
3947
- Fix SQLAlchemy uninstrumentation

docs-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ aiopg>=0.13.0,<1.3.0
2424
asyncpg>=0.12.0
2525
boto~=2.0
2626
botocore~=1.0
27+
boto3~=1.0
2728
celery>=4.0
2829
confluent-kafka>= 1.8.2,< 2.0.0
2930
elasticsearch>=2.0,<9.0

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def getlistcfg(strval):
126126
]
127127

128128

129-
ignore_categories = ["py-class", "py-func", "py-exc", "any"]
129+
ignore_categories = ["py-class", "py-func", "py-exc", "py-obj", "any"]
130130

131131
for category in ignore_categories:
132132
if category in mcfg:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. include:: ../../../instrumentation/opentelemetry-instrumentation-boto3sqs/README.rst
2+
3+
.. automodule:: opentelemetry.instrumentation.boto3sqs
4+
:members:
5+
:undoc-members:
6+
:show-inheritance:

docs/nitpick-exceptions.ini

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ py-class=
1313
opentelemetry.sdk.trace.id_generator.IdGenerator
1414
opentelemetry.instrumentation.confluent_kafka.ProxiedProducer
1515
opentelemetry.instrumentation.confluent_kafka.ProxiedConsumer
16+
opentelemetry.instrumentation.instrumentor.BaseInstrumentor
1617
; - AwsXRayIdGenerator
1718
TextMapPropagator
1819
CarrierT
@@ -54,7 +55,16 @@ any=
5455
; - instrumentation.*
5556
Setter
5657
httpx
57-
;
58+
instrument
59+
__iter__
60+
list.__iter__
61+
__getitem__
62+
list.__getitem__
63+
SQS.ReceiveMessage
64+
65+
py-obj=
66+
opentelemetry.propagators.textmap.CarrierT
67+
5868
py-func=
5969
poll
6070
flush

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
1717
.. _boto3sqs: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs.html
1818
19-
2019
Usage
2120
-----
2221
23-
.. code:: python
22+
.. code-block:: python
2423
2524
import boto3
2625
from opentelemetry.instrumentation.boto3sqs import Boto3SQSInstrumentor
2726
28-
2927
Boto3SQSInstrumentor().instrument()
28+
29+
---
3030
"""
3131
import logging
3232
from typing import Any, Collection, Dict, Generator, List, Mapping, Optional

instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py

+20
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,26 @@ def response_hook(span, response):
463463
spans[0].attributes[response_attribute_name],
464464
)
465465

466+
def test_no_op_tracer_provider(self, request_mock):
467+
ElasticsearchInstrumentor().uninstrument()
468+
ElasticsearchInstrumentor().instrument(
469+
tracer_provider=trace.NoOpTracerProvider()
470+
)
471+
response_payload = '{"found": false, "timed_out": true, "took": 7}'
472+
request_mock.return_value = (
473+
1,
474+
{},
475+
response_payload,
476+
)
477+
es = Elasticsearch()
478+
res = es.get(index="test-index", doc_type="_doc", id=1)
479+
self.assertEqual(
480+
res.get("found"), json.loads(response_payload).get("found")
481+
)
482+
483+
spans_list = self.get_finished_spans()
484+
self.assertEqual(len(spans_list), 0)
485+
466486
def test_body_sanitization(self, _):
467487
self.assertEqual(
468488
sanitize_body(sanitization_queries.interval_query),

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ def _wrap_connect(tracer_provider=None):
9191
def _wrap_connect_internal(func, module, args, kwargs):
9292
with tracer.start_as_current_span(
9393
"connect", kind=trace.SpanKind.CLIENT
94-
):
94+
) as span:
95+
if span.is_recording():
96+
attrs, _ = _get_attributes_from_url(module.url)
97+
span.set_attributes(attrs)
98+
span.set_attribute(
99+
SpanAttributes.DB_SYSTEM, _normalize_vendor(module.name)
100+
)
95101
return func(*args, **kwargs)
96102

97103
return _wrap_connect_internal

instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
2323
from opentelemetry.sdk.resources import Resource
2424
from opentelemetry.sdk.trace import TracerProvider, export
25+
from opentelemetry.semconv.trace import SpanAttributes
2526
from opentelemetry.test.test_base import TestBase
2627

2728

@@ -128,11 +129,12 @@ async def run():
128129
def test_not_recording(self):
129130
mock_tracer = mock.Mock()
130131
mock_span = mock.Mock()
132+
mock_context = mock.Mock()
131133
mock_span.is_recording.return_value = False
132-
mock_span.__enter__ = mock.Mock(return_value=(mock.Mock(), None))
133-
mock_span.__exit__ = mock.Mock(return_value=None)
134-
mock_tracer.start_span.return_value = mock_span
135-
mock_tracer.start_as_current_span.return_value = mock_span
134+
mock_context.__enter__ = mock.Mock(return_value=mock_span)
135+
mock_context.__exit__ = mock.Mock(return_value=None)
136+
mock_tracer.start_span.return_value = mock_context
137+
mock_tracer.start_as_current_span.return_value = mock_context
136138
with mock.patch("opentelemetry.trace.get_tracer") as tracer:
137139
tracer.return_value = mock_tracer
138140
engine = create_engine("sqlite:///:memory:")
@@ -159,6 +161,12 @@ def test_create_engine_wrapper(self):
159161
self.assertEqual(len(spans), 2)
160162
# first span - the connection to the db
161163
self.assertEqual(spans[0].name, "connect")
164+
self.assertEqual(
165+
spans[0].attributes[SpanAttributes.DB_NAME], ":memory:"
166+
)
167+
self.assertEqual(
168+
spans[0].attributes[SpanAttributes.DB_SYSTEM], "sqlite"
169+
)
162170
self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)
163171
# second span - the query
164172
self.assertEqual(spans[1].name, "SELECT :memory:")
@@ -217,6 +225,12 @@ async def run():
217225
self.assertEqual(len(spans), 2)
218226
# first span - the connection to the db
219227
self.assertEqual(spans[0].name, "connect")
228+
self.assertEqual(
229+
spans[0].attributes[SpanAttributes.DB_NAME], ":memory:"
230+
)
231+
self.assertEqual(
232+
spans[0].attributes[SpanAttributes.DB_SYSTEM], "sqlite"
233+
)
220234
self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)
221235
# second span - the query
222236
self.assertEqual(spans[1].name, "SELECT :memory:")

tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mssql.py

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def test_engine_execute_errors(self):
7171
spans = self.memory_exporter.get_finished_spans()
7272
# one span for the connection and one for the query
7373
self.assertEqual(len(spans), 2)
74+
self.check_meta(spans[0])
7475
span = spans[1]
7576
# span fields
7677
self.assertEqual(span.name, "SELECT opentelemetry-tests")
@@ -99,6 +100,7 @@ def test_orm_insert(self):
99100
spans = self.memory_exporter.get_finished_spans()
100101
# connect, identity insert on before the insert, insert, and identity insert off after the insert
101102
self.assertEqual(len(spans), 4)
103+
self.check_meta(spans[0])
102104
span = spans[2]
103105
self._check_span(span, "INSERT")
104106
self.assertIn(

tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def test_engine_execute_errors(self):
7070
spans = self.memory_exporter.get_finished_spans()
7171
# one span for the connection and one for the query
7272
self.assertEqual(len(spans), 2)
73+
self.check_meta(spans[0])
7374
span = spans[1]
7475
# span fields
7576
self.assertEqual(span.name, "SELECT opentelemetry-tests")

0 commit comments

Comments
 (0)