Audit Context Helper (audit/helpers.py)

Observal · observal-server/services/audit/helpers.py · python · Apache-2.0
security, infra, integration, fw:starlette

Sets business context on HTTP requests for audit middleware logging in Starlette applications.

# Source: https://github.com/Observal/Observal | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
# SPDX-FileCopyrightText: 2026 Hari Srinivasan <harisrini21@gmail.com>
# SPDX-License-Identifier: Apache-2.0

"""Helpers for route handlers to enrich audit entries."""

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from starlette.requests import Request


def audit_detail(
    request: Request,
    *,
    action: str = "",
    resource_type: str = "",
    resource_id: str = "",
    resource_name: str = "",
    detail: str = "",
) -> None:
    """Set business context on the request for the audit middleware."""
    if action:
        request.sta

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key