Audit logging
Audit logging lets administrators track the activity on a TypeDB server. It records authentication attempts, user and database management, transactions, queries, and changes to the cluster, each with the user and the client address it came from. Every record is one line of JSON, written to files, to the standard output, or to both.
|
Audit logging is available in TypeDB Enterprise only. TypeDB Community Edition does not have it. |
Enabling audit logging
Audit logging is disabled by default.
Enable it in the audit section of the configuration file, or on the command line:
typedb server --audit.enabled=true
With the default settings, the records are written to server/audit/audit.log in the distribution.
The server prints the settings in use when it starts:
Audit logging: enabled (exit-on-fail: true, sync: false)
Files: /opt/typedb/server/audit
In a cluster, each replica records the operations it serves into its own log. The logs are not replicated: enable audit logging on every replica, and collect the records from all of them.
What is recorded
Every record names its event in two fields, category and event.
category |
event |
Recorded when |
|---|---|---|
|
|
|
|
|
A user is created, deleted, or changed (for example, given a new password). |
|
|
A database is created, deleted, imported, or exported, or its schema is retrieved in full ( |
|
|
A transaction is opened, committed, rolled back, or closed. |
|
|
A query is run, or analyzed without being run ( |
|
|
The server starts or stops, or a replica is registered into or deregistered from the cluster with the admin tool. |
|
|
A read-only lookup of users, databases, or servers. Recorded only with |
Passwords and access tokens are never recorded.
Query text and error messages can contain sensitive data: set audit.query-text to false to leave both out.
Started and ended records
An operation is recorded twice, when it starts and when it ends, in two records that share an operationId:
{"timestamp":"2026-11-24T18:12:59.320667Z","deploymentId":"my-cluster","replicaId":1,"category":"query","event":"schema","stage":"started","endpoint":"grpc","clientAddress":"10.0.1.15:39430","user":"admin","database":"shop","transactionId":"011a2609-58e3-472b-bf10-ae827e3dec52","operationId":"1ebcb887-d989-4bb6-93d4-2ff82cc1865f","query":"define entity person, owns name; attribute name, value string;"}
{"timestamp":"2026-11-24T18:12:59.321393Z","deploymentId":"my-cluster","replicaId":1,"category":"query","event":"schema","stage":"ended","outcome":"success","endpoint":"grpc","clientAddress":"10.0.1.15:39430","user":"admin","database":"shop","transactionId":"011a2609-58e3-472b-bf10-ae827e3dec52","operationId":"1ebcb887-d989-4bb6-93d4-2ff82cc1865f","durationMicros":960}
The records read as follows:
-
An operation with a
startedrecord ran, or was about to run. -
An operation with only an
endedrecord did not run: for example, a query that could not be parsed, or a request with a rejected token. -
A
startedrecord without anendedone means that the server stopped abruptly while the operation was running, or that theendedrecord could not be written. -
The outcome is the outcome on the server. A write query whose transaction is closed while its answers are being sent is a
success: the write was applied, although the client receives an error instead of the answers. -
A committed transaction has a
commitrecord and nocloserecord. A transaction that ends in any other way has acloserecord. -
A one-shot query over HTTP (
/query) has only itsqueryrecords: notransactionId, and notransactionrecords, even when it commits.
Record format
Each record is a JSON object on a line of its own. The fields always come in the order below, and a field with no value is left out.
| Field | Present in | Meaning |
|---|---|---|
|
All records |
UTC time, with microseconds. |
|
All records |
The name of the cluster ( |
|
All records |
The id of the replica that served the operation ( |
|
All records |
See What is recorded. |
|
Operations |
|
|
|
|
|
|
Why a transaction was closed without the client closing it: |
|
Operations |
|
|
|
The address the connection came from: behind a proxy or a load balancer, the proxy’s address. |
|
Operations of a known user |
The authenticated user. For a |
|
|
The user that is created, deleted, changed, or looked up. |
|
|
The replica’s |
|
Where it applies |
The database the operation is on. |
|
|
Shared by all the records of one transaction. |
|
Operations |
Shared by the two records of one operation. |
|
|
The text of the query, in the first record of the operation. |
|
|
How long the operation took, in microseconds. |
|
|
The |
Examples
A failed login, and an HTTP request with a rejected token:
{"timestamp":"2026-12-01T13:13:32.283659Z","deploymentId":"my-cluster","replicaId":1,"category":"authentication","event":"login","stage":"started","endpoint":"grpc","clientAddress":"10.0.1.15:54338","user":"ghost","operationId":"5e39aa4e-962a-444a-b186-8a835c13596a"}
{"timestamp":"2026-12-01T13:13:32.287176Z","deploymentId":"my-cluster","replicaId":1,"category":"authentication","event":"login","stage":"ended","outcome":"failure","endpoint":"grpc","clientAddress":"10.0.1.15:54338","user":"ghost","operationId":"5e39aa4e-962a-444a-b186-8a835c13596a","durationMicros":3517,"error":{"code":"AUT1","message":"[AUT1] Invalid credential supplied.\n[SRV15] Error when authenticating."}}
{"timestamp":"2026-12-01T13:13:38.526968Z","deploymentId":"my-cluster","replicaId":1,"category":"authentication","event":"token","stage":"ended","outcome":"failure","endpoint":"http","clientAddress":"10.0.1.15:54138","operationId":"4e41dc36-5f01-4cec-8d4d-fb7afcd95572","durationMicros":94,"error":{"code":"AUT3","message":"[AUT3] Invalid token supplied.\n[HSR9] Authentication error."}}
A transaction closed because the connection of its client ended:
{"timestamp":"2026-12-01T13:18:09.765645Z","deploymentId":"my-cluster","replicaId":1,"category":"transaction","event":"close","stage":"started","reason":"connectionEnd","endpoint":"grpc","clientAddress":"10.0.1.15:60480","user":"admin","database":"shop","transactionId":"c6f19245-e9b6-42c7-8ffb-42cc57d3a356","operationId":"5cb95a49-f9df-472a-970d-16c83b9cd12f"}
{"timestamp":"2026-12-01T13:18:09.765726Z","deploymentId":"my-cluster","replicaId":1,"category":"transaction","event":"close","stage":"ended","outcome":"success","reason":"connectionEnd","endpoint":"grpc","clientAddress":"10.0.1.15:60480","user":"admin","database":"shop","transactionId":"c6f19245-e9b6-42c7-8ffb-42cc57d3a356","operationId":"5cb95a49-f9df-472a-970d-16c83b9cd12f","durationMicros":81}
A replica being registered with the admin tool, and the server stopping:
{"timestamp":"2026-12-01T13:14:02.118204Z","deploymentId":"my-cluster","replicaId":1,"category":"server","event":"register","stage":"started","endpoint":"admin","user":"[admin]","targetReplica":{"id":2,"address":"10.0.0.2:1730"},"operationId":"0d412ec4-0c0f-4a33-8505-b51db433602f"}
{"timestamp":"2026-12-01T13:14:02.341977Z","deploymentId":"my-cluster","replicaId":1,"category":"server","event":"register","stage":"ended","outcome":"success","endpoint":"admin","user":"[admin]","targetReplica":{"id":2,"address":"10.0.0.2:1730"},"operationId":"0d412ec4-0c0f-4a33-8505-b51db433602f","durationMicros":223773}
{"timestamp":"2026-12-01T13:14:16.255055Z","deploymentId":"my-cluster","replicaId":1,"category":"server","event":"stop","outcome":"success"}
Configuration
All the settings are in the audit section of the configuration file.
Every setting except audit.events can also be given on the command line, for example --audit.sync=true.
Audit logging |
|
|
Enable audit logging. Default value: |
|
Shut the server down when an audit record cannot be written. With |
|
Write the record of an operation’s start to every output, and sync it to disk in the file output, before the operation runs. Default value: |
|
Include the text of queries and the messages of errors in the records. With |
|
Record read-only lookups of users, databases, and servers (the |
|
The events to record in a category, as a list. Config file only. Default value: all events of every category. |
Audit logging output |
|
|
Write the records to files in the audit directory. Default value: |
|
Path to the audit directory. A relative path in the config file is resolved against the server executable, and on the command line against the working directory. Must be outside |
|
Size at which the current file is archived and a new one is started. Default value: |
|
Period at the end of which the current file is archived: |
|
Total size of the archived files above which the oldest ones are deleted. Must be at least |
|
Age in days after which archived files are deleted. Leave the value empty in the config file for no limit. Default value: |
|
Write the records to the standard output of the server. Default value: |
Sizes are written as described in the size format note. At least one output must be enabled while audit logging is enabled.
Selecting events
audit.events lists the events to record in each category:
-
A category that is left out records all of its events.
-
An empty list (
[]) records none of them. -
Event names are written in kebab-case here, and in camelCase in the records:
type-schemain the configuration istypeSchemain a record. -
Queries of the
unknowntype are recorded while any ofread,write, orschemais.
For example, to record only logins, user management, the queries that change data or schema, and the server events:
audit:
enabled: true
events:
authentication: [login, token]
user: [create, delete, update]
database: []
transaction: []
query: [write, schema]
server: [start, stop, register, deregister]
Audit log files
With the file output, the audit directory holds:
| File | Contents |
|---|---|
|
The current file. Records are appended to it. |
|
Archived files, named after the UTC time of their last record, for example |
|
A lock that keeps two servers from writing to the same directory. Give every server its own audit directory. |
The current file is archived by renaming it: before a record would take it over file-size-limit, and at the first record after the archive-grouping period ends (weeks start on Monday).
Archived files are not compressed.
They are deleted, oldest first, according to the two archive limits, which do not count the current file. The newest archived file is always kept.
For production use, put the audit directory on a volume of its own, so that a full data disk and a full audit disk are separate events.
Collecting the records
The records are meant to be shipped to a log store as they are written:
-
A log shipper that follows
audit.logloses nothing when the file is archived, as archiving is a rename. -
In containers, enable
audit.output.stdoutand let the container runtime collect the records. They are mixed with the other output of the server: every audit record is a line that starts with{"timestamp":. -
A crash can leave an incomplete record in a file: skip the lines that are not valid JSON.
Monitoring
The diagnostics monitoring endpoint exposes the state of the audit log while audit logging is enabled.
In the JSON format, the same values are in extensions.audit, named in camelCase without the prefix, for example recordsLostTotal.
| Metric | Type | Meaning |
|---|---|---|
|
counter |
Number of audit records produced. |
|
counter |
Number of audit records that could not be written to an output. |
|
counter |
Number of failed attempts to write to an output. |
|
counter |
Number of operations that went ahead without waiting any longer for the record of their start. |
|
gauge |
Size of the files in the audit directory: the current file and the archived ones. |
|
gauge |
How long the write in progress has been taking, or |