/proxy-wasm-cloud-logging-trace-context

A proxy-wasm compilant WebAssembly module for making proxies integrate with Google Cloud Logging.

Primary LanguageZigMIT LicenseMIT

proxy-wasm-cloud-logging-trace-context

A proxy-wasm compliant WebAssembly module for making proxies integrate with Google Cloud Logging.

Overview

In order to generate logs associated with Google Cloud Trace for Google Cloud Logging, we need to add a logging.googleapis.com/trace field to the log entries.

This proxy-wasm compliant WebAssembly module helps proxies generate logs integrated with Cloud Logging and Cloud Trace by extracting the trace id from the X-Cloud-Trace-Context HTTP Header and populating X-Cloud-Logging-Trace-Context by using the extracted trace id. The populated X-Cloud-Logging-Trace-Context HTTP Header is formatted as projects/<Your Google Cloud Project ID>/traces/<Trace ID> and can be used to add a logging.googleapis.com/trace filed to logs.

Usage

  1. Download the latest WebAssembly module from the release page.

  2. Configure the proxy to use the WebAssembly module and generate logs like below (this assumes Envoy as the proxy):

access_log:
  name: log
  typed_config:
    '@type': type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog
    log_format:
      json_format:
        status: '%RESPONSE_CODE%'
        message: access log
        severity: INFO
        component: envoy
        logging.googleapis.com/trace: '%REQ(x-cloud-logging-trace-context)%'
http_filters:
  - name: envoy.filters.http.wasm
    typed_config:
      '@type': type.googleapis.com/udpa.type.v1.TypedStruct
      type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
      value:
        config:
          vm_config:
            runtime: envoy.wasm.runtime.v8
            code:
              local:
                filename: /etc/envoy/proxy-wasm-cloud-logging-trace-context.wasm
          configuration:
            "@type": type.googleapis.com/google.protobuf.StringValue
            value: |
              {
                "project_id": "my-projectid"
              }
  - name: envoy.filters.http.router
    typed_config:
      '@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router