adobe / helix-logging

Set up Logging Endpoints for a Project Helix website
Apache License 2.0
2 stars 3 forks source link

Support Logging to Coralogix #243

Closed trieloff closed 4 years ago

trieloff commented 4 years ago

If the user is providing a CORALOGIX_KEY and a coralogixApplication parameter, then set up a new HTTPS logging endpoint named "Coralogix" with following settings:

{
  "timestamp": %{time.start.msec}V, 
  "applicationName": "trieloff", 
  "subsystemName": "%{req.service_id}V", 
  "severity": %{if(resp.status<400, "3", "")}V%{if(resp.status>=400 && resp.status<500, "4", "")}V%{if(resp.status>=500, "5", "")}V, 
  "json": { 
    "ow": {
      "activationId": "%{req.http.x-openwhisk-activation-id}V"
    },
    "cdn": {
      "url": "https://%{req.http.host}V%{cstr_escape(req.url)}V",
      "host": "%{req.http.host}V",
      "service_id":"%{req.service_id}V",
      "version": "%{req.http.X-Version}V",
      "time": {
        "start": "%{begin:%Y-%m-%dT%H:%M:%S%Z}t",
        "end": "%{end:%Y-%m-%dT%H:%M:%S%Z}t",
        "elapsed": %D
      },
      "client": {
        "name": "%{client.as.name}V",
        "number": "%{client.as.number}V",
        "connection_speed": "%{client.geo.conn_speed}V",
        "ip": "%{regsuball(req.http.X-Forwarded-For, "((\\d+)\\.(\\d+)\\.(\\d+)\\.)(\\d+)", "\\1xxx")}V"
      },
      "request": {
        "id": "%{req.http.X-CDN-Request-ID}V",
        "method": "%m",
        "protocol": "%H",
        "h2": %{if(fastly_info.is_h2, "true", "false")}V,
        "h2_push": %{if(fastly_info.h2.is_push, "true", "false")}V,
        "is_ipv6": %{if(req.is_ipv6, "true", "false")}V,
        "h2_stream_id": "%{fastly_info.h2.stream_id}V",
        "url":"%{cstr_escape(req.url)}V",
        "referer": "%{Referer}i",
        "user_agent": "%{User-Agent}i",
        "accept_content": "%{Accept}i",
        "accept_language": "%{Accept-Language}i",
        "accept_encoding": "%{Accept-Encoding}i",
        "accept_charset": "%{Accept-Charset}i",
        "connection": "%{Connection}i",
        "dnt": "%{DNT}i",
        "forwarded": "%{Forwarded}i",
        "via": "%{Via}i",
        "cache_control": "%{Cache-Control}i",
        "x_requested_with": "%{X-Requested-With}i",
        "header_size": %{req.header_bytes_read}V,
        "body_size": %{req.body_bytes_read}V
      },
      "origin": {
        "host": "%v"
      },
      "response": {
        "status":"%s",
        "content_type":"%{Content-Type}o",
        "age":"%{Age}o",
        "cache_control":"%{Cache-Control}o",
        "expires":"%{Expires}o",
        "last_modified":"%{Last-Modified}o",
        "tsv":"%{TSV}o",
        "header_size": %{resp.header_bytes_written}V,
        "body_size": %B
      },
      "edge": {
        "cache_status":"%{regsub(fastly_info.state, "^(HIT-(SYNTH)|(HITPASS|HIT|MISS|PASS|ERROR|PIPE)).*", "\\2\\3")}V",
        "is_cacheable":%{if(fastly_info.state ~"^(HIT|MISS)$", "true", "false")}V,
        "datacenter":"%{server.datacenter}V",
        "ip":"%A"
      },
      "socket": {
        "cwnd": %{client.socket.cwnd}V,
        "nexthop": "%{client.socket.nexthop}V",
        "tcpi_rcv_mss": %{client.socket.tcpi_rcv_mss}V,
        "tcpi_snd_mss": %{client.socket.tcpi_snd_mss}V,
        "tcpi_rtt": %{client.socket.tcpi_rtt}V,
        "tcpi_rttvar": %{client.socket.tcpi_rttvar}V,
        "tcpi_rcv_rtt": %{client.socket.tcpi_rcv_rtt}V,
        "tcpi_rcv_space": %{client.socket.tcpi_rcv_space}V,
        "tcpi_last_data_sent": %{client.socket.tcpi_last_data_sent}V,
        "tcpi_total_retrans": %{client.socket.tcpi_total_retrans}V,
        "tcpi_delta_retrans": %{client.socket.tcpi_delta_retrans}V,
        "ploss": %{client.socket.ploss}V
      }
    }
  }
}

Note: the HTTP logging endpoint might not be enabled for a service config. In this case, the entire transaction should fail, even if Google logs have been set up successfully.

trieloff commented 4 years ago

Requires https://github.com/adobe/fastly-native-promises/issues/205

trieloff commented 4 years ago

Depends on https://github.com/adobe/fastly-native-promises/pull/208