0

I'm trying to capture the unique id for each request in my logs. I thought I could use capture request header X-Unique-ID len 16 on the header but its not working. Any suggestions?

global
log /dev/log local1
maxconn 4096
user haproxy
group haproxy
daemon
stats socket /var/run/haproxy.sock mode 600 level admin
spread-checks 5

defaults
log    global
mode    http
option    httplog
option  dontlog-normal
option log-separate-errors
option    dontlognull
retries    2
option redispatch
maxconn 2000
timeout connect 5s
timeout client  15s
timeout server  10s
#option forwardfor
#option http-server-close


frontend http-in
bind *:8080
monitor-uri /haproxy-health
unique-id-header X-Unique-ID
unique-id-format %{+X}o\ %ci:%cp_%fi:%fp_%Ts_%rt:%pid

capture request header Host len 32
capture request header User-Agent len 200
capture request header X-Unique-ID len 16
rspidel ^X-Powered-By:.*

default_backend application-backend

backend application-backend
balance leastconn
option httpclose
option forwardfor
option httpchk

http-check send-state
http-send-name-header Node-Name
#http-check expect status 200
#cookie JSESSIONID prefix

server test1 192.168.1.73:80
#server 10.0.1.102:80 cookie A check
user1973314
  • 131
  • 2
  • 3
  • 8

1 Answers1

2

To log the unique id you will need to create a custom logging format that uses the %ID tag. There's no need to use a "capture request header" to log that.

Rewriting your example above with a custom log format:

frontend http-in
    bind *:8080
    monitor-uri /haproxy-health
    unique-id-header X-Unique-ID
    unique-id-format %{+X}o\ %ci:%cp_%fi:%fp_%Ts_%rt:%pid

    capture request header Host len 32
    capture request header User-Agent len 200
    rspidel ^X-Powered-By:.*
    log-format %{+Q}r\ %ST\ "%CC"\ "%hr"\ "%CS"\ "%hs"\ %ID

With a config like that you'll get a log messages that looks something like this:

Sep 10 17:37:55 lb2 haproxy[28497]: "GET /favicon.ico HTTP/1.1" 200 "-" "{172.20.0.20:8999|Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36}" "-" "" AC140001:C1B8_AC140014:2327_55F1BFF3_0003:6F51

The last entry being the unique id.

You can see all the possibilities for logging at http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#8.2.4

joyofhex
  • 21
  • 2