Collecting OTFP metrics

Fastly allows you to collect and process On-the-Fly Packaging (OTFP) service metrics for analysis using a combination of custom VCL updates and specific log streaming settings. Once you’ve set up OTFP metrics collection through remote log streaming you can use any of a number of third-party and open source software options to aggregate your logging data for visualization and further analysis.

Upload custom VCL

  1. If you have not already done so, request the ability to upload custom VCL code be enabled for your account.
  2. Review the caveats of mixing and matching Fastly VCL with custom VCL.
  3. Add the following custom VCL to your Fastly VCL:

    sub vcl_deliver {
      # Identify Request type
      if (req.url.ext ~ "m3u8|ts|aac|webvtt") {
        set resp.http.Otfp-Format = "HLS";
      } else if (req.url.ext ~ "mpd|m4s") {
        set resp.http.Otfp-Format = "DASH";
      } else {
        set resp.http.Otfp-Format = "OTHER";
      # Extract name-value pairs Otfp Info herder
      if (resp.http.X-Fastly-Otfp-Info) {
        set resp.http.Otfp-SS = regsub(resp.http.X-Fastly-Otfp-Info, ".*ss=(\S+).*", "\1");
        set resp.http.Otfp-SL = regsub(resp.http.X-Fastly-Otfp-Info, ".*sl=(\S+).*", "\1");
        set resp.http.Otfp-VL = regsub(resp.http.X-Fastly-Otfp-Info, ".*vl=(\S+).*", "\1");
        # Resolution (rs name-value) not available for audio-only segments
        if (resp.http.X-Fastly-Otfp-Info ~ ".*rs=(\S+).*") {
          set resp.http.Otfp-RS = re.group.1;
        } else {
          set resp.http.Otfp-RS = "-";
    #FASTLY deliver

Create a logging endpoint

Follow the instructions to set up remote log streaming for your account and when creating your specific logging endpoint, set the Format String field to the following:

%h now.sec %r %>s %b resp.http.Otfp-Format resp.http.Otfp-SS resp.http.Otfp-SL resp.http.Otfp-VL resp.http.Otfp-RS

Control log file timing with a logging endpoint condition

To avoid excess log files, consider attaching a condition to the logging endpoint so logs are only sent when video segments are requested so that logging specifically exclude those files sent from Fastly’s Origin Shield.

  1. Click the gear icon next to the logging service you enabled when setting up remote log streaming and select Conditions. The New Condition window appears.
  2. Fill out the New Condition window as follows:
    • In the Name field, type a human-readable name for the condition.
    • In the Apply If field, type resp.http.X-Fastly-Otfp-Info && !req.http.Fastly-FF.
    • Leave the default value set in the Priority field.
  3. Click Create.

Analyze logging data

In addition to any Varnish variable, and a variety of Fastly’s extensions to VCL, log files include the following video-specific fields:

You can use these fields to run queries for analysis and use what you discover to refine your video delivery settings.

Additional resources:

Back to Top