Skip to main content

Cross-app audit and analytics logging for Locaria Intelligence Layer

Project description

il-audit — Intelligence Layer audit & analytics

Cross-app BigQuery audit logging for intelligence-layer-ingest and intelligence-layer-chat.

Install

Local dev (sibling repo):

pip install -e ../intelligence-layer-audit

Production pin (PyPI, after release):

"il-audit>=0.1.3",

Or from Git:

"il-audit @ git+https://github.com/Locaria/intelligence-layer-audit@v0.1.0",

See PUBLISHING.md for release → PyPI workflow (same as locaria-integrated-testing).

Package layout

il_audit/
  config/
    audit_settings.py       # runtime settings (env + fallbacks)
    cost_catalog.py         # service/operation/resource constants
    cost_rates_loader.py    # seed JSON / BQ cost_rates loader
    fallbacks/              # bundled JSON defaults
    stores/
      audit_schema_store.py # BQ table ids + schema builders
  builders/
    envelope_builder.py     # shared row builder
  taxonomy.py               # event type constants
  emit.py, writer.py, ...   # runtime modules
  __init__.py               # public API re-exports

Import the stable API from the package root:

from il_audit import emit, AuditContext, flush_audit_writer

Configuration

All defaults live in bundled JSON — never hardcode prices or dataset names in application code.

File Purpose
il_audit/config/fallbacks/audit_defaults.json Dataset, flush tuning, default cost_rates_source
il_audit/config/fallbacks/cost_rates_seed.json Interim pricing catalog (until BQ cost_rates is scraped)
il_audit/config/cost_catalog.py Stable service/operation/resource identifier constants
il_audit/config/audit_settings.py Runtime settings (get_audit_settings)
il_audit/config/stores/audit_schema_store.py BigQuery table ids and schema builders
Variable Default (from JSON) Purpose
IL_ENABLE_AUDIT_LOGS true Master switch (also respects IL_ENABLE_BQ_LOGS)
IL_BQ_AUDIT_DATASET intelligence_layer_logs BQ dataset
IL_BQ_LOGS_PROJECT GCP project (GOOGLE_CLOUD_PROJECT / GCP_PROJECT fallback)
IL_COST_RATES_SOURCE seed seed or bigquery (authoritative catalog from cost_rates table)
IL_COST_RATES_CACHE_SECONDS 3600 In-memory rate cache TTL
IL_AUDIT_WRITE_QUEUE_MAX_SIZE 10000 Max pending rows before drop
IL_AUDIT_STORE_QUERY_TEXT true Store full chat questions in BQ (phase 2)

When IL_COST_RATES_SOURCE=bigquery, rates load from {project}.{dataset}.cost_rates. A scheduled-tasks job will scrape GCP pricing docs and maintain that table. Until then, seed JSON is used and rows are tagged pricing_source=seed_catalog.

Usage

from il_audit import AuditContext, emit
from il_audit import taxonomy as T

emit(
    T.AUTH_LOGIN_SUCCEEDED,
    context=AuditContext(app="ingest", actor_uid=uid, actor_email=email),
    status="succeeded",
    action="login",
)

Browser beacons

Mount the FastAPI router with host auth (ingest example):

from il_audit.beacon_router import create_beacon_router

app.include_router(
    create_beacon_router(
        app_name="ingest",
        get_context=audit_context_from_request,
        require_auth=require_beacon_auth,
    ),
)

Only UI_* event types from taxonomy.BEACON_EVENT_TYPES are accepted.

HTML convention: mark elements with data-il-audit-* attributes — see documentation/ui-beacon-convention.md. Host apps ship il_audit/static/audit_beacon.js (or a copy) with auditFieldsFromElement() and auditTrack().

Chat adoption (phase 2)

  1. Add same il-audit dep to chat
  2. Mount create_beacon_router(app_name="chat", get_context=...)
  3. Emit chat_turns on POST /query with client conversation_session_id
  4. See documentation/chat-phase2.md

SQL

Operator-run views: sql/analytics_views.sql

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

il_audit-0.1.3.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

il_audit-0.1.3-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file il_audit-0.1.3.tar.gz.

File metadata

  • Download URL: il_audit-0.1.3.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for il_audit-0.1.3.tar.gz
Algorithm Hash digest
SHA256 610ce365910f4f16ea916efb200a3d0d515236e0a4f725d9fd30911b787f53be
MD5 99819e5027ff23e2a6f53a9088e4bd60
BLAKE2b-256 57e75879c0e40daab2957e63ef724ca1196918aaf08e29080f5565d2a43a79af

See more details on using hashes here.

File details

Details for the file il_audit-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: il_audit-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for il_audit-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9a5f274dd3ef805f977ba603841f8d59e789ef80250a090177568b49b51b7fa3
MD5 03fb3e55f0ac659246372579acd7d42c
BLAKE2b-256 d7cba24b5508906ebc3251eb691e3c2f1ebe5b126330f060da920d071eda21ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page