How to support API analytics and Monetization with the Moesif Plugin for Envoy WASM

Moesif is offering a new Envoy plugin for Envoy’s latest proxy supporting WebAssembly.

Envoy is an open-source edge and service L7 proxy designed for cloud-native applications. Originally built at Lyft, it’s now part of the Cloud Native Computing Foundation. It provides a universal data plane API and is commonly used as a service mesh in microservices architectures, where it provides advanced load balancing, and API observability.

Web Assembly (WASM) is a binary instruction format for a stack-based virtual machine. It’s an architecture independent compilation target for several languages, including Rust which we used for this plugin. By design each WASM plugin runs in its own sandboxed environment for security and stability. WASM plugins in Envoy have near-native execution speed, and the async design of the Moesif WASM plugin adds no latency to monitored traffic.

Moesif provides deep product analytics and effortless monetization for API-enabled companies. Detailed insights on how your API product is being used span the gamut from tracking and altering on key metrics, through to identifying issues in onboarding flows. Additionally, your APIs can be easily monetized by just connecting Moesif to your billing provider and defining your usage-based meter like prepaid, postpaid or PAYG.

Learn More About Moesif Monetize in Minutes with Moesif 14 day free trial. No credit card required. Try for Free

Moesif’s Envoy WASM plugin is designed to be simple to install and configure, and supports our advanced API analytics and monetization features out the gate. It’s available as a free trial, and it can be installed in minutes.

How to set up Envoy API monitoring

The Moesif Envoy WebAssembly (WASM) plugin enables comprehensive API logging for analytics and API monetization. It helps engineering teams understand API usage, resolve issues, and empowers product teams to understand customer journeys and optimize resource allocation. It aids in identifying customer behavior patterns and helps in understanding the usage of specific payload keys.

Envoy, with its configurable APIs, permits dynamic proxy configuration. It offers robust and detailed customization of request handling to route traffic and apply the plugins to only some or all traffic as desired.

The Moesif Envoy WASM plugin, as a crucial part of this architecture, captures traffic data for detailed API analytics. It identifies API users, associates API users with organizational customers, and supports the creation of complex customer funnel reports, alerts, and usage based billing calculation. Automatic identification of users and companies from events, and efficient handling of traffic even during peak loads, are standout features of this plugin. The plugin ensures optimal performance by queueing events and periodically flushing them to Moesif, thus adding no latency even under high traffic conditions.

Run and Configure the Moesif Envoy WASM Plugin

If you want to try this out now, you can start the ready to use docker-compose example here: Moesif Envoy WASM Plugin

Assuming you have an existing Envoy setup, you can add the Moesif WASM plugin in just a few steps:

  1. Navigate to the GitHub release page, and download the moesif_envoy_wasm_plugin.wasm file from the assets section of the latest release.
  2. Place the file in a directory accessible to Envoy, such as /etc/envoy/proxy-wasm-plugins/ and note this for the configuration below.
  3. Add the following to your Envoy configuration:
http_filters:
# ... other filters ...
- name: envoy.filters.http.wasm
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
    config:
      name: "moesif_api"
      root_id: "moesif_api_root_id"
      configuration:
        "@type": "type.googleapis.com/google.protobuf.StringValue"
        value: |
          {
            "moesif_application_id":"<YOUR APPLICATION ID HERE>",
            "user_id_header":"X-User-Example-Header",
            "company_id_header":"X-Company-Example-Header",
            "upstream": "moesif_api"
          }
      vm_config:
        vm_id: "moesif_api_vm"
        code:
          local:
            # Path to the plugin file you downloaded above
            filename: "/etc/envoy/proxy-wasm-plugins/moesif_envoy_wasm_plugin.wasm"
# ... other filters ending with router
- name: envoy.filters.http.router
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
# ... other clusters ...
# Add the following cluster to enable Envoys WASM plugin to send data to Moesif
- name: moesif_api
  type: strict_dns
  load_assignment:
    cluster_name: moesif_api
    endpoints:
    - lb_endpoints:
      - endpoint:
          address:
            socket_address:
              address: api.moesif.net
              port_value: 443
  transport_socket:
    name: envoy.transport_sockets.tls
    typed_config:
      "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext

Note: The moesif_application_id is required

  • Sign up for a free trial at https://www.moesif.com/signup
  • Your application id will be generated during onboarding and will look something like U3RhcnQgbm93IGF0IGh0dHBzOi8vbW9lc2lmLmNvbS9zaWdudXAK
  1. Restart Envoy to load the new configuration.

  2. Make a few API calls that pass through the Envoy proxy. These calls should now be logged to your Moesif account.

This blog article section describes the set up of a Lua Envoy plugin. We have a new WebAssembly Envoy Plugin. Given the blog section below, use the readme of the new plugin to write a similar blog section for the new WebAssembly Envoy plugin.

How to use API observability

Engineering metrics

The first thing you’ll probably be interested in is engineering metrics like your API performance. This type of metric can be pulled up by going to Events -> Time Series view within Moesif. Then you can select 90th percentile latency as the metric to plot. You can then group by the URI route to understand which endpoints have the worst performance. Here, you can filter your traffic by API attributes like route, verb, along with HTTP headers and body fields.

90th percentile latency by API endpoint

Business metrics

To associate API calls to individual customers, configure Envoy with the user_id_header or company_id_header configuration option.

Once done, you can then store additional customer attributes like Company Domain or User Email via Moesif’s user tracking SDK. This provides clarity for customer-facing teams to understand who is using your APIs along with how they are using them.

Moesif supports analyzing common payload content-types including JSON and XML. As an example, you can group API calls by response.body.label and then group by Company Domain as shown in the below chart. This shows which customers received a bad experience due to running into Out of Stock issues even though no 500 error was thrown.

API Payload Analytics

Closing thoughts

With the Moesif Envoy WASM plugin, your engineering and business teams are empowered with deep API observability and monetization without the high cost of building and maintaining your own homegrown tooling.

To see the Envoy integration with Moesif in action, you can git clone and run this example app from GitHub

Learn More About Moesif Deep API Observability with Moesif 14 day free trial. No credit card required. Try for Free
Monetize in Minutes with Moesif Monetize in Minutes with Moesif

Monetize in Minutes with Moesif

Learn More