Add the OpenTelemetry API and SDK, the OTLP over HTTP exporter and the FastAPI and asyncpg instrumentations to the lock, and a platform module that builds one resource per process (service.name, service.version, service.instance.id as hostname and pid, deployment.environment.name from OTEL_RESOURCE_ATTRIBUTES), batch processors for traces and logs, a periodic metric reader, PostgreSQL client spans and a bounded shutdown in a daemon thread instead of the 30 s flush of the SDK. The SDK stays off without a Collector address or with OTEL_SDK_DISABLED. The sampler lets only server, consumer and producer spans open a trace, so readiness probes, outbox polls and sweeps do not become one-span traces. Log records carry trace_id and span_id in stdout and go to OTLP through a handler that keeps only the allowlisted fields, and deferred event subscribers now run in the context the event was emitted in, so audit records stay linked to their request or job. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
130 lines
4.0 KiB
TOML
130 lines
4.0 KiB
TOML
[project]
|
|
name = "mtusi-messenger"
|
|
version = "1.6.0"
|
|
description = "Лабораторная 6 «Наблюдаемость: OpenTelemetry и Grafana», МТУСИ"
|
|
requires-python = ">=3.14,<3.15"
|
|
dependencies = [
|
|
"fastapi>=0.118.0",
|
|
"uvicorn[standard]>=0.37.0",
|
|
"pydantic>=2.11.0",
|
|
"pydantic-settings>=2.11.0",
|
|
"dishka>=1.7.0",
|
|
"structlog>=26.1.0",
|
|
"gunicorn>=26.2.0",
|
|
"orjson>=3.12.0",
|
|
"asyncpg>=0.32.0",
|
|
"argon2-cffi>=25.1.0",
|
|
"uvicorn-worker>=0.4.0",
|
|
"redis>=8.1.0",
|
|
"aiobotocore>=3.10.0",
|
|
"pillow>=12.0.0",
|
|
"faststream[otel,rabbit]>=0.7.2,<0.8",
|
|
"dishka-faststream>=0.1",
|
|
"opentelemetry-api>=1.45.1,<1.46",
|
|
"opentelemetry-sdk>=1.45.1,<1.46",
|
|
"opentelemetry-exporter-otlp-proto-http>=1.45.1,<1.46",
|
|
"opentelemetry-instrumentation-fastapi==0.66b1",
|
|
"opentelemetry-instrumentation-asyncpg==0.66b1",
|
|
]
|
|
|
|
[dependency-groups]
|
|
dev = [
|
|
"pytest>=8.4.0",
|
|
"pytest-asyncio>=1.2.0",
|
|
"httpx>=0.28.0",
|
|
"ruff>=0.14.0",
|
|
"ty>=0.0.1a21",
|
|
]
|
|
|
|
[build-system]
|
|
requires = ["hatchling"]
|
|
build-backend = "hatchling.build"
|
|
|
|
[tool.hatch.build.targets.wheel]
|
|
packages = ["src/messenger"]
|
|
|
|
[tool.ruff]
|
|
line-length = 100
|
|
target-version = "py314"
|
|
src = ["src", "student-tests"]
|
|
extend-exclude = ["tests", "scripts/check_contract.py", "scripts/validate_openapi.py"]
|
|
per-file-target-version = { "scripts/*.py" = "py39" }
|
|
|
|
[tool.ruff.format]
|
|
indent-style = "space"
|
|
quote-style = "double"
|
|
|
|
[tool.ruff.lint]
|
|
select = [
|
|
"E",
|
|
"W",
|
|
"F",
|
|
"I",
|
|
"N",
|
|
"UP",
|
|
"B",
|
|
"A",
|
|
"C4",
|
|
"DTZ",
|
|
"T20",
|
|
"SIM",
|
|
"TID",
|
|
"PTH",
|
|
"RUF",
|
|
"ASYNC",
|
|
"S",
|
|
"ARG",
|
|
"PL",
|
|
]
|
|
ignore = [
|
|
"PLR0913",
|
|
"RUF001",
|
|
"RUF002",
|
|
"RUF003",
|
|
"S104",
|
|
"BLE001",
|
|
]
|
|
|
|
[tool.ruff.lint.per-file-ignores]
|
|
"student-tests/**" = ["S101", "S105", "S106", "S603", "S607", "PLR2004", "ARG001", "ARG002", "T20", "TID251"]
|
|
"scripts/*.py" = ["T20", "S603", "S607", "S310", "PLR2004", "TID251"]
|
|
"scripts/pipeline_suite.py" = ["T20", "S603", "S607", "S310", "PLR2004", "TID251", "E402", "S608"]
|
|
"scripts/pipeline_evidence.py" = ["T20", "S603", "S607", "S310", "PLR2004", "TID251", "E402"]
|
|
"src/messenger/*/infrastructure/**" = ["TID251", "ARG002"]
|
|
"src/messenger/*/domain/errors.py" = ["N818"]
|
|
"src/messenger/*/application/errors.py" = ["N818"]
|
|
"src/messenger/*/entrypoints/**" = ["TID251", "N818", "PLR0917", "S105"]
|
|
"src/messenger/shared/config.py" = ["ARG002", "ARG003"]
|
|
"src/messenger/main.py" = ["TID251"]
|
|
"src/messenger/migrate.py" = ["TID251"]
|
|
"src/messenger/relay.py" = ["TID251"]
|
|
"src/messenger/worker.py" = ["TID251"]
|
|
"src/messenger/admin.py" = ["TID251"]
|
|
"src/messenger/gunicorn_conf.py" = ["TID251", "ARG002", "RUF012"]
|
|
|
|
[tool.ruff.lint.flake8-tidy-imports.banned-api]
|
|
"messenger.shared.infrastructure".msg = "Домен и слой приложения не импортируют инфраструктуру: зависимость идёт через порт."
|
|
"messenger.identity.infrastructure".msg = "Домен и слой приложения не импортируют инфраструктуру: зависимость идёт через порт."
|
|
"messenger.messaging.infrastructure".msg = "Домен и слой приложения не импортируют инфраструктуру: зависимость идёт через порт."
|
|
"messenger.attachments.infrastructure".msg = "Домен и слой приложения не импортируют инфраструктуру: зависимость идёт через порт."
|
|
|
|
[tool.ruff.lint.isort]
|
|
known-first-party = ["messenger"]
|
|
|
|
[tool.ty.src]
|
|
include = ["src", "student-tests"]
|
|
|
|
[tool.ty.rules]
|
|
unresolved-import = "error"
|
|
invalid-argument-type = "error"
|
|
possibly-missing-attribute = "warn"
|
|
|
|
[tool.pytest.ini_options]
|
|
testpaths = ["student-tests"]
|
|
asyncio_mode = "auto"
|
|
asyncio_default_fixture_loop_scope = "function"
|
|
addopts = "-q --strict-markers -m 'not stack'"
|
|
markers = [
|
|
"stack: black-box проверки против поднятого compose-стенда (make test-faults)",
|
|
]
|