{"slug": "query-signoz-audit-logs-via-mcp-or-api-find-changes", "title": "Query SigNoz Audit Logs via MCP or API - Find Changes", "summary": "SigNoz documented two ways to query its audit logs: through the SigNoz MCP Server, which requires version 1.0.1 or later on Self-Hosted SigNoz, and through the Query Range API at POST /api/v5/query_range with a builder_query that sets \"signal\": \"logs\" and \"source\": \"audit\". The MCP path lets assistants such as Claude, Cursor and Codex answer plain-language questions about workspace changes by calling signoz_search_logs and signoz_aggregate_logs with source=\"audit\", while the API path targets scripts, security tools and scheduled exports. Both paths require a role permitted to read audit logs — the signoz-admin role by default, or a read-only role for integrations that only read audit logs — and the API example returns the 20 most recent audit logs from the last 24 hours.", "body_md": "## Overview\n\nQuery [audit logs](https://signoz.io/docs/audit-logs/overview/) in two ways:\n\n- **[Query via MCP](#query-via-mcp):** Ask questions in plain language from Claude, Cursor, Codex, or another MCP-compatible AI assistant.\n- **[Query via API](#query-via-api):** Query audit logs from scripts, security tools, or scheduled exports with the Query Range API.\n\n## Prerequisites\n\n- **SigNoz Cloud** , or**Self-Hosted SigNoz** with an active license.\n- **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](#create-a-read-only-role-for-audit-logs) .\n- For MCP: an AI assistant connected to the [SigNoz MCP Server](https://signoz.io/docs/ai/signoz-mcp-server/) (`signoz-mcp-server`` v1.0.1` or later on Self-Hosted SigNoz).\n- For the API examples: `jq` to format JSON responses.\n\n## Query via MCP\n\nOnce your AI assistant is connected to the [SigNoz MCP Server](https://signoz.io/docs/ai/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.\n\nMention \"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):\n\n- `\"Show the 20 most recent SigNoz audit logs from the last 24 hours.\"`\n- `\"Check the SigNoz audit logs for the last 7 days: who deleted a dashboard?\"`\n- `\"Show everything <email> changed in the SigNoz audit logs over the last 7 days.\"`\n- `\"From the SigNoz audit logs in the last 24 hours, count failed attempts grouped by resource kind.\"`\n\n**Verify these values:**\n\n- `<email>` : The email of the user, or`<service-account-name>@signozserviceaccount.com` for a service account.\n\nA 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.\n\nUnder 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](https://signoz.io/docs/audit-logs/reference/) directly in your prompt.\n\n## Query via API\n\n### Send a query\n\nSend 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:\n\n```\nNOW_MS=$(( $(date +%s) * 1000 ))\nSTART_MS=$(( NOW_MS - 24 * 3600 * 1000 ))\n \ncurl -s -X POST 'https://<your-signoz-url>/api/v5/query_range' \\\n  -H 'SIGNOZ-API-KEY: <your-api-key>' \\\n  -H 'Content-Type: application/json' \\\n  -d @- <<EOF | jq .\n{\n  \"schemaVersion\": \"v1\",\n  \"start\": $START_MS,\n  \"end\": $NOW_MS,\n  \"requestType\": \"raw\",\n  \"compositeQuery\": {\n    \"queries\": [\n      {\n        \"type\": \"builder_query\",\n        \"spec\": {\n          \"name\": \"A\",\n          \"signal\": \"logs\",\n          \"source\": \"audit\",\n          \"order\": [{ \"key\": { \"name\": \"timestamp\" }, \"direction\": \"desc\" }],\n          \"limit\": 20\n        }\n      }\n    ]\n  }\n}\nEOF\n```\n\n**Verify these values:**\n\n- `<your-signoz-url>` : The URL of your SigNoz workspace.\n- `<your-api-key>` : An API key that can read audit logs.\n\nThe fields that matter for audit logs:\n\n- `\"signal\": \"logs\"` and`\"source\": \"audit\"` select audit logs. Without`source` , the query reads your application logs.\n- `start` and`end` are Unix timestamps in milliseconds.\n- `order` sorts by time. Always set it. Without`order` , the results are in no particular order and can leave out the most recent audit logs.\n- `filter.expression` , which the examples below add, narrows the results. See[Fields](https://signoz.io/docs/audit-logs/reference/#fields) for what you can filter on.\n\nEach row in `data.data.results[0].rows` is one audit log. A trimmed row:\n\n```\n{\n  \"data\": {\n    \"timestamp\": 1795514484872756000,\n    \"event_name\": \"signoz.audit.delete\",\n    \"body\": {\n      \"message\": \"jane@example.com (019e7346-af3d-7c9a-984a-755b731ec346) deleted dashboard (01a20d00-c867-7bb0-9419-cd3d5109cf7f)\"\n    },\n    \"attributes\": {\n      \"client.address\": \"203.0.113.24\",\n      \"http.route\": \"/api/v2/dashboards/{id}\",\n      \"signoz.audit.action_category\": \"configuration_changes\",\n      \"signoz.audit.outcome\": \"success\",\n      \"signoz.audit.verb\": \"delete\",\n      \"signoz.principal.email\": \"jane@example.com\",\n      \"signoz.principal.id\": \"019e7346-af3d-7c9a-984a-755b731ec346\",\n      \"signoz.principal.type\": \"user\",\n      \"user_agent.original\": \"Mozilla/5.0 ...\"\n    },\n    \"resource\": {\n      \"attributes\": {\n        \"signoz.resource.id\": \"01a20d00-c867-7bb0-9419-cd3d5109cf7f\",\n        \"signoz.resource.kind\": \"dashboard\"\n      }\n    }\n  }\n}\n```\n\n### Examples\n\nEach example below replaces the `spec` in the request above. Set `requestType` as listed.\n\n#### Find every change to one dashboard\n\nLists the create, update, and delete operations on one dashboard, newest first. Request type: `raw`.\n\n```\n{\n  \"name\": \"A\",\n  \"signal\": \"logs\",\n  \"source\": \"audit\",\n  \"filter\": {\n    \"expression\": \"signoz.resource.kind = 'dashboard' AND signoz.resource.id = '<dashboard-id>'\"\n  },\n  \"order\": [{ \"key\": { \"name\": \"timestamp\" }, \"direction\": \"desc\" }],\n  \"limit\": 100\n}\n```\n\n**Verify these values:**\n\n- `<dashboard-id>` : The ID of the dashboard. It is the last part of the dashboard's URL in SigNoz,`/dashboard/<dashboard-id>` .\n\nTo look up another kind of resource, change `signoz.resource.kind`. For the list of kinds, see [Resource kinds](https://signoz.io/docs/audit-logs/reference/#resource-kinds).\n\n#### Find what a user or service account changed\n\nRequest type: `raw`.\n\n```\n{\n  \"name\": \"A\",\n  \"signal\": \"logs\",\n  \"source\": \"audit\",\n  \"filter\": { \"expression\": \"signoz.principal.email = '<email>'\" },\n  \"order\": [{ \"key\": { \"name\": \"timestamp\" }, \"direction\": \"desc\" }],\n  \"limit\": 100\n}\n```\n\n**Verify these values:**\n\n- `<email>` : The email of the user, or of the service account. A service account's email is`<service-account-name>@signozserviceaccount.com` .\n\n#### Find changes to roles, users, and keys\n\nChanges to who can do what, such as role assignments and new API keys, have the action category `access_control`. Request type: `raw`.\n\n```\n{\n  \"name\": \"A\",\n  \"signal\": \"logs\",\n  \"source\": \"audit\",\n  \"filter\": { \"expression\": \"signoz.audit.action_category = 'access_control'\" },\n  \"order\": [{ \"key\": { \"name\": \"timestamp\" }, \"direction\": \"desc\" }],\n  \"limit\": 100\n}\n```\n\n#### Count failed attempts by resource kind\n\nA failed attempt is a change that SigNoz rejected, for example because the caller lacked permission or sent an invalid request. Request type: `scalar`.\n\n```\n{\n  \"name\": \"A\",\n  \"signal\": \"logs\",\n  \"source\": \"audit\",\n  \"aggregations\": [{ \"expression\": \"count()\" }],\n  \"filter\": { \"expression\": \"signoz.audit.outcome = 'failure'\" },\n  \"groupBy\": [{ \"name\": \"signoz.resource.kind\" }]\n}\n```\n\nThe 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`.\n\n#### Count changes per hour by operation\n\nRequest type: `time_series`.\n\n```\n{\n  \"name\": \"A\",\n  \"signal\": \"logs\",\n  \"source\": \"audit\",\n  \"stepInterval\": 3600,\n  \"aggregations\": [{ \"expression\": \"count()\" }],\n  \"groupBy\": [{ \"name\": \"signoz.audit.verb\" }]\n}\n```\n\nThe result has one series per operation (`create`, `update`, `delete`, `attach`, `detach`), with one point per hour.\n\n## Create a read-only role for audit logs\n\nAn 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.\n\nThe role editor in **Settings > Roles** does not offer audit logs yet, so create the role with the [Roles API](https://signoz.io/api-reference/).\n\n1. \nCreate the role with an admin API key: \n\n```\ncurl -X POST 'https://<your-signoz-url>/api/v1/roles' \\\n  -H 'SIGNOZ-API-KEY: <your-admin-api-key>' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"name\": \"audit-log-reader\",\n    \"description\": \"Read audit logs\",\n    \"transactionGroups\": [\n      {\n        \"relation\": \"read\",\n        \"objectGroup\": {\n          \"resource\": { \"type\": \"telemetryresource\", \"kind\": \"audit-logs\" },\n          \"selectors\": [\"builder_query/*\"]\n        }\n      }\n    ]\n  }'\n```\n\n The response status is `201 Created` .\n2. \nCreate a service account, assign it the **audit-log-reader** role, and generate an API key. See[Service Accounts](https://signoz.io/docs/manage/administrator-guide/iam/service-accounts/) .\n\n**Verify these values:**\n\n- `<your-signoz-url>` : The URL of your SigNoz workspace, for example`acme.us.signoz.cloud` .\n- `<your-admin-api-key>` : An API key of a service account with the**signoz-admin** role.\n\nKeys 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.\n\n## Export audit logs on a schedule\n\nTo copy audit logs to a security tool or to storage that keeps them longer than 180 days, run the request in [Send a query](#send-a-query) on a schedule with a read-only key:\n\n- \nSet `start` to the`end` of the previous run. An audit log at the boundary between two runs can appear in both, so drop duplicates by the row's`id` .\n- \nOrder by `timestamp` and then`id` , so that the order is stable between requests:\n\n```\n\"order\": [\n  { \"key\": { \"name\": \"timestamp\" }, \"direction\": \"asc\" },\n  { \"key\": { \"name\": \"id\" }, \"direction\": \"asc\" }\n]\n```\n\n- \nIf a run returns `limit` rows, there can be more. Send the same request again with`offset` set to the number of rows received so far, until a request returns fewer rows than`limit` .\n\n## ## Troubleshooting\n\n### 403 `not authorized to perform audit-logs:read` or `PERMISSION_DENIED`\n\nThe 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](#create-a-read-only-role-for-audit-logs) role. If the role used to work, check that nobody saved it from the role editor, which removes the audit logs grant.\n\n### 401 unauthenticated\n\nThe 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](https://signoz.io/docs/ai/signoz-mcp-server/#authenticate-from-your-client).\n\n### A change is missing\n\n- Check that the change is one that SigNoz records. Reads, sign-ins, and some resources are not recorded. See [What is not recorded](https://signoz.io/docs/audit-logs/overview/#what-is-not-recorded) .\n- For API queries, check that `start` and`end` cover the time of the change (in milliseconds) and that`order` is set. Without`order` , results can leave out the most recent audit logs.\n- 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-server` is`v1.0.1` or later.\n\n### One change appears twice\n\nWhen 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.\n\n## Next steps\n\n- [SigNoz MCP Server](https://signoz.io/docs/ai/signoz-mcp-server/) : Connect Claude, Cursor, Codex, or other AI clients to SigNoz.\n- [Audit Logs Reference](https://signoz.io/docs/audit-logs/reference/) : Look up the fields you can filter and group by.\n- [Service Accounts](https://signoz.io/docs/manage/administrator-guide/iam/service-accounts/) : Create service accounts and API keys.\n- [Search Logs](https://signoz.io/docs/logs-management/logs-api/search-logs/) : Return only some fields, and page through results.\n\n## Get Help\n\nIf you need help with the steps in this topic, please reach out to us on [SigNoz Community Slack](https://signoz.io/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](mailto:cloud-support@signoz.io).", "url": "https://wpnews.pro/news/query-signoz-audit-logs-via-mcp-or-api-find-changes", "canonical_source": "https://signoz.io/docs/audit-logs/query", "published_at": "2026-11-30 00:00:00+00:00", "updated_at": "2026-11-30 12:45:05.500092+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-tools", "developer-tools"], "entities": ["SigNoz", "SigNoz MCP Server", "Claude", "Cursor", "Codex", "signoz_search_logs", "signoz_aggregate_logs", "Query Range API"], "also_reported_by": [], "takeaway": "To pull audit logs instead of application logs, set \"source\": \"audit\" alongside \"signal\": \"logs\" in a builder_query to POST /api/v5/query_range, or ask an MCP-connected assistant for \"SigNoz audit logs\" with an explicit time range, since log tools otherwise default to the last 1 hour.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/query-signoz-audit-logs-via-mcp-or-api-find-changes", "markdown": "https://wpnews.pro/news/query-signoz-audit-logs-via-mcp-or-api-find-changes.md", "text": "https://wpnews.pro/news/query-signoz-audit-logs-via-mcp-or-api-find-changes.txt", "jsonld": "https://wpnews.pro/news/query-signoz-audit-logs-via-mcp-or-api-find-changes.jsonld"}}