File size: 1,799 Bytes
7a3215f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""One request/response record per backend HTTP call, independent of its transaction."""

from datetime import datetime
from uuid import UUID

from sqlalchemy import Boolean, DateTime, Float, Index, Integer, String
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import Mapped, mapped_column

from app.common.base_model import Base, CreatedAtMixin, IdMixin


class ApiRequestLog(IdMixin, CreatedAtMixin, Base):
    __tablename__ = "api_request_logs"
    __table_args__ = (Index("ix_api_request_logs_created_at", "created_at"),)

    request_id: Mapped[str] = mapped_column(String(128), index=True)
    started_at: Mapped[datetime] = mapped_column(DateTime(timezone=True))
    method: Mapped[str] = mapped_column(String(16))
    path: Mapped[str] = mapped_column(String(2048))
    route: Mapped[str | None] = mapped_column(String(512), index=True)
    status_code: Mapped[int] = mapped_column(Integer, index=True)
    duration_ms: Mapped[float] = mapped_column(Float)
    account_id: Mapped[UUID | None] = mapped_column(index=True)
    session_id: Mapped[UUID | None] = mapped_column(index=True)
    analysis_id: Mapped[str | None] = mapped_column(String(256), index=True)
    analysis_revision: Mapped[int | None] = mapped_column(Integer)
    request_headers: Mapped[dict] = mapped_column(JSONB)
    query_params: Mapped[dict] = mapped_column(JSONB)
    request_payload: Mapped[dict] = mapped_column(JSONB)
    response_headers: Mapped[dict] = mapped_column(JSONB)
    response_payload: Mapped[dict] = mapped_column(JSONB)
    error_code: Mapped[str | None] = mapped_column(String(128))
    exception_type: Mapped[str | None] = mapped_column(String(128))
    response_complete: Mapped[bool] = mapped_column(Boolean)
    service_version: Mapped[str] = mapped_column(String(128))