Analytics
Analytics defines where tilegroxy records lightweight events describing successful tile usage.
Overview
This is useful for seeing which layers are actually consumed, attributing usage to tenants or users, or tracking consumption of a metered upstream provider. This differs from telemetry, which aggregates counters for operating the service rather than recording individual events.
An event is produced only when a tile is successfully served over HTTP. Failed requests and requests generated by the seed command, test command, or health checks produce no events. A layer rendered indirectly through the ref provider isn’t recorded separately, only the layer that was requested.
| A cache hit does produce an event. |
Individual layers can be excluded using the skipAnalytics parameter, see Layer.
Events are recorded asynchronously in batches, so analytics won’t add latency. If the write buffer clogs and gets full, events are dropped by default. There’s a batch.onFull config you can set to block if you would rather tile requests start hanging to try to avoid losing events. Buffered events are flushed on shutdown and upon hot reload. A regular shutdown shouldn’t lose any events, but a kill or server crash will certainly (there’s no WAL). Consider crosschecking your access logs if you detect a crash and exact tile count is important.
Every module accepts the same batch parameters. A batch is written when either maxSize events have accumulated or the oldest event in the buffer reaches maxAge. Note the age of a partial batch is only checked periodically so these rules are best-effort, not exact.
Event Contents
Every event always includes the following:
| Field | Description |
|---|---|
|
When the tile was served |
|
The ID of the layer as configured. When a layer uses a pattern this is the configured ID, not the name from the URL, matching how per-layer telemetry metrics are recorded |
|
The tile coordinates |
|
The authenticated user, or empty when the request was anonymous |
The following can be included via fields:
| Name | Description |
|---|---|
|
The layer name exactly as it appeared in the URL, which differs from the layer ID when the layer uses a pattern |
|
The placeholder values extracted from a patterned layer name, as a map |
|
The tenant identifier established during authentication, if any |
|
The client IP address |
|
The User-Agent header |
|
The Referer header |
|
The Host header |
|
The HTTP method |
|
The request path |
|
The raw query string |
|
How long the request took, in milliseconds |
|
The size of the served tile in bytes |
|
The MIME type of the served tile |
|
Whether the tile was served from cache rather than freshly rendered |
Custom Attributes
The extraFields parameter lets you get very fancy with what info you record. You can pick an env var, request var, or header and record it under whatever name you want.
| Value form | Description |
|---|---|
|
A value from the request context. Includes |
|
A request header. The name is canonicalized to Header-Case before lookup |
|
An environment variable - be cautious you don’t do something stupid like record your AWS keys |
anything else |
Used as a literal constant, useful for tagging events with an environment or region name |
For example, to track which server handled the request in question, the following gives your analytics destination a server field with your server’s hostname:
-
YAML
-
JSON
analytics:
extraFields:
server: env.HOSTNAME
{
"analytics": {
"extraFields": {
"server": "env.HOSTNAME"
}
}
}
Metrics
When telemetry is enabled, analytics reports three counters:
| Metric | Description |
|---|---|
|
Events successfully written to a destination |
|
Events discarded because a queue was full |
|
Events in batches that failed to write |
A rising dropped or error count means analytics is losing data even while tiles are served normally, so it’s recommended you alert on these separately from tile metrics.
|