Version 0.2.0
All checks were successful
Run linters on applied template / Python 3.13 lint and build (push) Successful in 54s

Changes:
- add metrics dispencer
- add basic authentication dependency
- enable GZIP middleware
- add !env() example to deploy section
- update dependencies state attribute name
This commit is contained in:
2025-11-30 16:59:25 +03:00
parent afe5d882ac
commit 34c1347402
16 changed files with 180 additions and 74 deletions

View File

@@ -4,11 +4,12 @@ import asyncio
from typing import Literal
import aiohttp
from fastapi import HTTPException
from fastapi import HTTPException, Request
from fastapi.responses import JSONResponse
from opentelemetry import trace
from starlette import status
from {{project_slug}}.dependencies import auth_dep
from {{project_slug}}.schemas import PingResponse
from {{project_slug}}.utils.observability import get_span_headers
@@ -64,9 +65,7 @@ async def get_exception(error_type: Literal["RuntimeError", "DebugException", "D
status_code=status.HTTP_200_OK,
)
async def tracing_check():
"""
Add event to span, and sleep 2 seconds inside an inner span.
"""
"""Add event to span, and sleep 2 seconds inside an inner span."""
span = trace.get_current_span()
span.add_event("successful log entry", attributes={"parameters": "go here"})
@@ -83,9 +82,7 @@ async def tracing_check():
status_code=status.HTTP_200_OK,
)
async def inner_get(host: str = "http://127.0.0.1:8080"):
"""
Perform GET request with span proxying to get more complicated trace.
"""
"""Perform GET request with span proxying to get more complicated trace."""
def perform_get(session: aiohttp.ClientSession) -> asyncio.Task:
return asyncio.create_task(
@@ -112,3 +109,15 @@ async def inner_get(host: str = "http://127.0.0.1:8080"):
)
return JSONResponse({"inner_results": inner_results})
@debug_errors_router.get(
"/authentication_info",
status_code=status.HTTP_200_OK,
)
async def authentication_info(request: Request):
"""Check authentication data from `Authorization` and `X-API-Key` headers."""
auth = auth_dep.obtain(request)
return JSONResponse({"auth_data": {"x-api-key": auth.api_key, "jwt_payload": auth.jwt_payload}})