Skip to content

New Method Logger.setAsyncContext()

Compare
Choose a tag to compare
@jongpie jongpie released this 28 Sep 03:17
· 64 commits to main since this release
13f2faa

This release introduces a new method & fields to further help with monitoring & troubleshooting of async jobs, using the platform-provided async context interfaces:

  1. Database.BatchableContext
  2. System.FinalizerContext
  3. System.QueueableContext
  4. System.SchedulableContext

The new features in this release can be used either in place of, or in addition to, Nebula Logger's existing method, Logger.setParentTransactionId(), to help with identifying logs from related asynchronous transactions.

Core Unlocked Package Changes

New Method Logger.setAsyncContext()

  • Added new global method Logger.setAsyncContext(). There are 4 overloads - 1 for each of the platform-provided interfaces:
     void setAsyncContext(Database.BatchableContext batchableContext) {}
     void setAsyncContext(System.FinalizerContext finalizerContext) {}
     void setAsyncContext(System.QueueableContext queueableContext) {}
     void setAsyncContext(System.SchedulableContext schedulableContext) {}

New Fields on LogEntryEvent__e and Log__c

  • Added new fields on LogEntryEvent__e and Log__c that are set by using Logger.setAsyncContext()
    New Fields Description
    LogEntryEvent__e.AsyncContextType__c and Log__c.AsyncContextType__c The interface of the platform-provided context. Current values are Database.BatchableContext, System.FinalizerContext, System.QueueableContext, and System.SchedulableContext.
    LogEntryEvent__e.AsyncContextParentJobId__c and Log__c.AsyncContextParentJobId__c The ID of the parent job (Schema.AsyncApexJob) that initiated the async transaction. Used for Database.Batchable, System.FinalizerContext, and System.QueueableContext.
    LogEntryEvent__e.AsyncContextChildJobId__c and Log__c.AsyncContextChildJobId__c The ID of the child job (Schema.AsyncApexJob) that initiated the async transaction. Used for Database.Batchable.
    LogEntryEvent__e.AsyncContextTriggerId__c and Log__c.AsyncContextTriggerId__c The ID of the cron trigger (Schema.CronTrigger) that initiated the async transaction.
  • Updated FlexiPage LogRecordPage to conditionally show a new page section, "Async Context Details", which also conditionally shows the 4 new fields, shown in the screenshot below (in the red box)
    image
  • Updated several async classes (including LogBatchPurger and LogBatchPurgeScheduler) to leverage the new method Logger.setAsyncContext()

Internal Code Cleanup

  • Eliminated the helper method LoggerMockDataCreator.createBatchableContext() - the underlying mock batchable context class, as well as some new similar mocks for Finalizer, Queueable, and Schedulable`, are now public and can be instantiated directly
    • Having the extra static methods was adding a lot of unnecessary complication & redundant code to expose static methods for each constructor

Pipeline Changes

  • Upgraded sf cli (again) to try to resolve some packaging issues in the pipeline (again)
  • Updated build.yml to output sf version to help with troubleshooting any future pipeline issues

Installation Info

Core Unlocked Package - no namespace

Full Changelog: v4.11.5...v4.11.6