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.

IMPORTANT

If you aren't sure how to configure OTFP, contact support before making any changes.

Upload custom VCL

  1. Before uploading custom VCL, review the caveats of mixing and matching Fastly VCL with custom VCL.

  2. Add the following custom VCL to your Fastly VCL:

    1sub vcl_deliver {
    2 # Identify Request type
    3 if (req.url.ext ~ "m3u8|ts|aac|webvtt") {
    4 set resp.http.Otfp-Format = "HLS";
    5 } else if (req.url.ext ~ "mpd|m4s") {
    6 set resp.http.Otfp-Format = "DASH";
    7 } else {
    8 set resp.http.Otfp-Format = "OTHER";
    9 }
    10
    11 # Extract name-value pairs Otfp Info herder
    12 if (resp.http.X-Fastly-Otfp-Info) {
    13 set resp.http.Otfp-SS = regsub(resp.http.X-Fastly-Otfp-Info, ".*ss=(\S+).*", "\1");
    14 set resp.http.Otfp-SL = regsub(resp.http.X-Fastly-Otfp-Info, ".*sl=(\S+).*", "\1");
    15 set resp.http.Otfp-VL = regsub(resp.http.X-Fastly-Otfp-Info, ".*vl=(\S+).*", "\1");
    16
    17 # Resolution (rs name-value) not available for audio-only segments
    18 if (resp.http.X-Fastly-Otfp-Info ~ ".*rs=(\S+).*") {
    19 set resp.http.Otfp-RS = re.group.1;
    20 } else {
    21 set resp.http.Otfp-RS = "-";
    22 }
    23 }
    24#FASTLY deliver
    25
    26 return(deliver);
    27}

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. Log in to the Fastly web interface.
  2. From the Home page, select the appropriate service. You can use the search box to search by ID, name, or domain. You can also click Compute services or CDN services to access a list of services by type.
  3. Click Edit configuration and then select the option to clone the active version.
  4. Click Logging.
  5. In the list of logging endpoints, find the endpoint you enabled when setting up remote log streaming, then click Attach a condition.
  6. Fill out the Create a new condition window as follows:
    • In the Name field, enter a human-readable name for the condition.
    • In the Apply if field, enter resp.http.X-Fastly-Otfp-Info && !req.http.Fastly-FF.
  7. Click Save and apply to.

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:

  • ss - video segment start presentation time in seconds
  • sl - video segment duration in seconds
  • vl - video duration in seconds
  • rs - video track display resolution in pixels

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

Was this guide helpful?

Do not use this form to send sensitive information. If you need assistance, contact support. This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.