Request tags
Request tags in Sanity Log Delivery can be added to API and CDN requests for filtering and aggregating log data, supported by @sanity/client.
Request tags are values assigned to API and CDN requests that can be used to filter and aggregate log data within request logs from your Sanity Content Lake. The tagging can be achieved by adding the tag
query parameter to the request URL, typically in the format:
GET /data/query/<dataset>?query=<GROQ-query>&tag=<custom-defined-tag>
@sanity/client has out-of-the-box support for tagging every API and CDN request on two levels:
- Globally: Using the
requestTagPrefix
client configuration parameter - Per Request: Pass the tag option to the SDK’s Request method.
This provides a flexible method for tagging requests:
requestTagPrefix | tag | result |
- | - | - |
- | landing-page | tag=landing-page |
website | - | tag=website |
website | landing-page | tag=website.landing-page |
The following example will result in a query with tag=website.landing-page
.
const client = createClient({
projectId: "<project>",
dataset: "<dataset>",
token: "",
useCdn: false,
apiVersion: "2024-01-24",
requestTagPrefix: "website" // Added to every request
});
const posts = await client.fetch('*[_type == "post"]', {
tag: `landing-page`, // Appended to requestTagPrefix for this individual request
});