How to analyze high Sanity CDN API usage and identify request sources?
Good news - you can definitely get more detailed information about those API CDN requests! Sanity has a Request Logs feature that's perfect for tracking down exactly where your usage is coming from.
For self-serve plans, you can download request logs directly:
- Go to your project's Usage section at sanity.io/manage
- Scroll to the bottom of the page
- Download up to 1GB of log data from the last 7 days
- You can request a new export every 24 hours
The logs come as GZIPPED NDJSON files and include super helpful fields like:
- Request Type (API, APICDN, CDN) - so you can see exactly which requests are hitting the CDN
- Full URL with query parameters
- GROQ Query Identifier - lets you group similar queries together
- Referrer and User Agent - helps identify where requests are coming from
- Remote IP - can help spot bot traffic or unexpected sources
- Timestamp - identify patterns or spikes
Pro tip: Use Request Tags to track down sources
This is probably the most useful thing for your situation. You can add the tag query parameter or X-Sanity-Client-Tag header to your requests to label them. This makes it super easy to see which parts of your app are generating the most requests.
If you're using @sanity/client, you can set this up at two levels:
const client = createClient({
projectId: "<project>",
dataset: "<dataset>",
useCdn: false,
apiVersion: "2024-01-24",
requestTagPrefix: "remix-app" // Added to every request
});
// Then tag specific requests
const products = await client.fetch('*[_type == "product"]', {
tag: `product-page`, // Results in tag=remix-app.product-page
});Analyzing the logs
Once you've downloaded the logs, you can convert them to CSV for easier analysis:
gunzip --stdout [logfile].ndjson.gz | npx json2csv --ndjson --output output.csvYou can also use tools like jq, GROQ CLI, or even upload samples to ChatGPT to help analyze patterns.
Common culprits for high CDN usage:
- Missing dependencies in
useEffecthooks causing request loops - Shopify webhook integrations making excessive calls
- Bot traffic
- Queries running on every render instead of being properly cached
Since you're using Remix + Shopify Connect, I'd especially check if your Shopify webhooks or product sync logic might be triggering more fetches than expected. The request logs will show you the exact URLs and patterns so you can pinpoint it!
Show original thread13 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.