Overview
Query audit logs with the SigNoz Query Range API. Use it to investigate a change, such as who deleted a dashboard, or to export audit logs on a schedule to a security tool or long-term storage.
Prerequisites
- SigNoz Cloud, or Self-Hosted SigNoz with an active license.
- An API key that can read audit logs. Keys of a service account with the signoz-admin role can read audit logs. For scripts and integrations, use a read-only key instead. See Create a read-only role for audit logs.
jq, to format the responses in the examples.
Create a read-only role for audit logs
An admin key can also change your workspace. For a script or a security tool that only reads audit logs, create a custom role that grants only read on audit logs, and use a key of a service account that has that role.
The role editor in Settings > Roles does not offer audit logs yet, so create the role with the Roles API.
-
Create the role with an admin API key:
curl -X POST 'https://<your-signoz-url>/api/v1/roles' \ -H 'SIGNOZ-API-KEY: <your-admin-api-key>' \ -H 'Content-Type: application/json' \ -d '{ "name": "audit-log-reader", "description": "Read audit logs", "transactionGroups": [ { "relation": "read", "objectGroup": { "resource": { "type": "telemetryresource", "kind": "audit-logs" }, "selectors": ["builder_query/*"] } } ] }'The response status is
201 Created. -
Create a service account, assign it the audit-log-reader role, and generate an API key. See Service Accounts.
Verify these values:
<your-signoz-url>: The URL of your SigNoz workspace, for exampleacme.us.signoz.cloud.<your-admin-api-key>: An API key of a service account with the signoz-admin role.
Keys of this service account can query audit logs. A query on other logs returns 403, and so does a change such as creating a dashboard.
Send a query
Send a builder_query on the logs signal with source set to audit to POST /api/v5/query_range. This request returns the 20 most recent audit logs from the last 24 hours:
NOW_MS=$(( $(date +%s) * 1000 ))
START_MS=$(( NOW_MS - 24 * 3600 * 1000 ))
curl -s -X POST 'https://<your-signoz-url>/api/v5/query_range' \
-H 'SIGNOZ-API-KEY: <your-api-key>' \
-H 'Content-Type: application/json' \
-d @- <<EOF | jq .
{
"schemaVersion": "v1",
"start": $START_MS,
"end": $NOW_MS,
"requestType": "raw",
"compositeQuery": {
"queries": [
{
"type": "builder_query",
"spec": {
"name": "A",
"signal": "logs",
"source": "audit",
"order": [{ "key": { "name": "timestamp" }, "direction": "desc" }],
"limit": 20
}
}
]
}
}
EOFVerify these values:
<your-signoz-url>: The URL of your SigNoz workspace.<your-api-key>: An API key that can read audit logs.
The fields that matter for audit logs:
"signal": "logs"and"source": "audit"select audit logs. Withoutsource, the query reads your application logs.startandendare Unix timestamps in milliseconds.ordersorts by time. Always set it. Withoutorder, the results are in no particular order and can leave out the most recent audit logs.filter.expression, which the examples below add, narrows the results. See Fields for what you can filter on.
Each row in data.data.results[0].rows is one audit log. A trimmed row:
{
"data": {
"timestamp": 1795514484872756000,
"event_name": "signoz.audit.delete",
"body": {
"message": "jane@example.com (019e7346-af3d-7c9a-984a-755b731ec346) deleted dashboard (01a20d00-c867-7bb0-9419-cd3d5109cf7f)"
},
"attributes": {
"client.address": "203.0.113.24",
"http.route": "/api/v2/dashboards/{id}",
"signoz.audit.action_category": "configuration_changes",
"signoz.audit.outcome": "success",
"signoz.audit.verb": "delete",
"signoz.principal.email": "jane@example.com",
"signoz.principal.id": "019e7346-af3d-7c9a-984a-755b731ec346",
"signoz.principal.type": "user",
"user_agent.original": "Mozilla/5.0 ..."
},
"resource": {
"attributes": {
"signoz.resource.id": "01a20d00-c867-7bb0-9419-cd3d5109cf7f",
"signoz.resource.kind": "dashboard"
}
}
}
}Examples
Each example below replaces the spec in the request above. Set requestType as listed.
Find every change to one dashboard
Lists the create, update, and delete operations on one dashboard, newest first. Request type: raw.
{
"name": "A",
"signal": "logs",
"source": "audit",
"filter": {
"expression": "signoz.resource.kind = 'dashboard' AND signoz.resource.id = '<dashboard-id>'"
},
"order": [{ "key": { "name": "timestamp" }, "direction": "desc" }],
"limit": 100
}Verify these values:
<dashboard-id>: The ID of the dashboard. It is the last part of the dashboard's URL in SigNoz,/dashboard/<dashboard-id>.
To look up another kind of resource, change signoz.resource.kind. For the list of kinds, see Resource kinds.
Find what a user or service account changed
Request type: raw.
{
"name": "A",
"signal": "logs",
"source": "audit",
"filter": { "expression": "signoz.principal.email = '<email>'" },
"order": [{ "key": { "name": "timestamp" }, "direction": "desc" }],
"limit": 100
}Verify these values:
<email>: The email of the user, or of the service account. A service account's email is<service-account-name>@signozserviceaccount.com.
Find changes to roles, users, and keys
Changes to who can do what, such as role assignments and new API keys, have the action category access_control. Request type: raw.
{
"name": "A",
"signal": "logs",
"source": "audit",
"filter": { "expression": "signoz.audit.action_category = 'access_control'" },
"order": [{ "key": { "name": "timestamp" }, "direction": "desc" }],
"limit": 100
}Count failed attempts by resource kind
A failed attempt is a change that SigNoz rejected, for example because the caller lacked permission or sent an invalid request. Request type: scalar.
{
"name": "A",
"signal": "logs",
"source": "audit",
"aggregations": [{ "expression": "count()" }],
"filter": { "expression": "signoz.audit.outcome = 'failure'" },
"groupBy": [{ "name": "signoz.resource.kind" }]
}The result has one row per resource kind, with the count in the __result_0 column. To list the failed attempts instead, use raw and drop aggregations and groupBy.
Count changes per hour by operation
Request type: time_series.
{
"name": "A",
"signal": "logs",
"source": "audit",
"stepInterval": 3600,
"aggregations": [{ "expression": "count()" }],
"groupBy": [{ "name": "signoz.audit.verb" }]
}The result has one series per operation (create, update, delete, attach, detach), with one point per hour.
Export audit logs on a schedule
To copy audit logs to a security tool or to storage that keeps them longer than 180 days, run the request in Send a query on a schedule with a read-only key:
-
Set
startto theendof the previous run. An audit log at the boundary between two runs can appear in both, so drop duplicates by the row'sid. -
Order by
timestampand thenid, so that the order is stable between requests:"order": [ { "key": { "name": "timestamp" }, "direction": "asc" }, { "key": { "name": "id" }, "direction": "asc" } ] -
If a run returns
limitrows, there can be more. Send the same request again withoffsetset to the number of rows received so far, until a request returns fewer rows thanlimit.
Troubleshooting
403 not authorized to perform audit-logs:read
The key's service account does not have a role that can read audit logs. Assign it the signoz-admin role or the audit-log-reader role. If the role used to work, check that nobody saved it from the role editor, which removes the audit logs grant.
401 unauthenticated
The API key is missing, expired, or revoked. Create a new key on the service account's Keys tab.
A change is missing
- Check that the change is one that SigNoz records. Reads, sign-ins, and some resources are not recorded. See What is not recorded.
- Check that
startandendcover the time of the change, in milliseconds. - Check that the query sets
order. Without it, the results can leave out the most recent audit logs.
One change appears twice
When two resources are linked, such as a role and a service account, SigNoz records the attach or detach once from each side. Filter on signoz.resource.kind to keep one side.
Next steps
- Audit Logs Reference: Look up the fields you can filter and group by.
- Service Accounts: Create service accounts and API keys.
- Search Logs: Return only some fields, and page through results.
Get Help
If you need help with the steps in this topic, please reach out to us on SigNoz Community Slack. If you are a SigNoz Cloud user, please use in product chat support located at the bottom right corner of your SigNoz instance or contact us at cloud-support@signoz.io.