Integration Guide - Envoy Proxy

The Moesif Envoy plugin captures API traffic from Envoy Service Proxy and logs it to Moesif API Analytics. This plugin leverages an asynchronous design and doesn’t add any latency to your API calls.

  • Envoy is an open-source Service Proxy.
  • Moesif is an API analytics and monitoring service.

Source Code on GitHub

How to install

1. Download plugin files

Download the latest release into your current working directory for Envoy.

 wget -O moesif-envoy-plugin.tar.gz https://github.com/Moesif/moesif-envoy-plugin/archive/0.1.0.tar.gz && \
    tar -xf moesif-envoy-plugin.tar.gz -C ./ --strip-components 1

2. Update Envoy config

In your envoy.yaml, add a http_filters section along with the below code snippet below.

Your Moesif Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

 http_filters:
    - name: envoy.filters.http.lua
    typed_config:
        "@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
        inline_code: |
        local log = require("moesif.plugins.log")

        -- Moesif configs
        log.set_application_id("Your Moesif Application Id")
        -- ... For other options see below.

        function envoy_on_request(request_handle)
            -- Log Event Request to Moesif
            log.log_request(request_handle)
        end

        function envoy_on_response(response_handle)
            -- Log Event Response to Moesif
            log.log_response(response_handle)
        end

If you downloaded the files to a different location, replace moesif.plugins.log with the correct path

3. Restart Envoy

Make a few API calls to test that they are logged to Moesif.

Docker Compose

If you’re using Docker, Moesif has a sample app available in the example To run the sample:

  1. cd into the example dir
  2. Add your Moesif Application Id to envoy.yml
  3. Run the command docker-compose up -d

You can modify the Dockerfile-envoy and envoy.yml for use with your live application.

Configuration options

set_application_id()

(required), string, is obtained via your Moesif Account, this is required.

set_batch_size()

(optional) number, default 25. Maximum batch size when sending to Moesif.

set_user_id_header()

(optional) string, Request header to use to identify the User in Moesif.

set_company_id_header()

(optional) string, Request header to use to identify the Company (Account) in Moesif.

set_metadata()

(optional) table, default {}. This allows you to associate the event with custom metadata. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.

set_disable_capture_request_body()

(optional) boolean, default false. Set this flag to true, to disable logging of request body.

set_disable_capture_response_body()

(optional) boolean, default false. Set this flag to true, to disable logging of response body.

set_request_header_masks()

(optional) table, default {}. An array of request header fields to mask.

set_request_body_masks()

(optional) table, default {}. An array of request body fields to mask.

set_response_header_masks()

(optional) table, default {}. An array of response header fields to mask.

set_response_body_masks()

(optional) table, default {}. An array of response body fields to mask.

set_debug()

(optional) boolean, default false. Set this flag to true, to see debugging messages.

How to test

  1. Clone this repo and edit the compose/envoy.yaml file to set your actual Moesif Application Id.

    Your Moesif Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

    You can always find your Moesif Application Id at any time by logging into the Moesif Portal, click on the top right menu, and then clicking API Keys.

  2. Build docker image and start container

     cd compose && docker-compose up -d
    
  3. By default, The container is listening on port 8000. You should now be able to make a request:

     curl --request GET \
         --url 'http://localhost:8000/?x=2&y=4' \
         --header 'Content-Type: application/json' \
         --header 'company_id_header: envoy_company_id' \
         --header 'user_id_header: envoy_user_id' \
         --data '{
             "envoy_event": true
         }'
    
  4. The data should be captured in the corresponding Moesif account.

Congratulations! If everything was done correctly, Moesif should now be tracking all network requests. If you have any issues with set up, please reach out to support@moesif.com.

Other integrations

To view more documentation on integration options, please visit the Integration Options Documentation.