Skip to content

Commit 8555bbc

Browse files
authored
Merge branch 'main' into add-type-hints-to-psycopg
2 parents d78970c + d2a51b9 commit 8555bbc

File tree

6 files changed

+117
-17
lines changed

6 files changed

+117
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5050
([#2816](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2816))
5151
- `opentelemetry-instrumentation-sqlalchemy`: Fix a remaining memory leak in EngineTracer
5252
([#3053](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3053))
53+
- `opentelemetry-instrumentation-sqlite3`: Update documentation on explicit cursor support of tracing
54+
([#3088](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3088))
5355

5456
### Breaking changes
5557

instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
3030
# Enable instrumentation
3131
BotocoreInstrumentor().instrument()
32-
AwsLambdaInstrumentor().instrument()
3332
3433
# Lambda function
3534
def lambda_handler(event, context):
@@ -39,6 +38,8 @@ def lambda_handler(event, context):
3938
4039
return "200 OK"
4140
41+
AwsLambdaInstrumentor().instrument()
42+
4243
API
4344
---
4445

instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ def test_traced_client(self):
103103
request_id = "fdcdcab1-ae5c-489e-9c33-4637c5dda355"
104104
self.assert_span("EC2", "DescribeInstances", request_id=request_id)
105105

106+
@mock_aws
107+
def test_no_op_tracer_provider_ec2(self):
108+
BotocoreInstrumentor().uninstrument()
109+
BotocoreInstrumentor().instrument(
110+
tracer_provider=trace_api.NoOpTracerProvider()
111+
)
112+
113+
ec2 = self._make_client("ec2")
114+
ec2.describe_instances()
115+
116+
spans_list = self.memory_exporter.get_finished_spans()
117+
self.assertEqual(len(spans_list), 0)
118+
106119
@mock_aws
107120
def test_not_recording(self):
108121
mock_tracer = Mock()
@@ -148,6 +161,19 @@ def test_s3_client(self):
148161
s3.list_buckets()
149162
self.assert_span("S3", "ListBuckets")
150163

164+
@mock_aws
165+
def test_no_op_tracer_provider_s3(self):
166+
BotocoreInstrumentor().uninstrument()
167+
BotocoreInstrumentor().instrument(
168+
tracer_provider=trace_api.NoOpTracerProvider()
169+
)
170+
171+
s3 = self._make_client("s3")
172+
s3.list_buckets()
173+
174+
spans_list = self.memory_exporter.get_finished_spans()
175+
self.assertEqual(len(spans_list), 0)
176+
151177
@mock_aws
152178
def test_s3_put(self):
153179
s3 = self._make_client("s3")
@@ -176,6 +202,19 @@ def test_sqs_client(self):
176202
"SQS", "ListQueues", request_id=_REQUEST_ID_REGEX_MATCH
177203
)
178204

205+
@mock_aws
206+
def test_no_op_tracer_provider_sqs(self):
207+
BotocoreInstrumentor().uninstrument()
208+
BotocoreInstrumentor().instrument(
209+
tracer_provider=trace_api.NoOpTracerProvider()
210+
)
211+
212+
sqs = self._make_client("sqs")
213+
sqs.list_queues()
214+
215+
spans_list = self.memory_exporter.get_finished_spans()
216+
self.assertEqual(len(spans_list), 0)
217+
179218
@mock_aws
180219
def test_sqs_send_message(self):
181220
sqs = self._make_client("sqs")
@@ -204,6 +243,19 @@ def test_kinesis_client(self):
204243
kinesis.list_streams()
205244
self.assert_span("Kinesis", "ListStreams")
206245

246+
@mock_aws
247+
def test_no_op_tracer_provider_kinesis(self):
248+
BotocoreInstrumentor().uninstrument()
249+
BotocoreInstrumentor().instrument(
250+
tracer_provider=trace_api.NoOpTracerProvider()
251+
)
252+
253+
kinesis = self._make_client("kinesis")
254+
kinesis.list_streams()
255+
256+
spans_list = self.memory_exporter.get_finished_spans()
257+
self.assertEqual(len(spans_list), 0)
258+
207259
@mock_aws
208260
def test_unpatch(self):
209261
kinesis = self._make_client("kinesis")
@@ -213,6 +265,19 @@ def test_unpatch(self):
213265
kinesis.list_streams()
214266
self.assertEqual(0, len(self.memory_exporter.get_finished_spans()))
215267

268+
@mock_aws
269+
def test_no_op_tracer_provider_kms(self):
270+
BotocoreInstrumentor().uninstrument()
271+
BotocoreInstrumentor().instrument(
272+
tracer_provider=trace_api.NoOpTracerProvider()
273+
)
274+
275+
kms = self._make_client("kms")
276+
kms.list_keys(Limit=21)
277+
278+
spans_list = self.memory_exporter.get_finished_spans()
279+
self.assertEqual(len(spans_list), 0)
280+
216281
@mock_aws
217282
def test_uninstrument_does_not_inject_headers(self):
218283
headers = {}
@@ -268,6 +333,19 @@ def test_sts_client(self):
268333
# check for exact attribute set to make sure not to leak any sts secrets
269334
self.assertEqual(expected, dict(span.attributes))
270335

336+
@mock_aws
337+
def test_no_op_tracer_provider_sts(self):
338+
BotocoreInstrumentor().uninstrument()
339+
BotocoreInstrumentor().instrument(
340+
tracer_provider=trace_api.NoOpTracerProvider()
341+
)
342+
343+
sts = self._make_client("sts")
344+
sts.get_caller_identity()
345+
346+
spans_list = self.memory_exporter.get_finished_spans()
347+
self.assertEqual(len(spans_list), 0)
348+
271349
@mock_aws
272350
def test_propagator_injects_into_request(self):
273351
headers = {}
@@ -308,6 +386,19 @@ def check_headers(**kwargs):
308386
finally:
309387
set_global_textmap(previous_propagator)
310388

389+
@mock_aws
390+
def test_no_op_tracer_provider_xray(self):
391+
BotocoreInstrumentor().uninstrument()
392+
BotocoreInstrumentor().instrument(
393+
tracer_provider=trace_api.NoOpTracerProvider()
394+
)
395+
396+
xray_client = self._make_client("xray")
397+
xray_client.put_trace_segments(TraceSegmentDocuments=["str1"])
398+
399+
spans_list = self.memory_exporter.get_finished_spans()
400+
self.assertEqual(len(spans_list), 0)
401+
311402
@mock_aws
312403
def test_override_xray_propagator_injects_into_request(self):
313404
headers = {}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
"""
1616
SQLite instrumentation supporting `sqlite3`_, it can be enabled by
17-
using ``SQLite3Instrumentor``.
17+
using ``SQLite3Instrumentor``. At this time, cursor objects must
18+
be explicitly initialized as shown below to support tracing.
1819
1920
.. _sqlite3: https://docs.python.org/3/library/sqlite3.html
2021
@@ -29,8 +30,9 @@
2930
3031
SQLite3Instrumentor().instrument()
3132
32-
cnx = sqlite3.connect('example.db')
33+
cnx = sqlite3.connect(':memory:')
3334
cursor = cnx.cursor()
35+
cursor.execute("CREATE TABLE test (testField INTEGER)")
3436
cursor.execute("INSERT INTO test (testField) VALUES (123)")
3537
cursor.close()
3638
cnx.close()

opentelemetry-instrumentation/src/opentelemetry/instrumentation/dependencies.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
from logging import getLogger
16-
from typing import Collection, Optional, Union
18+
from typing import Collection
1719

1820
from packaging.requirements import InvalidRequirement, Requirement
1921

@@ -27,10 +29,10 @@
2729

2830

2931
class DependencyConflict:
30-
required: str = None
31-
found: Optional[str] = None
32+
required: str | None = None
33+
found: str | None = None
3234

33-
def __init__(self, required, found=None):
35+
def __init__(self, required: str | None, found: str | None = None):
3436
self.required = required
3537
self.found = found
3638

@@ -40,7 +42,7 @@ def __str__(self):
4042

4143
def get_dist_dependency_conflicts(
4244
dist: Distribution,
43-
) -> Optional[DependencyConflict]:
45+
) -> DependencyConflict | None:
4446
instrumentation_deps = []
4547
extra = "extra"
4648
instruments = "instruments"
@@ -57,8 +59,8 @@ def get_dist_dependency_conflicts(
5759

5860

5961
def get_dependency_conflicts(
60-
deps: Collection[Union[str, Requirement]],
61-
) -> Optional[DependencyConflict]:
62+
deps: Collection[str | Requirement],
63+
) -> DependencyConflict | None:
6264
for dep in deps:
6365
if isinstance(dep, Requirement):
6466
req = dep

opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
OpenTelemetry Base Instrumentor
1818
"""
1919

20+
from __future__ import annotations
21+
2022
from abc import ABC, abstractmethod
2123
from logging import getLogger
22-
from typing import Collection, Optional
24+
from typing import Any, Collection
2325

2426
from opentelemetry.instrumentation._semconv import (
2527
_OpenTelemetrySemanticConventionStability,
@@ -33,7 +35,7 @@
3335

3436

3537
class BaseInstrumentor(ABC):
36-
"""An ABC for instrumentors
38+
"""An ABC for instrumentors.
3739
3840
Child classes of this ABC should instrument specific third
3941
party libraries or frameworks either by using the
@@ -74,18 +76,18 @@ def instrumentation_dependencies(self) -> Collection[str]:
7476
is present in the environment.
7577
"""
7678

77-
def _instrument(self, **kwargs):
79+
def _instrument(self, **kwargs: Any):
7880
"""Instrument the library"""
7981

8082
@abstractmethod
81-
def _uninstrument(self, **kwargs):
83+
def _uninstrument(self, **kwargs: Any):
8284
"""Uninstrument the library"""
8385

84-
def _check_dependency_conflicts(self) -> Optional[DependencyConflict]:
86+
def _check_dependency_conflicts(self) -> DependencyConflict | None:
8587
dependencies = self.instrumentation_dependencies()
8688
return get_dependency_conflicts(dependencies)
8789

88-
def instrument(self, **kwargs):
90+
def instrument(self, **kwargs: Any):
8991
"""Instrument the library
9092
9193
This method will be called without any optional arguments by the
@@ -117,7 +119,7 @@ def instrument(self, **kwargs):
117119
self._is_instrumented_by_opentelemetry = True
118120
return result
119121

120-
def uninstrument(self, **kwargs):
122+
def uninstrument(self, **kwargs: Any):
121123
"""Uninstrument the library
122124
123125
See ``BaseInstrumentor.instrument`` for more information regarding the

0 commit comments

Comments
 (0)