Export Functions logs

Functions publish log output to an internal PubNub channel. To keep that output after the console session ends, use Events & Actions to forward it to a Webhook endpoint or an S3 bucket.

Before you start​

Before starting, confirm you have:

  • A deployed Function. If you do not have one, see Create a Function.
  • The log channel name for your Function revision. It follows the pattern output-rev-{{functionRevisionId}}-key-{{keysetId}}, for example output-rev-00000000-0000-4000-8000-000000000000-key-123456, where the revision ID is a UUID and the keyset ID is a number. Find the exact name in the Console output.

A Function replica publishes up to 250 console log lines over its lifetime, not per execution, and output stops silently once a replica reaches that budget.

Configure the event listener​

  1. In the Admin Portal, open Events & Actions and configure an event listener on the log channel.

  2. Enter the output-rev-* channel name from the Console output in the Condition value field.

    Event listener configured on the Functions log channel

Create the export action​

  1. Create a Webhook or S3 action.
  2. Attach the event listener you created in the previous section to the action.
  3. To send multiple log events in one request, enable batching on the action.

Events & Actions now forwards log output to your destination each time the Function publishes to the log channel.

Sort the exported lines​

Every line from one invocation of your Function carries the same executionId, and each line carries a sequenceId. To read one invocation's lines in the order your Function logged them:

  1. Group the lines by executionId.
  2. Sort each group by sequenceId.
  3. Keep lines without an executionId in a group of their own. The runtime publishes some lines, such as those logged outside an invocation, without one.

Don't order lines by their timetoken. The timetoken records when PubNub received a line, and sequenceId records the order your Function logged it. For each field, see Function log lines in the Events & Actions payloads reference.

Live delivery is at most once, so a line can be missed. See Data transport and delivery. A gap in sequenceId is normal and doesn't mean a line was lost, because the counter also advances for calls that are filtered out before publishing.

If you need an order of your own, log a marker or an identifier of your own and sort by that.

Was this page useful?

Last updated on