Skip to content

Instantly share code, notes, and snippets.

@jelder
Created July 28, 2010 12:10
Show Gist options
  • Save jelder/494265 to your computer and use it in GitHub Desktop.
Save jelder/494265 to your computer and use it in GitHub Desktop.
Add X-Request-Start header so we can track queue times in New Relic RPM beginning at Varnish.
/*
* Add X-Request-Start header so we can track queue times in New Relic RPM beginning at Varnish.
*
*/
#include <sys/time.h>
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(sp, HDR_REQ, "\020X-Request-Start:", start, vrt_magic_string_end);
@Kalyse
Copy link

Kalyse commented Jan 20, 2013

If you are using Varnish 3.0 you need to place the C includes outside of the VCL blocks.


........
C{
    #include <syslog.h>
    #include <sys/time.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
}C

sub vcl_recv {

    C{
        struct timeval detail_time;
        gettimeofday(&detail_time,NULL);
        char start[20];
        sprintf(start, "%lu%06lu", detail_time.tv_sec, detail_time.tv_usec);
        VRT_SetHdr(sp, HDR_REQ, "\020X-Request-Start:", start, vrt_magic_string_end);
    }C

........

sub vcl_deliver {
    set resp.http.X-ID = req.xid;
}
.......

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