|
3 | 3 |
|
4 | 4 | import psqlpy |
5 | 5 | import wrapt # type: ignore[import-untyped] |
6 | | - |
7 | 6 | from opentelemetry import trace |
8 | | -from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignore[attr-defined] |
| 7 | +from opentelemetry.instrumentation.instrumentor import ( |
| 8 | + BaseInstrumentor, # type: ignore[attr-defined] |
| 9 | +) |
9 | 10 | from opentelemetry.instrumentation.utils import unwrap |
10 | 11 | from opentelemetry.semconv.trace import ( |
11 | 12 | DbSystemValues, |
|
14 | 15 | ) |
15 | 16 | from opentelemetry.trace import SpanKind |
16 | 17 | from opentelemetry.trace.status import Status, StatusCode |
| 18 | + |
17 | 19 | from otlp_psqlpy.package import _instruments |
18 | 20 | from otlp_psqlpy.version import __version__ |
19 | 21 |
|
20 | | - |
21 | 22 | CONNECTION_METHODS = [ |
22 | 23 | "execute", |
23 | 24 | "execute_batch", |
|
51 | 52 | ] |
52 | 53 |
|
53 | 54 |
|
54 | | -def _construct_span(instance, query, parameters, prepared=None) -> dict: |
| 55 | +def _construct_span( |
| 56 | + instance: psqlpy.Connection | psqlpy.Transaction | psqlpy.Cursor, |
| 57 | + query: str, |
| 58 | + parameters: t.Sequence[t.Any], |
| 59 | + prepared: bool | None = None, |
| 60 | +) -> dict[str, t.Any]: |
55 | 61 | """Get network and database attributes from instance.""" |
56 | 62 | span_attributes = { |
57 | 63 | SpanAttributes.DB_SYSTEM: DbSystemValues.POSTGRESQL.value, |
@@ -108,17 +114,19 @@ def _retrieve_parameter_from_args_or_kwargs( |
108 | 114 |
|
109 | 115 |
|
110 | 116 | class PSQLPyPGInstrumentor(BaseInstrumentor): |
| 117 | + """Instrumentor for PSQLPy.""" |
| 118 | + |
111 | 119 | _leading_comment_remover = re.compile(r"^/\*.*?\*/") |
112 | 120 | _tracer = None |
113 | 121 |
|
114 | | - def __init__(self, capture_parameters=False): |
| 122 | + def __init__(self, capture_parameters: bool = False) -> None: |
115 | 123 | super().__init__() |
116 | 124 | self.capture_parameters = capture_parameters |
117 | 125 |
|
118 | | - def instrumentation_dependencies(self) -> t.Collection[str]: |
| 126 | + def instrumentation_dependencies(self) -> t.Collection[str]: # noqa: D102 |
119 | 127 | return _instruments |
120 | 128 |
|
121 | | - def _instrument(self, **kwargs): |
| 129 | + def _instrument(self, **kwargs: t.Any) -> None: |
122 | 130 | tracer_provider = kwargs.get("tracer_provider") |
123 | 131 | self._tracer = trace.get_tracer( |
124 | 132 | __name__, |
@@ -148,7 +156,7 @@ def _instrument(self, **kwargs): |
148 | 156 | self._do_cursor_execute, |
149 | 157 | ) |
150 | 158 |
|
151 | | - def _uninstrument(self, **__): |
| 159 | + def _uninstrument(self, **__: t.Any) -> None: |
152 | 160 | for cls, methods in [ |
153 | 161 | ( |
154 | 162 | psqlpy.Connection, |
|
0 commit comments