Skip to content

Commit 07bf70c

Browse files
committed
fix duration
1 parent 9ce5d1c commit 07bf70c

File tree

7 files changed

+142
-116
lines changed

7 files changed

+142
-116
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ repos:
1616
args: [ --fix ]
1717
# Run the formatter.
1818
- id: ruff-format
19+
20+
- repo: https://github.com/pycqa/isort
21+
rev: 5.13.2
22+
hooks:
23+
- id: isort

httpx_logging_client/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from .client import LoggingClient, AsyncLoggingClient
2-
1+
from .client import (
2+
AsyncLoggingClient,
3+
LoggingClient,
4+
)
35

46
__all__ = ("AsyncLoggingClient", "LoggingClient")

httpx_logging_client/client.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import typing
2+
23
import httpx
3-
from httpx import ASGITransport, WSGITransport
4+
from httpx import (
5+
ASGITransport,
6+
WSGITransport,
7+
)
8+
from httpx._config import (
9+
DEFAULT_LIMITS,
10+
Limits,
11+
Proxy,
12+
)
13+
from httpx._types import (
14+
CertTypes,
15+
VerifyTypes,
16+
)
17+
418
from httpx_logging_client.transport import (
519
AsyncHTTPLoggingTransport,
620
HTTPLoggingTransport,
721
)
8-
from httpx._types import CertTypes
9-
from httpx._types import VerifyTypes
10-
from httpx._config import Limits, Proxy, DEFAULT_LIMITS
1122

1223

1324
class LoggingClient(httpx.Client):

httpx_logging_client/transport.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import httpx
44
import structlog
5-
from httpx import Request
5+
from httpx import (
6+
Request,
7+
Response,
8+
)
69
from structlog.types import FilteringBoundLogger
7-
from httpx import Response
8-
910

1011
logger = structlog.get_logger()
1112

@@ -38,12 +39,13 @@ def handle_request(self, request: Request) -> Response:
3839
start_time = time.perf_counter()
3940
try:
4041
response = super().handle_request(request)
42+
end_time = time.perf_counter()
4143
log = log_bind_response(log, response)
4244
response.read()
4345
log.info(
4446
"httpx request",
4547
response_body=response.content.decode(),
46-
duration=time.perf_counter() - start_time,
48+
duration=end_time - start_time,
4749
)
4850
return response
4951
except httpx.HTTPError as exc:
@@ -61,12 +63,13 @@ async def handle_async_request(
6163
start_time = time.perf_counter()
6264
try:
6365
response = await super().handle_async_request(request)
66+
end_time = time.perf_counter()
6467
log = log_bind_response(log, response)
6568
await response.aread()
6669
log.info(
6770
"httpx request",
6871
response_body=response.content.decode(),
69-
duration=time.perf_counter() - start_time,
72+
duration=end_time - start_time,
7073
)
7174
return response
7275
except httpx.HTTPError as exc:

poetry.lock

Lines changed: 104 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ structlog = "^24.2.0"
1313
[tool.poetry.group.dev.dependencies]
1414
mypy = "^1.10.1"
1515
ruff = "^0.5.0"
16+
isort = "^5.13.2"
1617

1718
[build-system]
1819
requires = ["poetry-core"]
1920
build-backend = "poetry.core.masonry.api"
21+
22+
[tool.isort]
23+
multi_line_output = 3
24+
include_trailing_comma = true
25+
force_grid_wrap = 2

test.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)