Request/Trace ID

This page is based on the following example:

https://github.com/aileron-gateway/aileron-gateway/tree/main/examples/tracking/

Tracking Middleware

Overview

This example runs a reverse-proxy server with tracking middleware. Tracking middleware have ability to handle request IDs and tracing IDs.

block-beta
  columns 7
  Downstream:1
  space:1
  block:aileron:3
    HTTPServer["πŸŸͺ</br>HTTP</br>Server"]
    TrackingMiddleware["🟩</br>Tracking</br>Middleware"]
    ReverseProxyHandler["πŸŸ₯</br>ReverseProxy</br>Handler"]
  end
  space:1
  Upstream:1

Downstream --> HTTPServer
HTTPServer --> Downstream
Upstream --> ReverseProxyHandler
ReverseProxyHandler --> Upstream

style Downstream stroke:#888
style Upstream stroke:#888
style TrackingMiddleware stroke:#77dd77,stroke-width:2px
style ReverseProxyHandler stroke:#ff6961,stroke-width:2px

Legend:

  • πŸŸ₯ #ff6961 Handler resources.
  • 🟩 #77dd77 Middleware resources (Server-side middleware).
  • 🟦 #89CFF0 Tripperware resources (Client-side middleware).
  • πŸŸͺ #9370DB Other resources.

In this example, following directory structure and files are supposed. If you need a pre-built binary, download from GitHub Releases.

tracking/          ----- Working directory.
β”œβ”€β”€ aileron        ----- AILERON Gateway binary (aileron.exe on windows).
└── config.yaml    ----- AILERON Gateway config file.

Config

Configuration yaml to run a reverse-proxy server would becomes as follows.

# config.yaml

apiVersion: core/v1
kind: Entrypoint
spec:
  runners:
    - apiVersion: core/v1
      kind: HTTPServer

---
apiVersion: core/v1
kind: HTTPServer
spec:
  addr: ":8080"
  virtualHosts:
    - middleware:
        - apiVersion: app/v1
          kind: TrackingMiddleware
      handlers:
        - handler:
            apiVersion: core/v1
            kind: ReverseProxyHandler

---
apiVersion: core/v1
kind: ReverseProxyHandler
spec:
  loadBalancers:
    - pathMatcher:
        match: "/"
        matchType: Prefix
      upstreams:
        - url: http://httpbin.org

---
apiVersion: app/v1
kind: TrackingMiddleware
spec:
  requestIDProxyName: X-Aileron-Request-ID
  traceIDProxyName: X-Aileron-Trace-ID

The config tells:

  • Start a HTTPServer with port 8080.
  • ReverseProxy is registered to the server (all paths match).
  • Apply tracking middleware to the proxy.
  • Proxy upstream is http://httpbin.org.

This graph shows the resource dependencies of the configuration.

graph TD
  Entrypoint["πŸŸͺ **Entrypoint**</br>default/default"]
  HTTPServer["πŸŸͺ **HTTPServer**</br>default/default"]
  TrackingMiddleware["🟩</br>**TrackingMiddleware**</br>default/default"]
  ReverseProxyHandler["πŸŸ₯</br>**ReverseProxyHandler**</br>default/default"]

Entrypoint --"Runner"--> HTTPServer
HTTPServer --"HTTP Handler"--> ReverseProxyHandler
HTTPServer --"Middleware"--> TrackingMiddleware

style TrackingMiddleware stroke:#77dd77,stroke-width:2px
style ReverseProxyHandler stroke:#ff6961,stroke-width:2px

Run

Run the AILERON Gateway with command:

./aileron -f ./config.yaml

Check

After running a reverse-proxy server with tracking middleware, send HTTP requests to it.

A json response will be returned when the reverse-proxy server is correctly running.

We can check

  • X-Aileron-Request-Id is added to the proxy request.
  • X-Aileron-Trace-Id is added to the proxy request.
$ curl http://localhost:8080/get
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.68.0",
    "X-Aileron-Request-Id": "00338GYPDSUVFQ4KRDD6QVX8VPH9UVGHRG5QNZZBH2V9Y0XN",
    "X-Aileron-Trace-Id": "00338GYPDSUVFQ4KRDD6QVX8VPH9UVGHRG5QNZZBH2V9Y0XN",
    "X-Amzn-Trace-Id": "Root=1-681623e8-0f9880644a116cbe4ee1db61",
    "X-Forwarded-Host": "localhost:8080"
  },
  "origin": "127.0.0.1, 106.73.5.65",
  "url": "http://localhost:8080/get"
}

Last modified June 2, 2025: update docs (df954a4)