Skip to content

Commit c89052c

Browse files
committed
Update depends and fix tests
1 parent e8cd352 commit c89052c

File tree

11 files changed

+807
-319
lines changed

11 files changed

+807
-319
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
stages: [commit-msg]
1010

1111
- repo: https://github.com/pre-commit/pre-commit-hooks
12-
rev: v4.5.0
12+
rev: v4.6.0
1313
hooks:
1414
- id: check-ast
1515
- id: check-case-conflict
@@ -21,14 +21,14 @@ repos:
2121
- id: trailing-whitespace
2222

2323
- repo: https://github.com/python-formate/flake8-dunder-all
24-
rev: v0.4.0
24+
rev: v0.4.1
2525
hooks:
2626
- id: ensure-dunder-all
2727
exclude: "tests*|examples*"
2828
args: ["--use-tuple"]
2929

3030
- repo: https://github.com/astral-sh/ruff-pre-commit
31-
rev: v0.3.4
31+
rev: v0.5.0
3232
hooks:
3333
- id: ruff
3434
args: ["--fix"]

pdm.lock

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

src/asgi_monitor/integrations/litestar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
def _get_default_span_details(scope: Scope) -> tuple[str, dict[str, Any]]:
36-
method, path = scope["method"], scope["path"] # type: ignore[typeddict-item] # The WebSocket is not supported
36+
method, path = scope["method"], scope["path"] # The WebSocket is not supported
3737
return f"{method} {path}", {SpanAttributes.HTTP_ROUTE: path}
3838

3939

@@ -74,7 +74,7 @@ def __init__(self, app: ASGIApp, config: TracingConfig) -> None:
7474
self.open_telemetry_middleware = build_open_telemetry_middleware(app, config)
7575

7676
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
77-
return await self.open_telemetry_middleware(scope, receive, send) # type: ignore[arg-type]
77+
return await self.open_telemetry_middleware(scope, receive, send) # type: ignore[no-any-return]
7878

7979

8080
def _get_wrapped_send(send: Send, request_span: dict[str, float]) -> Callable:
@@ -146,7 +146,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
146146
self.metrics.inc_responses_count(
147147
method=method,
148148
path=path,
149-
status_code=request_span["status_code"], # type: ignore[arg-type]
149+
status_code=request_span["status_code"],
150150
)
151151
self.metrics.remove_request_in_progress(method=method, path=path)
152152

src/asgi_monitor/integrations/starlette.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async def __call__(
115115
if scope["type"] != "http":
116116
return await self.app(scope, receive, send)
117117

118-
return await self.open_telemetry_middleware(scope, receive, send) # type: ignore[arg-type]
118+
return await self.open_telemetry_middleware(scope, receive, send) # type: ignore[no-any-return]
119119

120120

121121
class MetricsMiddleware(BaseHTTPMiddleware):

src/asgi_monitor/logging/configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def _configure_default_logging(
7171

7272
formatter = structlog.stdlib.ProcessorFormatter(
7373
foreign_pre_chain=default_processors,
74-
processors=logging_processors, # type: ignore[arg-type]
74+
processors=logging_processors,
7575
)
7676

7777
handler = logging.StreamHandler(stream=sys.stdout)

src/asgi_monitor/logging/trace_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def extract_opentelemetry_trace_meta(
1818
return event_dict
1919

2020
ctx = span.get_span_context()
21-
service_name = trace.get_tracer_provider().resource.attributes["service.name"] # type: ignore[attr-defined]
21+
service_name = trace.get_tracer_provider().resource.attributes["service.name"]
2222
parent = getattr(span, "parent", None)
2323

2424
event_dict["span_id"] = trace.format_span_id(ctx.span_id)

src/asgi_monitor/logging/uvicorn/log_config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
5252
]
5353

5454
super().__init__(
55-
processors=processors, # type: ignore[arg-type]
55+
processors=processors,
5656
foreign_pre_chain=_build_default_processors(json_format=False),
5757
pass_foreign_args=True, # for args from record.args in positional_args
5858
)
@@ -68,7 +68,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
6868
]
6969

7070
super().__init__(
71-
processors=processors, # type: ignore[arg-type]
71+
processors=processors,
7272
foreign_pre_chain=_build_default_processors(json_format=False),
7373
pass_foreign_args=True, # for args from record.args in positional_args
7474
)
@@ -91,7 +91,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
9191
]
9292

9393
super().__init__(
94-
processors=processors, # type: ignore[arg-type]
94+
processors=processors,
9595
foreign_pre_chain=_build_default_processors(json_format=True),
9696
pass_foreign_args=True, # for args from record.args in positional_args
9797
)
@@ -107,7 +107,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
107107
]
108108

109109
super().__init__(
110-
processors=processors, # type: ignore[arg-type]
110+
processors=processors,
111111
foreign_pre_chain=_build_default_processors(json_format=True),
112112
pass_foreign_args=True, # for args from record.args in positional_args
113113
)
@@ -134,7 +134,7 @@ def build_uvicorn_log_config(
134134
default = UvicornDefaultJSONFormatter
135135
access = UvicornAccessJSONFormatter if not include_trace else TraceUvicornAccessJSONFormatter
136136
else:
137-
default = UvicornDefaultConsoleFormatter # type: ignore[assignment]
137+
default = UvicornDefaultConsoleFormatter
138138
access = UvicornAccessConsoleFormatter if not include_trace else TraceUvicornAccessConsoleFormatter
139139

140140
return {

tests/integration/litestar/test_middlewares.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ async def test_tracing() -> None:
4242
first_span, second_span, third_span = cast("tuple[Span, Span, Span]", exporter.get_finished_spans())
4343

4444
assert response.status_code == 200
45-
assert_that(first_span.attributes).is_equal_to({"http.status_code": 200, "type": "http.response.start"})
46-
assert_that(second_span.attributes).is_equal_to({"type": "http.response.body"})
45+
assert_that(first_span.attributes).is_equal_to(
46+
{"http.status_code": 200, "asgi.event.type": "http.response.start"},
47+
)
48+
assert_that(second_span.attributes).is_equal_to({"asgi.event.type": "http.response.body"})
4749
assert_that(third_span.attributes).is_equal_to(
4850
{
4951
"http.scheme": "http",

tests/integration/starlette/test_middlewares.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ async def test_tracing() -> None:
3939
first_span, second_span, third_span = cast("tuple[Span, Span, Span]", exporter.get_finished_spans())
4040

4141
assert response.status_code == 200
42-
assert_that(first_span.attributes).is_equal_to({"http.status_code": 200, "type": "http.response.start"})
43-
assert_that(second_span.attributes).is_equal_to({"type": "http.response.body"})
42+
assert_that(first_span.attributes).is_equal_to(
43+
{"http.status_code": 200, "asgi.event.type": "http.response.start"},
44+
)
45+
assert_that(second_span.attributes).is_equal_to({"asgi.event.type": "http.response.body"})
4446
assert_that(third_span.attributes).is_equal_to(
4547
{
4648
"http.scheme": "http",
4749
"http.host": "testserver",
4850
"net.host.port": 80,
4951
"http.flavor": "1.1",
5052
"http.target": "/",
53+
"net.peer.ip": "testclient",
54+
"net.peer.port": 50000,
5155
"http.url": "http://testserver/",
5256
"http.method": "GET",
5357
"http.server_name": "testserver",
@@ -71,8 +75,10 @@ async def test_tracing_with_empty_routes() -> None:
7175
# Assert
7276
first_span, second_span, third_span = cast("tuple[Span, Span, Span]", exporter.get_finished_spans())
7377
assert response.status_code == 405
74-
assert_that(first_span.attributes).is_equal_to({"http.status_code": 405, "type": "http.response.start"})
75-
assert_that(second_span.attributes).is_equal_to({"type": "http.response.body"})
78+
assert_that(first_span.attributes).is_equal_to(
79+
{"http.status_code": 405, "asgi.event.type": "http.response.start"},
80+
)
81+
assert_that(second_span.attributes).is_equal_to({"asgi.event.type": "http.response.body"})
7682
assert_that(third_span.attributes).is_equal_to(
7783
{
7884
"http.scheme": "http",
@@ -86,6 +92,8 @@ async def test_tracing_with_empty_routes() -> None:
8692
"http.user_agent": "testclient",
8793
"http.status_code": 405,
8894
"http.route": "/",
95+
"net.peer.ip": "testclient",
96+
"net.peer.port": 50000,
8997
},
9098
)
9199

@@ -103,8 +111,10 @@ async def test_tracing_partial_match() -> None:
103111
# Assert
104112
first_span, second_span, third_span = cast("tuple[Span, Span, Span]", exporter.get_finished_spans())
105113
assert response.status_code == 404
106-
assert_that(first_span.attributes).is_equal_to({"http.status_code": 404, "type": "http.response.start"})
107-
assert_that(second_span.attributes).is_equal_to({"type": "http.response.body"})
114+
assert_that(first_span.attributes).is_equal_to(
115+
{"http.status_code": 404, "asgi.event.type": "http.response.start"},
116+
)
117+
assert_that(second_span.attributes).is_equal_to({"asgi.event.type": "http.response.body"})
108118
assert_that(third_span.attributes).is_equal_to(
109119
{
110120
"http.scheme": "http",
@@ -117,6 +127,8 @@ async def test_tracing_partial_match() -> None:
117127
"http.server_name": "testserver",
118128
"http.user_agent": "testclient",
119129
"http.status_code": 404,
130+
"net.peer.ip": "testclient",
131+
"net.peer.port": 50000,
120132
},
121133
)
122134

tests/unit/metrics/test_get_latest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def add_metrics() -> None:
6969

7070
def test_get_latest_metrics_multiprocess(tmpdir: Path, manager: MetricsManager) -> None:
7171
# Arrange
72-
multiprocessing.set_start_method("spawn")
72+
multiprocessing.set_start_method("spawn", force=True)
7373
os.environ["PROMETHEUS_MULTIPROC_DIR"] = str(tmpdir)
7474
processes = [Process(target=add_metrics) for _ in range(10)]
7575

0 commit comments

Comments
 (0)