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.2",

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.

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.2.tar.gz (25.8 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.2-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: il_audit-0.1.2.tar.gz
  • Upload date:
  • Size: 25.8 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.2.tar.gz
Algorithm Hash digest
SHA256 92c77b6a92ad07100108c32c895fd4b739bb169379166aee353859aee98ef73d
MD5 b2c167a1ab8cadaacb63be4d6ac8fc52
BLAKE2b-256 72cbd989c79cf692d6e74b030da197e2a176954026afd1d3b809477dad57694d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: il_audit-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 28.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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 98a9594da4518cc130d870ebe236c1ac8b6dde55aa0da9fa4780f3d2531fa765
MD5 bade42651bbbb622430a2a95089a3dbf
BLAKE2b-256 9d51b60c375fdf505d0e88d4f60f8539e0736e6ef07efcee60527fb8787941de

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