| Crates.io | haproxy-otel |
| lib.rs | haproxy-otel |
| version | 0.2.0 |
| created_at | 2025-02-27 10:44:48.112609+00 |
| updated_at | 2025-07-25 09:28:55.725644+00 |
| description | HAProxy OpenTelemetry tracing support |
| homepage | |
| repository | https://github.com/khvzak/haproxy-otel |
| max_upload_size | |
| id | 1571597 |
| size | 71,330 |
A Rust-based OpenTelemetry module for HAProxy Community Edition using the Lua API.
Please check the module and tests directories for working examples.
global
master-worker
# This is required to enable non-blocking background activity (exporting traces)
insecure-fork-wanted
lua-load-per-thread otel.lua
...
frontend http-in
bind *:8080
http-request lua.start_server_span
filter lua.opentelemetry-trace
http-request set-var-fmt(txn.custom_attr_value) "hello"
http-request lua.set_span_attribute_var test_attribute txn.custom_attr_value
default_backend default
backend default
server srv1 127.0.0.1:8080
Create a file named otel.lua with the following content:
local opentelemetry = require("haproxy_otel_module")
opentelemetry.register({
name = "loadbalancer", -- Service name
sampler = "AlwaysOn", -- Sampling strategy
propagator = "w3c", -- Propagation format
otlp = {
endpoint = "http://otel-collector:4317/v1/trace", -- OTLP endpoint
protocol = "json", -- Protocol format (json or binary)
}
})
| Option | Description | Values | Default |
|---|---|---|---|
name |
Service name for the traces | String | "haproxy" |
sampler |
Sampling strategy | "AlwaysOn", "AlwaysOff", "ParentBased" |
"ParentBased" |
propagator |
Trace context propagation format | "w3c", "zipkin", "jaeger" |
"w3c" |
otlp.endpoint |
OTLP collector endpoint URL | URL string | "http://localhost:4318/v1/trace" |
otlp.protocol |
OTLP protocol format | "json", "binary" |
"binary" |
To create a server-side and a client-side (upstream proxying) spans for incoming requests:
http-request lua.start_server_span
filter lua.opentelemetry-trace start_client_span=true
The http-request directive is required to start a new span and filter is responsible for (optional) client-side (upstream) span creation and finishing all the spans.
Both directives are needed to create a complete trace for the request.
| Option | Description | Values | Default |
|---|---|---|---|
start_client_span |
Whether to create client spans | true, false |
true |
You can add custom attributes to spans:
http-request set-var-fmt(txn.user_id) "%[req.hdr(User-ID)]"
http-request lua.set_span_attribute_var user.id txn.user_id
You need to assign a value to a variable first, and then use the lua.set_span_attribute_var function to add the attribute to the span.
This module sends traces to an OpenTelemetry collector. Configure your collector to receive OTLP traces and export them to your preferred backend (Jaeger, Zipkin, etc.).
This project is licensed under the MIT license.