Skip to content

Commit 4a03955

Browse files
📝 Add docstrings to codex/fix-cache-key-comparison-logic (#292)
Docstrings generation was requested by @shayancoin. * #150 (comment) The following files were modified: * `backend/api/config.py` * `backend/api/instrumentation_boot.py` * `backend/api/main.py` * `backend/api/metrics.py` Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Shayan <shayan@coin.link>
1 parent 0c72839 commit 4a03955

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

backend/api/config.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,18 @@ class Settings(BaseSettings):
7676
@field_validator("hygraph_webhook_secret")
7777
@classmethod
7878
def _validate_hygraph_webhook_secret(cls, value: str) -> str:
79-
"""Ensure the Hygraph webhook secret is populated and trimmed."""
79+
"""
80+
Validate and return a trimmed Hygraph webhook secret.
81+
82+
Parameters:
83+
value (str): The raw webhook secret from environment or configuration.
84+
85+
Returns:
86+
str: The webhook secret with surrounding whitespace removed.
87+
88+
Raises:
89+
ValueError: If `value` is empty or contains only whitespace.
90+
"""
8091

8192
if not value or not value.strip():
8293
raise ValueError(
@@ -113,12 +124,22 @@ def get_settings() -> Settings:
113124

114125

115126
def get_fastapi_settings() -> Dict[str, Any]:
116-
"""Get FastAPI application metadata for documentation UIs."""
127+
"""
128+
Provide FastAPI application metadata used by documentation UIs.
129+
130+
Returns:
131+
dict: Mapping with the FastAPI documentation settings:
132+
- "title": API title.
133+
- "description": Short API description.
134+
- "version": API version string.
135+
- "docs_url": URL path for the Swagger UI.
136+
- "redoc_url": URL path for the ReDoc UI.
137+
"""
117138

118139
return {
119140
"title": "MVP API",
120141
"description": "API for MVP application",
121142
"version": "0.1.0",
122143
"docs_url": "/docs",
123144
"redoc_url": "/redoc",
124-
}
145+
}

backend/api/metrics.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,23 @@ def observe_http_request(
119119
status_code: int | str,
120120
duration_seconds: float,
121121
) -> None:
122-
"""Record a single HTTP request observation."""
122+
"""
123+
Record metrics for a single HTTP request.
124+
125+
Parameters:
126+
service (str): Logical service name to label the metric (written to `service` / `service.name`).
127+
route (str): Request route to label the metric (written to `route` / `http.route`).
128+
method (str): HTTP method to label the metric (written to `method` / `http.method`).
129+
status_code (int | str): HTTP status code used as the `status` label; if an integer can be derived,
130+
it is also recorded as the `http.status_code` attribute for OpenTelemetry metrics.
131+
duration_seconds (float): Request duration in seconds to record in latency histograms.
132+
133+
Description:
134+
Increments the Prometheus request counter and records the request duration histogram using the
135+
provided labels. If OpenTelemetry metrics are initialized, records equivalent OTEL counter and
136+
histogram measurements with attributes `service.name`, `http.route`, `http.method`, and
137+
`http.status_code` (when `status_code` can be coerced to an integer).
138+
"""
123139

124140
status_label = str(status_code)
125141
http_requests_total.labels(
@@ -148,9 +164,15 @@ def observe_http_request(
148164

149165

150166
def observe_lcp(*, app: str, seconds: float) -> None:
151-
"""Record a Largest Contentful Paint measurement in seconds."""
167+
"""Record a Largest Contentful Paint (LCP) measurement for an application.
168+
169+
Records the value to the module's LCP histogram and, when OpenTelemetry is initialized, to the OTEL LCP histogram with the `app` attribute.
170+
171+
Parameters:
172+
app (str): Application identifier used as the metric label.
173+
seconds (float): LCP value in seconds.
174+
"""
152175

153176
web_vitals_lcp.labels(app=app).observe(seconds)
154177
if _web_vitals_lcp_histogram is not None:
155178
_web_vitals_lcp_histogram.record(seconds, {"app": app})
156-

0 commit comments

Comments
 (0)