adding-activity-logging
БесплатноБез исполняемых скриптовНе проверенAdds or changes activity logging (the audit trail) for a Django model in PostHog. Use when a model's writes must show in the Activity side panel or the…
от PostHog★ 41 278 звёзд на GitHubОб этом скилле
Adding activity logging
Read docs/internal/activity-logging.md first. It carries the pipeline, the file locations, and the reasons. This skill carries the workflow and the gates.
Reference implementation: products/feature_flags/backend/activity_logging.py with its apps.py.
Separate-database reference: products/stamphog/backend/activity_logging.py.
Step 1 - Find every write path before you touch the model
The mixin hooks save() and delete().
It does not see QuerySet.update(), bulk_create(), bulk_update(), or raw SQL.
A receiver that logs only the API path gives an audit trail that says nobody changed a row a webhook changed.
rg -n "Thing\.objects|Thing\.all_teams" products/<name>/ --type py | rg -v "tests/"
rg -n "\.update\(|bulk_create\(|bulk_update\(" products/<name>/backend --type py
Write the list down: which paths call save() (the mixin covers them) and which do bulk writes (you log those by hand in step 5).
Include tasks, Temporal activities, webhook handlers, and management commands.
Step 2 - Model and scope
- Add
ModelActivityMixinfirst in the bases:class Thing(ModelActivityMixin, TeamScopedRootMixin, ...). - Set
activity_logging_on_delete = Trueonly when a hard delete must show in the log. - Add the class name to
ActivityScopeinposthog/models/activity_logging/activity_log.py. - Add the same string to the
ActivityScopeenum infrontend/src/types.ts. - Run
hogli build:openapi(needs the dev stack) because the APIscopefilter enum is generated from the Literal.
No migration is needed. The mixin adds no field.
Step 3 - Receiver module
Create products/<name>/backend/activity_logging.py.
One @mutable_receiver(model_activity_signal, sender=Thing) per model.
The receiver calls changes_between and log_activity; nothing else.
Keep the module import-light.
It must not import a viewset, a serializer, or a query runner.
ready() imports it at django.setup() in every process.
For a model without a .team foreign key (ProductTeamModel), read organization_id from Team on the main database inside the receiver.
Step 4 - Wire it
- In
products/<name>/backend/apps.pyready():from products.<name>.backend import activity_logging # noqa: F401, PLC0415, with a one-line comment that says why it must connect in every process. - Add
model_activity:products.<name>.backend.activity_logging.<handler>toposthog/test/repo_invariants/setup_receivers_baseline.txt.
A receiver that is not imported in ready() connects only where something else imports the module.
That is the silent failure this convention exists to prevent.
Each product owns this wiring in its apps.py; core keeps no list of product receivers, following #93107.
Step 5 - Bulk writes
For each bulk write from step 1:
- Read the before-values from the writer database before the update.
- Run the update.
- Build one
Changeper field that actually changed, for rows whose value changed. - Call
bulk_log_activity(orlog_activityfor one row) withuser=Nonewhen no request user exists, and aTriggerthat names the job and its id.
Do not wrap a request path in mute_selected_signals().
The flag is process-wide.
Step 6 - Separate-database products only
When the model is routed in products/db_routing.yaml:
- Pass
using=router.db_for_write(Thing)to everylog_activityandbulk_log_activitycall in the product, including the receiver. Without it, the audit row is written before the product row commits and survives its rollback. - The mixin already pins its before-update read to the writer and reads by primary key without a team filter.
Step 7 - Tune the diff
- Fields a job touches on every run go in
signal_exclusions(no row is logged when only they change). - Bookkeeping fields go in
field_exclusions(dropped from the diff). - Secrets go in
field_with_masked_contents(the change is recorded, the values are not). - User-facing names go in
field_name_overrides.
Put them in a data only module next to the model, so the team that owns the model owns its tuning:
# products/<name>/backend/activity_log_config.py
FIELD_EXCLUSIONS = {"Thing": ["bookkeeping_field"]}
Product configs must use exactly products/<name>/backend/activity_log_config.py; other names and locations will not load by convention.
For a core model, put the config beside it so it inherits the model's owners. If the ownership rule lists explicit files, add the config to its match list.
Installed product apps discover their config automatically.
For a core model, add an import and a MODULES entry in posthog/models/activity_logging/activity_log_config_registry.py.
The registry is intentionally unowned so the model team can register its config without a review from the activity-log owners.
A config module holds no imports: activity_log.py merges it a
Установить adding-activity-logging в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл adding-activity-logging?
Adds or changes activity logging (the audit trail) for a Django model in PostHog. Use when a model's writes must show in the Activity side panel or the advanced activity logs, when adding ModelActivityMixin, an ActivityScope, a model_activity_signal receiver, an activity describer, or field exclusions, when auditing which write paths of a model are logged, or when a change is missing from the activity log. Covers the receiver-module convention, writes the signal cannot see (QuerySet.update, bulk_create), the actor outside requests, and product models on a separate database. Trigger terms - activity log, audit log, audit trail, ModelActivityMixin, log_activity, changes_between, activity describer, who changed this.
Как установить скилл adding-activity-logging?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл adding-activity-logging запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic