Skip to content

Commit 9345fb7

Browse files
authored
Merge pull request #4 from oliverlambson/master
2 parents 84b2540 + 9157fbc commit 9345fb7

File tree

4 files changed

+79
-39
lines changed

4 files changed

+79
-39
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,21 @@ repos:
1414
hooks:
1515
- id: add-trailing-comma
1616

17-
- repo: local
17+
- repo: https://github.com/psf/black
18+
rev: 25.1.0
1819
hooks:
1920
- id: black
20-
name: Format with Black
21-
entry: poetry run black
22-
language: system
23-
types: [python]
2421

22+
- repo: https://github.com/astral-sh/ruff-pre-commit
23+
rev: v0.9.5
24+
hooks:
2525
- id: ruff
26-
name: Run ruff lints
27-
entry: poetry run ruff
28-
language: system
29-
pass_filenames: false
30-
types: [python]
3126
args:
32-
- "check"
3327
- "--fix"
3428
- "otlp_psqlpy"
3529

30+
- repo: https://github.com/pre-commit/mirrors-mypy
31+
rev: v1.15.0
32+
hooks:
3633
- id: mypy
37-
name: Validate types with MyPy
38-
entry: poetry run mypy
39-
language: system
40-
pass_filenames: false
41-
types: [python]
42-
args:
43-
- ./otlp_psqlpy
34+
additional_dependencies: ["."]

otlp_psqlpy/__init__.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
import typing as t
3+
from collections.abc import Awaitable, Mapping, Sequence
34

45
import psqlpy
56
import wrapt # type: ignore[import-untyped]
@@ -76,7 +77,7 @@ def _construct_span(
7677
if hosts:
7778
span_attributes[SpanAttributes.SERVER_ADDRESS] = ", ".join(hosts)
7879
span_attributes[SpanAttributes.SERVER_PORT] = ", ".join(
79-
[str(port) for port in ports]
80+
[str(port) for port in ports],
8081
)
8182
span_attributes[SpanAttributes.NETWORK_TRANSPORT] = (
8283
NetTransportValues.IP_TCP.value
@@ -85,7 +86,7 @@ def _construct_span(
8586
elif host_addrs:
8687
span_attributes[SpanAttributes.SERVER_ADDRESS] = ", ".join(host_addrs)
8788
span_attributes[SpanAttributes.SERVER_PORT] = ", ".join(
88-
[str(port) for port in ports]
89+
[str(port) for port in ports],
8990
)
9091
span_attributes[SpanAttributes.NETWORK_TRANSPORT] = (
9192
NetTransportValues.IP_TCP.value
@@ -171,7 +172,13 @@ def _uninstrument(self, **__: t.Any) -> None:
171172
for method_name in methods:
172173
unwrap(cls, method_name)
173174

174-
async def _do_execute(self, func, instance, args, kwargs):
175+
async def _do_execute(
176+
self,
177+
func: t.Callable[..., Awaitable[t.Any]],
178+
instance: t.Union[psqlpy.Connection, psqlpy.Transaction, psqlpy.Cursor],
179+
args: Sequence[t.Any],
180+
kwargs: Mapping[str, t.Any],
181+
) -> t.Any:
175182
exception = None
176183
params = getattr(instance, "_params", {})
177184
name = args[0] if args else params.get("database", "postgresql")
@@ -182,20 +189,20 @@ async def _do_execute(self, func, instance, args, kwargs):
182189
except IndexError:
183190
name = ""
184191

185-
with self._tracer.start_as_current_span(
192+
with self._tracer.start_as_current_span( # type: ignore[union-attr]
186193
name,
187194
kind=SpanKind.CLIENT,
188195
) as span:
189196
if span.is_recording():
190197
span_attributes = _construct_span(
191198
instance,
192-
_retrieve_parameter_from_args_or_kwargs(
199+
_retrieve_parameter_from_args_or_kwargs( # type: ignore[arg-type]
193200
parameter_name="querystring",
194201
parameter_index=0,
195202
args=args,
196203
kwargs=kwargs,
197204
),
198-
_retrieve_parameter_from_args_or_kwargs(
205+
_retrieve_parameter_from_args_or_kwargs( # type: ignore[arg-type]
199206
parameter_name="parameters",
200207
parameter_index=1,
201208
args=args,
@@ -222,13 +229,19 @@ async def _do_execute(self, func, instance, args, kwargs):
222229

223230
return result
224231

225-
async def _do_cursor_execute(self, func, instance, args, kwargs):
232+
async def _do_cursor_execute(
233+
self,
234+
func: t.Callable[..., Awaitable[t.Any]],
235+
instance: psqlpy.Cursor,
236+
args: Sequence[t.Any],
237+
kwargs: Mapping[str, t.Any],
238+
) -> t.Any:
226239
"""Wrap cursor based functions. For every call this will generate a new span."""
227240
exception = None
228241

229242
stop = False
230-
with self._tracer.start_as_current_span(
231-
f"CURSOR",
243+
with self._tracer.start_as_current_span( # type: ignore[union-attr]
244+
"CURSOR",
232245
kind=SpanKind.CLIENT,
233246
) as span:
234247
if span.is_recording():

0 commit comments

Comments
 (0)