Skip to content

Commit cbf6a98

Browse files
authored
Merge branch 'main' into add-type-hints-to-dbapi
2 parents 4c87873 + 8302310 commit cbf6a98

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
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-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)