Coverage for src/couchers/models/logging.py: 100%
23 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-08 00:20 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-08 00:20 +0000
1from sqlalchemy import BigInteger, Boolean, Column, DateTime, Float, String, func
2from sqlalchemy import LargeBinary as Binary
3from sqlalchemy.sql import expression
5from couchers.config import config
6from couchers.models.base import Base
9class APICall(Base):
10 """
11 API call logs
12 """
14 __tablename__ = "api_calls"
15 __table_args__ = {"schema": "logging"}
17 id = Column(BigInteger, primary_key=True)
19 # whether the call was made using an api key or session cookies
20 is_api_key = Column(Boolean, nullable=False, server_default=expression.false())
22 # backend version (normally e.g. develop-31469e3), allows us to figure out which proto definitions were used
23 # note that `default` is a python side default, not hardcoded into DB schema
24 version = Column(String, nullable=False, default=config["VERSION"])
26 # approximate time of the call
27 time = Column(DateTime(timezone=True), nullable=False, server_default=func.now())
29 # the method call name, e.g. "/org.couchers.api.core.API/ListFriends"
30 method = Column(String, nullable=False)
32 # gRPC status code name, e.g. FAILED_PRECONDITION, None if success
33 status_code = Column(String, nullable=True)
35 # handler duration (excluding serialization, etc)
36 duration = Column(Float, nullable=False)
38 # user_id of caller, None means not logged in
39 user_id = Column(BigInteger, nullable=True)
41 # sanitized request bytes
42 request = Column(Binary, nullable=True)
44 # sanitized response bytes
45 response = Column(Binary, nullable=True)
47 # whether response bytes have been truncated
48 response_truncated = Column(Boolean, nullable=False, server_default=expression.false())
50 # the exception traceback, if any
51 traceback = Column(String, nullable=True)
53 # human readable perf report
54 perf_report = Column(String, nullable=True)
56 # details of the browser, if available
57 ip_address = Column(String, nullable=True)
58 user_agent = Column(String, nullable=True)