Overview
Query audit logs in two ways:
- Query via MCP: Ask questions in plain language from Claude, Cursor, Codex, or another MCP-compatible AI assistant.
- Query via API: Query audit logs from scripts, security tools, or scheduled exports with the Query Range API.
Prerequisites
- SigNoz Cloud, or Self-Hosted SigNoz with an active license.
- Permission to read audit logs. The signoz-admin role can read audit logs by default. For scripts, integrations, or an MCP connection that only reads audit logs, use a read-only role instead. See Create a read-only role for audit logs.
- For MCP: an AI assistant connected to the SigNoz MCP Server (
signoz-mcp-serverv1.0.1or later on Self-Hosted SigNoz). - For the API examples:
jqto format JSON responses.
Query via MCP
Once your AI assistant is connected to the SigNoz MCP Server, ask about workspace changes in plain language. MCP queries run with the service account API key you connected with, so that service account needs a role that can read audit logs. On Self-Hosted SigNoz, use signoz-mcp-server v1.0.1 or later.
Mention "SigNoz audit logs" and a time range in your prompt so the assistant queries audit logs instead of application logs or current resource lists (without a time range, log tools default to the last 1 hour):
"Show the 20 most recent SigNoz audit logs from the last 24 hours.""Check the SigNoz audit logs for the last 7 days: who deleted a dashboard?""Show everything <email> changed in the SigNoz audit logs over the last 7 days.""From the SigNoz audit logs in the last 24 hours, count failed attempts grouped by resource kind."
Verify these values:
<email>: The email of the user, or<service-account-name>@signozserviceaccount.comfor a service account.
A valid audit log response lists workspace changes with the principal email, operation (create, update, delete, attach, or detach), resource kind and ID, outcome, and timestamp.
Under the hood, the MCP server calls signoz_search_logs and signoz_aggregate_logs with source="audit". Field discovery (signoz_get_field_keys and signoz_get_field_values) does not list audit attributes; the assistant reads the audit schema from signoz://logs/query-builder-guide, and you can name any field from the Audit Logs Reference directly in your prompt.
Query via API
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.
Create a read-only role for audit logs
An admin key can also change your workspace. For a script, an MCP connection, 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.
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 or PERMISSION_DENIED
The API 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. For MCP, reconnect the SigNoz MCP server in your client and enter a valid API key. See Authenticate from your client.
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.
- For API queries, check that
startandendcover the time of the change (in milliseconds) and thatorderis set. Withoutorder, results can leave out the most recent audit logs. - For MCP queries, include a time range and "SigNoz audit logs" in your prompt (without a time range, log tools default to the last 1 hour). On Self-Hosted SigNoz, verify
signoz-mcp-serverisv1.0.1or later.
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
- SigNoz MCP Server: Connect Claude, Cursor, Codex, or other AI clients to SigNoz.
- 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.