LogoLogo
  • User Guide
    • Getting Started
      • Building a Usage-Based Product in Revenium
      • Setting Up & Using API Analytics & Observability
      • Setting Up & Using Product Analytics
      • Sending Data to Revenium's Metering API
      • Key Concepts & Relationships
    • Connect Your Data
      • cURL Commands for Testing
      • Container-Native Metering
      • Kong
        • Kubernetes Installation
      • Salesforce
        • Revenium Unmanaged Package
          • Anypoint API Experience Hub (AEH)
            • Anypoint API Experience Hub Unmanaged Package Post Installation Instructions
          • Anypoint Community Manager (ACM)
            • Anypoint Community Manager Package Post Installation Instructions
        • Revenium Lightning Web Components
          • Add Components to Experience Cloud site
          • Drop-In Storefront
          • Product Card
          • Product Card (Anypoint)
          • Product Checkout
          • Product Details Button
          • Usage History
          • API Access Requester
      • MuleSoft
        • Metering Policy Configuration
        • Offline Metering Policy Configuration
        • Anypoint API & API Group Synchronization
        • Revenium Connector
        • Disable Default Anypoint Community Manager (ACM) Email Notifications
      • Gravitee
      • Istio
      • Envoy
      • AWS API Gateway
      • Python & Django
      • Golang
      • Spring Boot
      • .Net
      • NodeJs
      • Java/JVM
      • Snowflake
      • Azure API Management
      • IBM
      • Custom Integrations Using Metering Beacons
        • JWT Enrichment
      • Offline Metering via Log Parsing
    • Sources
      • Metering Elements
      • Alerts
        • Alert History
    • API Keys
    • Products & Pricing
      • Product Lines
      • Pricing Rules
        • Revenium Scripting Language
          • RSL Reference
        • Execution Logs
      • SLA Definitions
      • SLA Violation Review
    • Customers
      • Customers
      • Subscribers
      • Subscriptions
      • Subscribers Credentials
      • Subscribers Notifications
    • Billing and Invoicing
      • Manage Refunds
    • Analytics
      • Revenue Analytics
      • Product Analytics
        • Custom Reports (Products)
      • Subscriber Analytics
        • New Subscribers
        • (Daily/Weekly/Monthly) Active Subscribers
        • Most Engaged Subscribers & Customers
        • Historical Usage
      • API Analytics
        • Performance & Availability
        • Compare Periods
        • Traffic by Geography
        • Advanced Search
        • Custom Reports
    • Profile
      • Profile
      • Revenium API Documentation
    • Settings
      • Revenium Users & Organizations
        • Access Permissions by User Type
      • Revenium Subscription
      • Revenium Organizations
      • Notification Templates
      • Transactions Logs
        • Analytics Transaction Log
        • Product Transaction Log
        • Subscription Audit Log
        • No Code Transaction Testing
      • Integrations
        • Data Sync
        • Export Configurations
        • Notification Providers
        • Payment Configurations
          • Customer VAT ID Support
        • ERP Configurations
        • External Integration Logs
        • Identity Providers
      • System Logs
      • Default Configuration Limits
Powered by GitBook

© Revenium - www.revenium.io

On this page
  1. User Guide
  2. Connect Your Data

Envoy

Envoy Proxy Configuration

The following Lua Request and Response filters can be used to meter arbitrary API traffic passing through an Envoy Proxy.

request.lua

function envoy_on_request(request_handle)
    local api_client = request_handle:headers():get("x-revenium-product-key")
    if (api_client ~= nil) then
        if request_handle:connection():ssl() == nil then
            request_handle:streamInfo():dynamicMetadata():set("revenium", "scheme", "http")
        else
            request_handle:streamInfo():dynamicMetadata():set("revenium", "scheme", "https")
        end
        local method = request_handle:headers():get(":method")
        local path = request_handle:headers():get(":path")
        request_handle:streamInfo():dynamicMetadata():set("revenium", "address", address)
        request_handle:streamInfo():dynamicMetadata():set("revenium", "method", method)
        request_handle:streamInfo():dynamicMetadata():set("revenium", "path", path)
        request_handle:streamInfo():dynamicMetadata():set("revenium", "api_client", api_client)
    end
end

response.lua

function envoy_on_response(response_handle)
    local api_client = response_handle:streamInfo():dynamicMetadata():get("profitstream")["api_client"]
    local status = tonumber(response_handle:headers():get(":status"))
    if (api_client ~= nil and (status >= 200 and status <= 299)) then
        local method = response_handle:streamInfo():dynamicMetadata():get("profitstream")["method"]
        local path = response_handle:streamInfo():dynamicMetadata():get("profitstream")["path"]
        local scheme = response_handle:streamInfo():dynamicMetadata():get("profitstream")["scheme"]
        local api = response_handle:metadata():get("profitstream_api_id")
        local body = "api=" .. api .. "&apiClient=" .. api_client .. "&method=" .. method .. "&url=" .. path
        local headers, response_body = response_handle:httpCall("profitstream",
            {
                [":method"] = "POST",
                [":path"] = "/",
                [":authority"] = "profitstream",
            },
            body, 5000)
        local ps_status = tonumber(headers[":status"])
        if (ps_status > 200 or ps_status > 299) then
            response_handle:logError("Could not post body to metering beacon: " .. body)
        else
            response_handle:logDebug("Successfully posted body to metering beacon: " .. body)
        end
    end
end

Last updated 9 months ago