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

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.1.tar.gz (25.1 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.1-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: il_audit-0.1.1.tar.gz
  • Upload date:
  • Size: 25.1 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.1.tar.gz
Algorithm Hash digest
SHA256 7fd016604d6711afda5fc2730b42f31da1e9585766da8c88b649b40bbc64d5d3
MD5 b318413a09eebd137266e3d9e18f8c62
BLAKE2b-256 da880921003359902ba3c464243c0f93e5ac952a6cd3fd1b918c612f6a49c9c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: il_audit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 28.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 176c2cdf7081f6157923055a3089150935a103c69b9841d0a0a40d5346269c3d
MD5 de73225a4a59957a596d108730b0bc16
BLAKE2b-256 21a4719f4f4d00608b6917ac07ad7dfe1e52af68fc89994ecd1ecf1fec050973

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