Journal Signals and Receivers
Signals for the Smarter Journal.
- smarter.lib.journal.signals.journal_entries_listed = <django.dispatch.dispatcher.Signal object>
Signal sent when journal entries are listed through the journal api.
Arguments:
user(User): The user who listed them.count(int): The number of entries that match the request’s search.
Example:
journal_entries_listed.send(sender=self.__class__, user=request.user, count=count)
- smarter.lib.journal.signals.journal_entry_accessed = <django.dispatch.dispatcher.Signal object>
Signal sent when a journal entry is read through the journal api.
Journal entries hold user content, e.g. prompts, manifests and LLM responses, so every read is signaled.
Arguments:
journal(SAMJournal): The journal entry that was read.user(User): The user who read it.
Example:
journal_entry_accessed.send(sender=self.__class__, journal=journal, user=request.user)
- smarter.lib.journal.signals.journal_entry_created = <django.dispatch.dispatcher.Signal object>
Signal sent when a journal entry is saved.
It is sent by the Celery worker that saves the entry, or by the journaled response itself, when the entry could not be queued.
Arguments:
journal(SAMJournal): The new journal entry.
Example:
journal_entry_created.send(sender=SAMJournal, journal=journal)
- smarter.lib.journal.signals.journal_entry_failed = <django.dispatch.dispatcher.Signal object>
Signal sent when a journal entry could not be saved.
It is sent by the journaled response when the entry could neither be queued nor saved, and the response is returned without a key, or by the Celery task, when its last try fails.
Arguments:
user(int): The id of the user who made the request, or None for an anonymous request.thing(str): The journal’s thing, e.g. Guardrail.command(str): The journal’s command, e.g. apply.status(int): The response’s http status.request(HttpRequest): The request, or None from the task.response(dict): The response’s JSON, or None if it could not be serialized, or from the task.error(Exception): The error that prevented the entry from being saved.
Example:
journal_entry_failed.send( sender=self.__class__, user=user, thing=thing, command=command, status=status, request=request, response=response, error=e, )
Django signal receivers for the Smarter Journal.
They only log. A journal entry’s request and response documents hold user content, e.g. prompts, manifests and LLM responses, so the receivers log an entry’s key, thing, command and status code, never its documents.
- smarter.lib.journal.receivers.error_logger = <WaffleSwitchedLoggerWrapper logger=smarter.lib.journal.receivers>
Logs whatever the waffle switches, for a journal entry that could not be saved.
- smarter.lib.journal.receivers.journal_entries_listed_receiver(sender, user, count, **kwargs)[source]
Signal receiver for journal_entries_listed signal: log the listing at DEBUG.
- Parameters:
sender – The class that sent the signal.
user – The user who listed the entries.
count – The number of entries listed.
kwargs – The rest of the signal’s arguments.
- smarter.lib.journal.receivers.journal_entry_accessed_receiver(sender, journal, user, **kwargs)[source]
Signal receiver for journal_entry_accessed signal: log the access at DEBUG.
- Parameters:
sender – The class that sent the signal.
journal (
SAMJournal) – The entry that was read.user – The user who read it.
kwargs – The rest of the signal’s arguments.
- smarter.lib.journal.receivers.journal_entry_created_receiver(sender, journal, **kwargs)[source]
Signal receiver for journal_entry_created signal: log the entry at DEBUG.
- Parameters:
sender – The class that sent the signal.
journal (
SAMJournal) – The new entry.kwargs – The rest of the signal’s arguments.
- smarter.lib.journal.receivers.journal_entry_failed_receiver(sender, user, thing, command, status, request, response, error, **kwargs)[source]
Signal receiver for journal_entry_failed signal.
It logs at error level, whatever the waffle switches, because a missing journal entry is a gap in an audit record. Operators monitor the logs for
could not create journal entry. The request and response documents are not logged, because they hold user content.- Parameters:
sender – The class that sent the signal.
user – The user the entry was for, or None.
thing – The kind of resource.
command – The command that was journaled.
status – The response’s http status code.
request – The serialized request. Not logged.
response – The response document. Not logged.
error – The exception that stopped the entry from being created.
kwargs – Any other signal arguments.
- smarter.lib.journal.receivers.samjournal_post_delete(sender, instance, **kwargs)[source]
Signal receiver for deleted of SAMJournal model: log the entry’s key at DEBUG.
- Parameters:
sender – The SAMJournal model.
instance (
SAMJournal) – The deleted entry.kwargs – The rest of the signal’s arguments.
- smarter.lib.journal.receivers.samjournal_post_save(sender, instance, created, **kwargs)[source]
Signal receiver for created/saved of SAMJournal model: log the entry at DEBUG.
- Parameters:
sender – The SAMJournal model.
instance (
SAMJournal) – The saved entry.created – True if the entry was created.
kwargs – The rest of the signal’s arguments.