adding-activity-logging

Adds audit-trail activity logging to Django models in PostHog.

713|118|Updated Aug 11, 2020
One-click install
npx skills add https://github.com/PostHog/posthog-foss --skill adding-activity-logging
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: adding-activity-logging
Source: https://github.com/PostHog/posthog-foss/tree/main/.agents/skills/adding-activity-logging
Command: npx skills add https://github.com/PostHog/posthog-foss --skill adding-activity-logging

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

When a Django model's writes must appear in PostHog's Activity side panel or advanced activity logs, developers need to wire up ModelActivityMixin, signal receivers, scope enums, and bulk-write logging correctly—missing any step produces a silently incomplete audit trail.

Core Features & Use Cases

  • Write-path auditing: Enumerates every write path (save, QuerySet.update, bulk_create, webhooks, tasks) so no change goes unlogged.
  • Receiver and scope wiring: Guides adding ModelActivityMixin, ActivityScope entries in backend and frontend, a receiver module imported in apps.py ready(), and the repo-invariant baseline entry.
  • Bulk writes and separate databases: Covers manual bulk_log_activity calls and passing using=router.db_for_write for products routed to their own database.
  • Use Case: You add a new product model and need every create, update, and delete to show who changed what in the Activity panel, including changes made by background jobs.

Quick Start

Add activity logging to my Django model so all of its writes appear in the PostHog activity log.

Frequently Asked Questions about adding-activity-logging

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add activity logging to a Django model in PostHog?

Add ModelActivityMixin first in the model's bases, register the class name in the ActivityScope enum in both backend and frontend, then create a receiver module with a model_activity_signal receiver that calls changes_between and log_activity, imported in the app's ready() method.

Why is my model change missing from the activity log?

Common causes are the receiver module not being imported in ready(), the write bypassing save() via QuerySet.update or bulk_create, only excluded fields changing, or transaction management deferring the write to a commit that never happened. Check each cause in order.

Does ModelActivityMixin capture bulk updates and raw SQL?

No. The mixin only hooks save() and delete(), so QuerySet.update(), bulk_create(), bulk_update(), and raw SQL are invisible to it. Those paths require manually reading before-values, building Change objects, and calling bulk_log_activity.

How do I log activity for models on a separate database?

Pass using=router.db_for_write(Thing) to every log_activity and bulk_log_activity call, including inside the receiver. Without it, the audit row is written before the product row commits and survives its rollback.

How do I hide secret field values from the activity log diff?

Add secret fields to field_with_masked_contents so the change is recorded without the values. Use signal_exclusions for fields jobs touch every run, field_exclusions for bookkeeping fields, and field_name_overrides for user-facing names.