Context, events and markers
Tie work across many requests into one trail with pb_context, record business events with pb_event, and mark deploys with pb_mark.
On this page
Three functions add meaning to what Paul Bunyan records: a context ties requests together, an event records something the business cares about, and a marker splits time into before and after.
pb_context: one trail across many requests
An order is more than one request: the checkout, the thank-you page, the emails and the background jobs that follow. Give them a shared context and they can be read as one trail.
pb_context( 'order:' . $order_id );Messages with the same context are linked on the Messages screen; click a context to see its whole trail, or filter Messages by context. With Professional, WooCommerce orders get a context automatically, and it follows the work into Action Scheduler jobs and order emails sent later: an order trail.
Keep contexts short and free of personal data: an id, not a name.
pb_event: speed read against business numbers
pb_event( 'tickets issued', array( 'tickets' => 250 ) );Events are recorded in either edition. With Professional, the Events screen shows them with the speed of the request that produced them, so you can see whether, for example, checkout is slower for larger orders, and WooCommerce orders are recorded for you.
pb_mark: before and after
pb_mark( 'Version 7.2 deployed' );A marker is a point in time the Compare screen can measure around. Call it from a deploy script or an upgrade routine. Plugin and theme updates are marked automatically.
pb_bug: things that should never happen
pb_bug( 'checkout', 'Order total is negative', array( 'order' => $order_id ) );Logged as an error whatever the minimum level is set to, with "BUG:" in front of the message so it stands out.
