I Take it Back! Use Windows Azure Diagnostics

October 13, 2013 — 7 Comments

computer-diagnostics-icon I used to create my own logging mechanisms for my Windows Azure Cloud Services. For a while this was the perfect solution to my requirements. But It had a down side, it required cleanup routines and a bit of maintenance.

In the recent months I changed my mind about Windows Azure Diagnostics and if you’re not too adventurous and don’t need your logs available every 30 seconds, I strongly recommend using them. They’ve come such a long way since the first versions that I’m now willing to wait the full minute for my application logs to get persisted to table storage.

The issues I had with Windows Azure Diagnostics were because of my ignorance and half because of irritating issues that used to exist.

Gaurav Mantri wrote an excellent blog post about an effective way of fetching diagnostics data from Windows Azure Diagnostics Table.  In his post, Gaurav mentions that the table’s PartitionKey is UTC time ticks rounded to the minute. This is actually really practical! Because it means that we can query for multiple time spans in parallel.

Get Windows Azure Diagnostics Cloud Table Query

Using code from my post about querying over Windows Azure Table Storage Service I created the following example to demonstrate how to query Windows Azure Diagnostics using UTC ticks as the PartitionKey.

public class GetWindowsAzureDiagnostics<TEntity> :
    CloudTableQuery<TEntity>
    where TEntity : ITableEntity, new()
{
    private readonly string tableStartPartition;

    private readonly string cacheKey;
    private readonly string tableEndPartition;

    public GetWindowsAzureDiagnostics(DateTime start, DateTime end)
    {
        tableStartPartition = "0" + start.ToUniversalTime().Ticks;
        tableEndPartition = "0" + end.ToUniversalTime().Ticks;

        var queryCacheHint = "GetWindowsAzureDiagnostics"
                                + tableStartPartition
                                + tableEndPartition;

        cacheKey = queryCacheHint;
    }

    public override Task<ICollection<TEntity>> Execute(CloudTable model)
    {
        if (model == null)
            throw new ArgumentNullException("model");

        return Task.Run(() =>
        {
            var condition = MakePartitionKeyCondition();

            var tableQuery = new TableQuery<TEntity>();

            tableQuery = tableQuery.Where(condition);

            return (ICollection<TEntity>)model.ExecuteQuery(tableQuery).ToList();
        });
    }

    public override string GenerateCacheKey(CloudTable model)
    {
        return cacheKey;
    }

    private string MakePartitionKeyCondition()
    {
        var startTicks = tableStartPartition.ToUpperInvariant();
        var partitionStarts = TableQuery.GenerateFilterCondition("PartitionKey",
            QueryComparisons.GreaterThanOrEqual,
            startTicks);

        var endTicks = tableEndPartition.ToUpperInvariant();
        var partitionEnds = TableQuery.GenerateFilterCondition("PartitionKey",
            QueryComparisons.LessThanOrEqual,
            endTicks);

        return TableQuery.CombineFilters(partitionStarts, TableOperators.And, partitionEnds);
    }
}

Using the GetWindowsAzureDiagnostics query

public async Task<ICollection<DynamicTableEntity>> GetDiagnostics()
{
    TimeSpan oneHour = TimeSpan.FromHours(1);
    DateTime start = DateTime.UtcNow.Subtract(oneHour);

    var query = new GetWindowsAzureDiagnostics<DynamicTableEntity>(start, DateTime.UtcNow);

    return await TableStorageReader.Table("WADLogsTable").Execute(query);
}

Setting Up Windows Azure Diagnostics Configurations

From the Solution Explorer right click on the role’s definition located in the Clod Project.

update-diagnostics-001

Then select Properties.

update-diagnostics-01

Enable Diagnostics and specify a storage account connection string. Be sure to use a separate account from you application’s production storage account. Each storage account has a target performance of 20,000 transactions per second, therefore using a different storage account will not penalize your application’s performance.

Click on the Edit button

update-diagnostics-2   

Use this window to configure the application’s diagnostics.

Updating Windows Azure Diagnostics from Visual Studio’s Server Explorer

From the Server Explorer, select the Cloud Service role open the context menu.

update-diagnostics-1

From this menu, select Update Diagnostics Settings…

update-diagnostics-2

From this menu, you will be able to modify the current Windows Azure Diagnostics configurations. Clicking on Ok will update the role instances on Windows Azure with the new settings.

Next Steps

Once you’ve gathered Windows Azure Diagnostics for a little while, you will probably want to have a look. To accomplish this you have a couple options like third party tools. The Azure Management Studio can help you browse the Windows Azure Diagnostics data. On the other hand, if you need something more custom, you can use a method similar to the table storage query from this blog post. I usually query storage directly because I haven’t come across the perfect tool.

How do you work with Windows Azure Diagnostics data?

7 responses to I Take it Back! Use Windows Azure Diagnostics

  1. 

    I’m thinking of injecting Semantic Logging App Block. So all my app info will be structured. Then I’m going to create my custom view of all the data which should be easy to do.

    Like

Trackbacks and Pingbacks:

  1. Windows Azure - October 25, 2013

    Windows Azure Community News Roundup #74

    Welcome to the latest edition of our weekly roundup of the latest community-driven news, content and

    Like

  2. Windows Azure Community News Roundup #74 | The Right Tool Kit For Your Home Based Business - October 25, 2013

    […] Take it Back! Use Windows Azure Diagnostics (posted October 13th) […]

    Like

  3. Windows Azure Community News Roundup #74 - Windows Azure Blog - October 25, 2013

    […] Take it Back! Use Windows Azure Diagnostics (posted October 13th) […]

    Like

  4. 微软云计算: Windows Azure 中文博客 - October 29, 2013

    Windows Azure 社区新闻综述(#74 版)

    欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻、内容和对话。以下是本周的亮点。 文章、视频和博客文章 Azure CDN:吸取的宝贵经验

    Like

  5. Fixing the Microsoft.ApplicationServer.Caching.ConfigStoreException | Alexandre Brisebois - April 7, 2014

    […] Emulator. As you can imagine, I was completely baffled by all this… So I decided to check if Windows Azure Diagnostics was able to log anything. Fortunately, I was able to get two exceptions. (The exceptions were found […]

    Liked by 1 person

  6. A Quick Reference to Azure Diagnostics - The Activity Designer - Site Home - MSDN Blogs - May 28, 2014

    […] So: here is the schema as mainly derived from the internet… (references: http://stackoverflow.com/questions/5737343/how-to-filter-azure-logs-or-wcf-data-services-filters-for-dummies http://blog.yaplex.com/azure/windows-azure-logging/ http://gauravmantri.com/2012/02/17/effective-way-of-fetching-diagnostics-data-from-windows-azure-diagnostics-table-hint-use-partitionkey/ http://alexandrebrisebois.wordpress.com/2013/10/13/i-take-it-back-use-windows-azure-diagnostics/ […]

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s