Skip to content

Instantly share code, notes, and snippets.

@felixbuenemann
Last active February 2, 2017 10:44
Show Gist options
  • Save felixbuenemann/bce1fc848da498ffec6d to your computer and use it in GitHub Desktop.
Save felixbuenemann/bce1fc848da498ffec6d to your computer and use it in GitHub Desktop.
Varnish 4 X-Request-Start Header for New Relic Queue Time Reporting
# To allow inline-C in VCL start varnishd with -p vcc_allow_inline_c=on
C{
#include <sys/time.h>
#include <stdio.h>
static const struct gethdr_s VGC_HDR_REQ_reqstart = { HDR_REQ, "\020X-Request-Start:" };
}C
sub vcl_recv {
# Add X-Request-Start header for New Relic queue time analytics
C{
struct timeval detail_time;
gettimeofday(&detail_time, NULL);
char start[20];
sprintf(start, "t=%lu%06lu", detail_time.tv_sec, detail_time.tv_usec);
VRT_SetHdr(ctx, &VGC_HDR_REQ_reqstart, start, vrt_magic_string_end);
}C
}
@felixbuenemann
Copy link
Author

Add X-Request-Start Header in Varnish 4.x

Based on Varnish 3.x snippet from Tracking request queue time on New Relic RPM with Varnish comment by Disqus user Marcelo IH.

To allow inline-C in the VCL start Varnish with: varnishd -p vcc_allow_inline_c=on

You can check if it works by looking at: varnishtop -I ReqHeader:X-Request-Start

@wirtsi
Copy link

wirtsi commented Feb 2, 2017

Nice, thnx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment