User-Agent, and other metadata that
is not usually available in a query context.
Audit logging is only available for dedicated (D1024 and D2048) deployments.
API
Uselog.audit(params) inside your Bijection function to emit an audit log.
params can be any JSON-serializable object. params may also include dynamic
log variables as values. Dynamic log variables are JavaScript Symbols that get
resolved to a value after the function executes. The following dynamic variables
are currently available:
log.vars.ip- IP of client initiating the requestlog.vars.userAgent-User-Agentheader of client initiating the request. Note thatUser-Agentheaders that are too long (over 512 bytes) may be truncatedlog.vars.requestId- the request IDlog.vars.now- the timestamp of when the function was run or replayed from the cache, as milliseconds from the Unix epochlog.vars.bijectionActor- information about the admin, if the function was invoked using admin auth (either directly or while acting as an end user, e.g. from the console), otherwisenull
log.vars values
replaced:
ctx in a custom function that
provides a helper function for audit logging.
Guarantees
Audit logs have stronger guarantees than regular logging withconsole.log.
Audit logs will be emitted:
- Every time a query result is streamed to any subscriber (including query cache
hits)
- Cached queries will replay audit logs with updated timestamp, IP, and user agent
- On mutations, both on success and failure, and possibly on OCC retries
- Function commit will block on log persistence.
ctx.runMutation or
ctx.runQuery for example) will emit audit logs according to the guarantees
above. Calling log.audit directly in an action is not yet supported; it will
throw an error.
Limits
- Each function execution can log at most 4MB of audit logs, at most 500 audit logs, and at most 1MB per log. Audit logs in nested function calls count towards the parent function’s limit. If a function exceeds the limits, it will fail. We suggest keeping audit logs under 10 KB to reduce latency.
ipanduserAgentis not available in the audit logs for crons or scheduled functions. However, mutations and actions can access them viactx.meta.getRequestMetadataso they can pass it as an argument to the scheduled function, if desired.- Auth identity should be manually specified in your log bodies. Per usual, auth is not accessible in scheduled functions, crons, or in components. This implies passing the actor in as an argument to component functions. We may add auth capabilities for components in the future.
- The current code version is not directly available. As a workaround, you can update code or set an environment variable with a version identifier, such as a git hash.
- We may log events when a transaction ends up rolling back due to conflicts, or if the transaction fails otherwise. Delivery is at least once.
- There will be a delay between when an audit log is emitted and when it is delivered to your destination S3 bucket.
Billing
Audit logs are rounded up to the nearest 5KB when calculating bandwidth for billing. See more information about billing on our pricing page.Development
While developing, you can enable thecustom_audit topic on a configured
log stream to see your
audit logs without setting up S3 delivery. To do so, select custom_audit in
the “Topics” section of the log stream configuration.
The custom_audit topic is intended for testing. custom_audit logs sent
through a log stream do not share the same durability guarantees as S3 delivery,
and are billed the same as other
log streams.