Request logs data reference
The article explains the file format and data structure of the API request log feature, detailing the content and available data.
This article describes the file format and data structure delivered by the API request log feature.
File format
Files are gzipped in newline-delimited JSON (NDJSON) format.
File content
The logs contain detailed HTTP event information, with each line representing an individual event.
Exclude exempt requests from cost analysis
Many requests from Sanity's own tools, like Sanity Studio, Canvas, etc., are exempt from API and bandwidth usage when they carry a reserved tag starting with sanity.*. Not all tags starting with the sanity. prefix are exempt.
The exemption follows the tag, not the tool. For example, sanity dataset export sends untagged requests and downloads assets without a tag, so an export counts toward your usage. Agent Actions requests are always billed, whatever their tags. Responses with a status code of 400 or higher aren't billed.
Available data
Each event contains the following fields. The Mapping column shows where each field appears in the event's JSON object.
| Field ID | Field name | Type | Description | Mapping |
|---|---|---|---|---|
| insertId | Insert ID | String | Unique identifier for log entry. Used in deduplication processes. | body.insertId |
| traceId | Trace ID | String | Can appear for multiple log entries. Useful for Sanity Support. | traceId |
| spanId | Span ID | String | Can appear for multiple log entries. Useful for Sanity Support. | spanId |
| timestamp | Timestamp | String | Time of request in RFC3339 UTC format. | timestamp |
| severityText | Severity Text | String | Severity derived from the response status: INFO for status codes below 400, WARN for 400 to 499, and ERROR for 500 and above. | severityText |
| severityNumber | Severity Number | Integer | Numeric severity matching severityText: 9 (INFO), 13 (WARN), or 17 (ERROR). | severityNumber |
| resourceType | Resource Type | String | Type of resource the request targets, parsed from the request URL: project or media-library. | attributes.sanity.resourceType |
| resourceId | Resource ID | String | ID of the resource named in resourceType, such as a project ID or a Media Library ID. | attributes.sanity.resourceId |
| projectId | Project ID | String | Project ID associated with the request. | attributes.sanity.projectId |
| datasetName | Dataset Name | String | Dataset associated with the request. Not all APIs require a dataset name. | attributes.sanity.dataset |
| domain | Request Type | String | Type of request (api, apicdn, cdn, studio). | attributes.sanity.domain |
| requestMethod | Request Method | String | HTTP verb used (for example, GET or POST). Useful for differentiating request types. | body.method |
| requestUrl | Full URL | String | Unaltered URL received by Sanity including query parameters. | body.url |
| groqQueryIdentifier | GROQ Query Identifier | String | Hashed version of the GROQ query string without parameters. Useful for grouping similar queries. Only available for GET requests. | attributes.sanity.groqQueryIdentifier |
| apiVersion | API Version | String | API version used, with the leading "v" stripped from the URL (for example, 1, X, or YYYY-MM-DD). Not applicable to asset requests. | attributes.sanity.apiVersion |
| tags | Tags | String[] | Array of tags supplied by the caller. Useful for grouping requests by business needs. | attributes.sanity.tags |
| referer | Referrer | String | Referrer URL of the request, as defined in HTTP/1.1 Header Field Definitions. | body.referer |
| userAgent | User Agent | String | User agent sent by the client. Optional. Example: python-requests/2.21.0. | body.userAgent |
| remoteIp | Remote IP | String | IP address (IPv4 or IPv6) of the client that issued the HTTP request. Includes port information if available. | body.remoteIp |
| studioRequest | Is Studio Request | Boolean | Indicates whether the request has a tag that starts with sanity.studio. Sanity Studio adds this tag prefix to its requests. | attributes.sanity.studioRequest |
| returnStatus | Return Status | Integer | Response code indicating the status of the response (for example, 200 or 404). | body.status |
| requestSize | Request Size | Number | Size of the HTTP request message in bytes. | body.requestSize |
| responseSize | Response Size | Number | Size of the HTTP response message sent back to the client in bytes. Used for metering bandwidth. | body.responseSize |
| duration | Response Time | Decimal | Number of milliseconds between request and response within the service. Useful for performance analysis. Does not account for network latency. | body.duration |
| endpoint | Endpoint | String | The endpoint used in the request. For example, graphql for GraphQL calls, query for GROQ queries, and mutate for mutations. | attributes.sanity.endpoint |
The groqQueryIdentifier value is empty for POST requests. To group or identify POST queries, use request tags.
Example output
The following example shows one event, formatted with line breaks and comments for readability. In a log file, each event is a single line of JSON without comments:
{
"timestamp": "2024-01-03T13:36:56.87202961Z",
"traceId": "b48b918db42f0f0786702fa3ef7f6451",
"spanId": "be245ae33db3cdaf",
"severityText": "INFO", // INFO = <400, WARN = 400-499, ERROR = >=500
"severityNumber": 9, // INFO = 9, WARN = 13, ERROR = 17
"body": {
"duration": 32,
"insertId": "asdf93n03nasdf",
"method": "GET",
"referer": "",
"remoteIp": "34.79.228.45",
"requestSize": 421,
"responseSize": 936,
"status": 200,
"url": "https://0ekpuoxg.apicdn.sanity.io/v2022-09-01/data/query/cache-delay?query=%0A%2A%5B_id+%3D%3D+%22cache-delay%22%5D%5B0%5D%7B%0A++++%22timestampUnixMs%22%3A+dateTime%28_updatedAt%29+-+dateTime%28%221970-01-01T00%3A00%3A00Z%22%29%2C%0A++++%22counter%22%3A+counter%0A%7D%0A",
"userAgent": "python-requests/2.21.0"
},
"resource": {
"service": {
"name": "Sanity.io"
},
"sanity": {
"type": "http_request",
"version": "0.0.1"
}
},
"attributes": { // parsed from the request URL
"sanity": {
"resourceType": "project",
"resourceId": "0ekpuoxg",
"projectId": "0ekpuoxg",
"dataset": "cache-delay",
"domain": "apicdn",
"endpoint": "query",
"groqQueryIdentifier": "faaf4cdc188e5c2",
"apiVersion": "2022-09-01",
"tags": [],
"studioRequest": false
}
}
}File delivery for projects on enterprise plans
We key the object using Hive partitioning with the following format:
gs://[BUCKET_NAME]/[PREFIX]/event-logs/project_id=[string]/kind=request-log/dt=[date:DATE]/[file-name:string].ndjson.gzThis lets you load the data into various platforms, using the project ID, data type, and date as partitioning properties.