Bound Tempo blocks and complete telemetry diagnostics

This commit is contained in:
Самохвалов Андрей Ремович
2026-10-02 17:06:13 +03:00
parent 43bcde73de
commit f1963e5f19
5 changed files with 36 additions and 10 deletions
+11 -5
View File
@@ -14,6 +14,8 @@ import psycopg
from argon2 import PasswordHasher
from argon2.exceptions import InvalidHashError, VerificationError
from fastapi import HTTPException
from opentelemetry import trace
from opentelemetry.trace import Status, StatusCode
from psycopg.errors import UniqueViolation
from psycopg_pool import PoolTimeout
@@ -21,6 +23,7 @@ from . import db
from .auth import BASIC_CHALLENGE, BEARER_CHALLENGE, token_hash, unauthorized
password_hasher = PasswordHasher()
tracer = trace.get_tracer(__name__)
def timestamp(value: datetime) -> str:
@@ -53,11 +56,14 @@ def decode_cursor(cursor: str | None, resource: str) -> tuple[datetime, UUID] |
@contextmanager
def connection():
try:
with db.pool().connection() as conn:
yield conn
except (psycopg.Error, PoolTimeout, OSError):
raise HTTPException(503) from None
with tracer.start_as_current_span("db.store", record_exception=False, set_status_on_exception=False) as span:
span.set_attribute("db.system.name", "postgresql")
try:
with db.pool().connection() as conn:
yield conn
except (psycopg.Error, PoolTimeout, OSError):
span.set_status(Status(StatusCode.ERROR))
raise HTTPException(503) from None
def user_view(row: dict) -> dict: