|
| 1 | +# Runbook: Fastly debugging |
| 2 | + |
| 3 | +## Real-time logging |
| 4 | + |
| 5 | +Aggregate statistics are available under the "Edge Observer" tab |
| 6 | +of the [Observability](https://docs.fastly.com/en/guides/about-the-observability-page) |
| 7 | +page in Fastly, this includes for example requests by cache response |
| 8 | +type (hit, miss, pass, synthetic, error), status code, object size, |
| 9 | +and HTTP version. |
| 10 | + |
| 11 | + |
| 12 | +There isn't a built-in way to review, e.g. a sampled web request log, |
| 13 | +but you can debug actual requests by setting up a logging endpoint |
| 14 | +under one of the "services" in your account. This endpiont then |
| 15 | +receives a stream of real-time log events. |
| 16 | + |
| 17 | +Documentation: |
| 18 | +* https://docs.fastly.com/en/guides/setting-up-remote-log-streaming |
| 19 | +* https://docs.fastly.com/en/guides/log-streaming-https |
| 20 | +* https://docs.fastly.com/en/guides/useful-conditions-for-logging |
| 21 | +* https://docs.fastly.com/en/guides/useful-variables-to-log |
| 22 | + |
| 23 | +### Example: Log "pass" requests |
| 24 | + |
| 25 | +* https://docs.fastly.com/en/guides/using-conditions |
| 26 | +* https://developer.fastly.com/reference/vcl/variables/ |
| 27 | +* https://developer.fastly.com/reference/http/http-headers/ |
| 28 | + |
| 29 | +Log the request URLs of requests that are considered uncachable |
| 30 | +(as opposed to a cache "miss"). |
| 31 | + |
| 32 | +Condition: |
| 33 | +``` |
| 34 | +req.http.Fastly-Cachetype == "PASS" |
| 35 | +``` |
| 36 | + |
| 37 | +Logging endpoint: |
| 38 | + |
| 39 | +* Condition: "If pass" |
| 40 | +* Placement: "Format Version Default" |
| 41 | +* Log format: (simplified from the default to not contain any obvious PII) |
| 42 | + ```json |
| 43 | + { |
| 44 | + "host": "%{if(req.http.Fastly-Orig-Host, req.http.Fastly-Orig-Host, req.http.Host)}V", |
| 45 | + "url": "%{json.escape(req.url)}V", |
| 46 | + "request_method": "%{json.escape(req.method)}V", |
| 47 | + "response_status": %{resp.status}V |
| 48 | + } |
| 49 | + ``` |
| 50 | +* URL: A newly generated URL from https://log-bin.fastly.dev/ |
| 51 | +* Advanced |
| 52 | + * Content type: `text/plain` |
| 53 | + * Method: `POST` |
| 54 | + * JSON log entry format: "Newline delimited" |
| 55 | + * Select a log line format: "Blank" |
| 56 | + |
| 57 | +### Example: Sampled "miss" log |
| 58 | + |
| 59 | +* https://developer.fastly.com/reference/vcl/functions/randomness/randombool/ |
| 60 | + |
| 61 | +``` |
| 62 | +req.http.Fastly-Cachetype == "PASS" |
| 63 | +``` |
0 commit comments