AWS for M&E Blog

Working with AWS Elemental MediaTailor logs and metrics

AWS Elemental MediaTailor is a content personalization and monetization service that allows customers to implement stitched server-side ad insertion for streaming video while maintaining high quality of service. It uses dynamic transcoding to reduce storage requirements and ensure that video seamlessly transitions between advertising and primary content during playback. AWS Elemental MediaTailor manipulates the HTTP Live Streaming (HLS) manifest to include URLs for the appropriate ads.

Like most AWS services, you can monitor AWS Elemental MediaTailor for performance via Amazon CloudWatch. To get started, you will first need to use AWS Identity and Access Management (IAM) to create a role that explicitly allows AWS Elemental MediaTailor to access Amazon CloudWatch. This documentation walks you through how to do just that. Once that’s done, you should be able to see AWS Elemental MediaTailor logs and metrics in your account through the CloudWatch console.

In the CloudWatch console, you’ll see that MediaTailor supplies logging information under the following log groups:

  • MediaTailor/AdDecisionServerInteractions records activities relating to interactions between AWS Elemental MediaTailor and an ad decision server (ADS). Examples of these activities include requesting VAST response, beaconing messages back to ADS, and filling ad avails.
  • MediaTailor/ManifestService records activities relating to manifest retrieval (typically from an origin server) and processing. If there are no errors recorded, you may not see this log group at all as it will only get created if there are log data being written out.
  • MediaTailor/TranscodeService records status relating to ad transcoding like ads not being ready at the time of the request or errors during the transcoding itself.[MOU1]

Under the log groups are log stream names that hold the actual logs. Logs are written to log stream names with the prefix matching the configuration name given to the AWS Elemental MediaTailor configuration. Although the logs are available via the console, you might find yourself wanting to extract the logs programmatically so you can embed the information to a dashboard, or do further analysis on your logs. You can do this by using either the AWS CLI or the SDK libraries.

Here, we provide you code snippets on how to pull logs from the AdDecisionServerInteractions log group pertaining to a specific AWS Elemental MediaTailor configuration using the Boto 3 library. It is usually best to query CloudWatch for the stream names available for the given AWS Elemental MediaTailor configuration first, then use the list of stream names to pull the actual logs. This way, the log search is done only on the applicable streams.

import boto3

MediaTailorConfigName = "MyEMTConfigName"
logGroupName = "MediaTailor/AdDecisionServerInteractions"
client = boto3.client('logs')
   
#get the log stream names associated with the log group name we want to query
log_streams = client.describe_log_streams(
                logGroupName=logGroupName, 
                logStreamNamePrefix=MediaTailorConfigName
              )            

What describe_log_streams returns is a dictionary of logStreams, which you can iterate over to make a list of the logStreamNames. You pass on this list when you make the call to extract the logs.

for stream in log_streams['logStreams']:
            logStreamNamesList.append(stream['logStreamName'])
            
loginfo = client.filter_log_events(
            logGroupName=logGroupName,
            logStreamNames=logStreamNamesList
           )

You can further limit the logs returned in loginfo by providing a filterPattern to the filter_log_events call if you only want to retrieve specific event types. For example, if you are only interested in seeing tracking beacons being sent back to the ADS for reporting, then you can run the following instead:

loginfo = client.filter_log_events(
            logGroupName=logGroupName,
            logStreamNames=logStreamNamesList,
            filterPattern='{($.eventType = 'BEACON_FIRED')}'
           )

AWS Elemental MediaTailor metrics are provided in the “AWS/MediaTailor” namespace. Metrics included by default are described in this document. As with the logs, you can query for metrics programmatically using AWS CLI or the SDK libraries. In the code snippets below, we once again use the Boto 3 library to query for a specific metric relating to the ADS’s ad fill rate, AdDecisionServer.FillRate. This particular metric gives you an idea on how well the ADS is filling the request for ads. If the ADS never fails to return an ad when a request is made, and the duration of ad returned closely matches the ad duration requested, then the higher (better) the fill rate.

The example below queries for the average ADS fill rate in the last 60 minutes with a period of every 5 minutes (period below is given in seconds).

import boto3

client = boto3.client('cloudwatch')

MediaTailorConfigName = "MyEMTConfigName"

#1 hour ago represented in timedelta
delta = datetime.timedelta(minutes=60)
#endtime is now
end = datetime.datetime.now()
#starttime is delta min ago
start = end - delta

result = client.get_metric_statistics(
            Namespace = 'AWS/MediaTailor',
            MetricName = 'AdDecisionServer.FillRate',
            Dimensions = [
                {
                    'Name': 'ConfigurationName',
                    'Value': MediaTailorConfigName
                }
            ],
            StartTime = start,
            EndTime = end,
            Period = 600, 
            Statistics = ['Average']
         )

This post gave high level examples on how to programmatically query CloudWatch for default logs and metrics. Data gathered can be used to perform further analysis on logs, check for errors, and even create custom metrics by using specific information included in the log details. Metrics information can be graphed and possibly embedded to a dashboard in order to assess not just AWS Elemental MediaTailor performance, but ADS behavior as well.

References: