IBM Instana

IBM Instana

The community for performance and observability professionals to learn, to share ideas, and to connect with others.

 View Only

Tracing OpenResty Lua Code with OpenTelemetry (OTel) and Instana

By Sebastian Parschauer posted 09/23/26 05:37 AM

  

OpenResty — NGINX enhanced with the Lua programming language — is widely used for API gateways, dynamic content serving, and high-performance web applications.

Instana has long provided automatic distributed tracing for NGINX through the Instana NGINX OpenTracing module. However, one gap has persisted: Lua code executing inside OpenResty could not be traced automatically, breaking the end-to-end trace continuity that developers and SREs rely on.
Today we are announcing native OpenTelemetry tracing support for OpenResty Lua code.

With this release, HTTP requests issued from Lua via lua-resty-http ≥ 0.18.0 are fully stitched into distributed traces alongside NGINX, Java, Go, and Python spans — giving you complete visibility across the entire request path.

The problem: broken trace continuity for Lua code

When Lua code inside OpenResty makes HTTP requests to upstream services, those calls traditionally start a new trace rather than continuing the existing one. This happens because the W3C traceparent header — necessary to link the outgoing call to the current trace—was never forwarded by Lua HTTP clients.
The result: You see two disconnected traces instead of one continuous end-to-end flow.

The solution: W3C traceparent propagation through Lua

The fix is straightforward. The Instana NGINX OTel module automatically injects the traceparent header (carrying the NGINX span ID) into every proxied request. When lua-resty-http ≥ 0.18.0 is installed, it picks up this header from the NGINX variable ngx.var.http_traceparent and forwards it to upstream services — no code
changes required.

local http = require "resty.http"
local httpc = http.new()
local res, err = httpc:request_uri("http://server-app:8080", {
    method = "GET",
})
-- traceparent is propagated automatically by lua-resty-http >= 0.18.0


The NGINX sensor (version 1.1.89 and later) also includes a proactive check: It verifies whether the installed lua-resty-http provides traceparent support. If it doesn't, the sensor raises a resty_http_no_tracing monitoring event, helping you identify and remediate gaps before they impact observability.

How it works in practice

A complete, runnable demo is available at:
https://github.com/instana/otel-demos/blob/main/openresty-otel-tracing
The demo deploys a Docker Compose stack that demonstrates two request paths through OpenResty:

   Service    Description
   client-app A Spring Boot application that sends an HTTP request every second to OpenResty's /openresty-otel-demo endpoint (the standard NGINX proxy path). Traced by the Instana Java agent.
   client-app-lua Identical to client-app, but targets the /lua-otel-demo endpoint, which routes through Lua code using lua-resty-http. Also traced by the Instana Java agent.
   openresty The OpenResty 1.31.1 reverse proxy, instrumented with the Instana NGINX OTel module. Forwards all requests to server-app.
   server-app A simple Spring Boot application that returns 200 OK. Traced by the Instana Java agent.
   agent The Instana agent that collects Java spans and NGINX stub_status metrics.
   collector The Instana distribution of the OpenTelemetry Collector (IDOT) that receives OpenResty/NGINX spans over gRPC (port 4317) and forwards them to the Instana backend via OTLP HTTP.

Here's how the trace flows:

  1. The Spring Boot client-app initiates a request and the Instana Java agent injects a W3C traceparent header.
  2. OpenResty's NGINX OTel module extracts that header, creates a child span for the NGINX/OpenResty request (same trace ID, new span ID), and injects a new traceparent header into the upstream request.
  3. For the /lua-otel-demo path, lua-resty-http ≥ 0.18.0 automatically forwards the traceparent to server-app, continuing the trace through the Lua code.
  4. The server-app completes the request, and the Instana Java agent closes the final span.
  5. NGINX OTel spans are sent to the IDOT collector via gRPC and forwarded to the Instana backend via OTLP HTTP, alongside the Java spans — producing a single, unified end-to-end trace.

The otel_service_name directive in the NGINX configuration controls how the OpenResty service appears in Instana:

# Set in openresty/nginx.conf
otel_service_name "openresty-otel-proxy";

What you see in Instana

Once the stack is running and traces are flowing, you can find the OpenResty service in the Instana UI:

  • Applications — Search for the service name openresty-otel-proxy to view NGINX spans and end-to-end traces.
  • Analytics — Use the trace/span search and filter by service.name = openresty-otel-proxy to query individual spans.
  • Infrastructure — Navigate to Infrastructure and filter by the zone configured in the .env file (default: openresty-tracing-demo) to find the host.
  • Service dashboard — The service dashboard shows OpenResty alongside the Java services in the service map.
  • Flow graph — The end-to-end flow graph visualizes the complete call chain: client-app → openresty → server-app.

Getting started

The full demo — including Docker Compose configuration, NGINX config, IDOT collector pipeline, and Instana agent settings — is available at:

https://github.com/instana/otel-demos/blob/main/openresty-otel-tracing

To try it yourself:

  1. Clone the repository:
    git clone https://github.com/instana/otel-demos.git
    cd otel-demos/openresty-otel-tracing
    
  2. Configure your credentials:
    cp .env.example .env
    
    Fill in your Instana agent key, download key, OTLP HTTP endpoint, and host name/ID in the .env file. If you don't have an Instana account, request a free trial.
  3. Build and launch the demo:
    docker-compose down && docker-compose up --build
    
  4. View traces in Instana: Once the stack is healthy, open the Instana UI and search for openresty-otel-proxy in Applications or Analytics to see end-to-end traces flowing through both the NGINX proxy path and the Lua code path.

Important notes and limitations

  • The lua-resty-http library, the NGINX Lua module, OpenResty itself, and any custom Lua code are third-party components not directly supported by Instana. Issues with these components should be routed to their respective vendors.
  • Instana support covers the Instana-specific NGINX OTel module and the IDOT collector used in this demo.
  • The NGINX sensor's resty_http_no_tracing monitoring event can help you detect whether your lua-resty-http version supports traceparent propagation. Enable it in the Instana agent configuration:
com.instana.plugin.nginx:
  openresty:
    tracing:
      enabled: true
      check_resty_http: true
  • For a fallback approach without upgrading lua-resty-http, you can manually forward the traceparent header in your Lua code by reading it from the ngx.var.http_traceparent NGINX variable.

Learn more


Ready to trace your OpenResty Lua code? Clone the demo at https://github.com/instana/otel-demos/blob/main/openresty-otel-tracing and try it with your own Instana agent key — or request an Instana trial to get started today.


#Documentation
#Education
#OpenTelemetry
#Tracing
#Announcement
#Cloud
#Demo
#Integration
#Tutorial

1 comment
17 views

Permalink

Comments

17 days ago

Great Insight