Viewing Logs

Each Cloud CDN request is logged in Cloud Logging. Logging is automatic and does not need to be enabled.

Viewing logs

Logs for Cloud CDN are associated with the external HTTP(S) load balancer your Cloud CDN backends are attached to.

To view Cloud CDN logs, go to the Logs Viewer in the Cloud Platform Console.

Cloud CDN logs are indexed first by forwarding rule and then by URL map.

  • To see all logs, in the first pull-down menu select Load Balancing > All forwarding rules.
  • To see logs for just one forwarding rule, select a single forwarding rule name from the list.
  • To see logs for just one URL map used by a forwarding rule, select Load Balancing and choose the forwarding rule and URL map of interest.

Example cache hit in log

The following log entry shows a cache hit. You can view cache hits by opening the Logs Viewer in the Google Cloud Console and filtering by the forwarding rule name.

2020-06-08 16:41:30.078 PDT
GET
304
157 B
null
Chrome 83
http://LOAD_BALANCER_IP_ADDRESS/static/us/three-cats.jpg


CLIENT_IP_ADDRESS - "GET http://LOAD_BALANCER_IP_ADDRESS/static/us/three-cats.jpg" 304 157 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
Expand all | Collapse all{
 httpRequest: {
  cacheHit: true
  cacheLookup: true
  remoteIp: "CLIENT_IP_ADDRESS"
  requestMethod: "GET"
  requestSize: "577"
  requestUrl: "http://LOAD_BALANCER_IP_ADDRESS/static/us/three-cats.jpg"
  responseSize: "157"
  status: 304
  userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
 }
 insertId: "1oek5rg3l3fxj7"
 jsonPayload: {
  @type: "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry"
  cacheId: "SFO-fbae48ad"
  statusDetails: "response_from_cache"
 }
 logName: "projects/PROJECT_ID/logs/requests"
 receiveTimestamp: "2020-06-08T23:41:30.588272510Z"
 resource: {
  labels: {
   backend_service_name: ""
   forwarding_rule_name: "FORWARDING_RULE_NAME"
   project_id: "PROJECT_ID"
   target_proxy_name: "TARGET_PROXY_NAME"
   url_map_name: "URL_MAP_NAME"
   zone: "global"
  }
  type: "http_load_balancer"
 }
 severity: "INFO"
 spanId: "7b6537d3672e08e1"
 timestamp: "2020-06-08T23:41:30.078651Z"
 trace: "projects/PROJECT_ID/traces/241d69833e64b3bf83fabac8c873d992"
}

What is logged

In addition to general information contained in most logs, such as severity, project ID, project number, and timestamp, HTTP(S) Load Balancing logs contain:

  • The HttpRequest log fields, which captures the HTTP status code, bytes returned, and whether a cache lookup and/or cache fill was performed.
  • The jsonPayload.cacheId field, which indicates the location and cache instance the cache response was served from. For example, a cache response served from a cache in Amsterdam would have a cacheId value of AMS-85e2bd4b, where AMS is the IATA code, and 85e2bd4b is an opaque identifier of the cache instance, as some Cloud CDN locations have multiple discrete caches.
  • The statusDetails fields of the structPayload.

You can filter on these fields to determine the cache hit, miss or revalidation status of a request served by Cloud CDN:

  1. Cache Hit
    statusDetails="response_from_cache"

    or

    httpRequest.cacheHit=true
    httpRequest.cacheValidatedWithOriginServer!=true

  2. Cache Hit Validated With Origin Server
    statusDetails="response_from_cache_validated"

    or

    httpRequest.cacheHit=true
    httpRequest.cacheValidatedWithOriginServer=true

  3. Cache Miss
    statusDetails="response_sent_by_backend"

    or

    httpRequest.cacheHit!=true
    httpRequest.cacheLookup=true

Log fields of type boolean typically only appear if they have a value of true. If a boolean field has a value of false, that field is omitted from the log.

UTF-8 encoding is enforced for these fields. Characters that are not UTF-8 characters are replaced with question marks.

When Cloud CDN serves a client request by initiating validation requests and/or byte range requests, it omits the serverIp field from the Stackdriver Logging log entry for the client request. This is because Cloud CDN can send requests to multiple server IP addresses in reaction to a single client request.

Each request initiated by Cloud CDN creates a Stackdriver Logging log entry. The resulting log entry contains a parentInsertId field inside the jsonPayload. You can use this field to identify the insertId of the log entry for the single client request that prompted Cloud CDN to initiate the validation request or byte range request. Furthermore, the log entry identifies Cloud CDN as the user agent.

What's next

Refer to the Stackdriver Logging documentation for more information, including how to export logs to BigQuery, Cloud Pub/Sub and/or Cloud Storage, and how to configure logs-based metrics for monitoring and alerting.