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

authentication

login, token

login: a client signs in with a username and a password.
token: a request does not pass the check of its access token, because the token is missing or invalid.

user

create, delete, update

A user is created, deleted, or changed (for example, given a new password).

database

create, delete, schema, typeSchema, import, export

A database is created, deleted, imported, or exported, or its schema is retrieved in full (schema) or as type definitions only (typeSchema).

transaction

open, commit, rollback, close

A transaction is opened, committed, rolled back, or closed.

query

read, write, schema, analyze, unknown

A query is run, or analyzed without being run (analyze).
unknown: the query ended before its type was known, for example because it could not be parsed.

server

start, stop, register, deregister

The server starts or stops, or a replica is registered into or deregistered from the cluster with the admin tool.

inspection

usersAll, usersGet, usersContains, databasesAll, databasesGet, databasesContains, serversAll, serversGet, serverVersion

A read-only lookup of users, databases, or servers. Recorded only with audit.inspections: true.

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 started record ran, or was about to run.

  • An operation with only an ended record did not run: for example, a query that could not be parsed, or a request with a rejected token.

  • A started record without an ended one means that the server stopped abruptly while the operation was running, or that the ended record 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 commit record and no close record. A transaction that ends in any other way has a close record.

  • A one-shot query over HTTP (/query) has only its query records: no transactionId, and no transaction records, 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

timestamp

All records

UTC time, with microseconds.

deploymentId

All records

The name of the cluster (diagnostics.deployment-id).

replicaId

All records

The id of the replica that served the operation (server.clustering.id).

category, event

All records

See What is recorded.

stage

Operations

started or ended. The server events start and stop are single records without it.

outcome

ended records, server start and stop

success, failure, or abandoned: the server does not know the outcome, because the client went away or the server was stopping.

reason

transaction close

Why a transaction was closed without the client closing it: connectionEnd (the client’s connection ended while the transaction was open), requestFailure, timeout, shutdown, or serverStateChange.

endpoint

Operations

grpc, http, or admin (the admin tool).

clientAddress

grpc and http operations

The address the connection came from: behind a proxy or a load balancer, the proxy’s address.

user

Operations of a known user

The authenticated user. For a login, the name the client signs in with. For the admin tool, [admin].

targetUser

user events, usersGet, usersContains

The user that is created, deleted, changed, or looked up.

targetReplica

register, deregister

The replica’s id, and its address when it is being registered.

database

Where it applies

The database the operation is on.

transactionId

transaction and query events in a transaction

Shared by all the records of one transaction.

operationId

Operations

Shared by the two records of one operation.

query

query events

The text of the query, in the first record of the operation.

durationMicros

ended records

How long the operation took, in microseconds.

error

ended records with "outcome":"failure"

The code of the error and its message: the error followed by the errors it caused, one per line.
A request that is refused before it reaches the database, such as a login from an incompatible driver version, has no code.

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

audit.enabled

Enable audit logging. Default value: false.

audit.exit-on-fail

Shut the server down when an audit record cannot be written. With false, the server carries on: the records are lost, counted, and warned about in the server log. Default value: true.

audit.sync

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: false.

audit.query-text

Include the text of queries and the messages of errors in the records. With false, both are left out and error codes stay. Default value: true.

audit.inspections

Record read-only lookups of users, databases, and servers (the inspection category). Default value: false.

audit.events.<category>

The events to record in a category, as a list. Config file only. Default value: all events of every category.

Audit logging output

audit.output.file.enabled

Write the records to files in the audit directory. Default value: true.

audit.output.file.directory

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 storage.data-directory. Default value: audit, which is server/audit in the distribution.

audit.output.file.file-size-limit

Size at which the current file is archived and a new one is started. Default value: 50mb.

audit.output.file.archive-grouping

Period at the end of which the current file is archived: day, week, month, or year, in UTC. Default value: month.

audit.output.file.archives-size-limit

Total size of the archived files above which the oldest ones are deleted. Must be at least file-size-limit. Leave the value empty in the config file for no limit. Default value: 1gb.

audit.output.file.archives-age-limit-days

Age in days after which archived files are deleted. Leave the value empty in the config file for no limit. Default value: 365.

audit.output.stdout.enabled

Write the records to the standard output of the server. Default value: false.

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-schema in the configuration is typeSchema in a record.

  • Queries of the unknown type are recorded while any of read, write, or schema is.

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

audit.log

The current file. Records are appended to it.

audit-<time>.log

Archived files, named after the UTC time of their last record, for example audit-20261201T131502.908Z.log. Sorted by name, they are in the order they were written.

audit.lock

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.log loses nothing when the file is archived, as archiving is a rename.

  • In containers, enable audit.output.stdout and 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

audit_records_total

counter

Number of audit records produced.

audit_records_lost_total

counter

Number of audit records that could not be written to an output.

audit_output_failures_total

counter

Number of failed attempts to write to an output.

audit_late_starts_total

counter

Number of operations that went ahead without waiting any longer for the record of their start.

audit_directory_bytes

gauge

Size of the files in the audit directory: the current file and the archived ones.

audit_current_write_seconds

gauge

How long the write in progress has been taking, or 0 when the log is idle.