:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import structlog
from llm_gateway.auth.models import AuthenticatedUser
from llm_gateway.metrics.prometheus import RATE_LIMIT_EXCEEDED
from llm_gateway.rate_limiting.redis_limiter import RateLimiter
logger = structlog.get_logger(__name__)
async def check_rate_limit(user: AuthenticatedUser, limiter: RateLimiter, product: str = "unknown") -> bool:
allowed, scope = await limiter.check(user.user_id)
if not allowed and scope:
RATE_LIMIT_EXCEEDED.labels(scope=scope, product=product).inc()
logger.warning("rate_limit_exceeded", user_id=user.user_id, scope=scope, product=product)
return allowed