Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

An Inside Look at Microsoft Azure WebJobs

DZone's Guide to

An Inside Look at Microsoft Azure WebJobs

Learn all about simplifying scheduled tasks and processing jobs with Azure WebJobs.

· Performance Zone
Free Resource

Discover 50 of the latest mobile performance statistics with the Ultimate Guide to Digital Experience Monitoring, brought to you in partnership with Catchpoint.

Scheduled tasks, batches, and small processing jobs have historically been convoluted to build, run, and monitor. Microsoft Azure WebJobs tries to drastically simplify this for developers: They are simply background jobs that can process continuously or on a schedule.

Free and Simple

Free and incredibly simple to create and use, Azure WebJobs are one of the .NET agent team’s favorite bits of technology on the Microsoft Azure stack. For developers, some of the most delightful aspects of WebJobs are the dashboards and invocation features available right out of the box!

The WebJobs dashboards can be accessed through the kudu site associated with your WebJobs host site:

https://[your-host].scm.azurewebsites.net/azurejobs/#/jobs

We wanted to monitor our WebJobs to better understand what they were doing. We wanted to find out, for example, if there were any issues or errors and learn what things might need refactoring to make processing our queues more efficient.

So we instrumented the things that were important to us using the New Relic .NET agent. (See the supporting code on GitHub.)

How to Do What We Did

1. Add the New Relic Site Extension to your host site: See the docs under “Install using the Site Extension from the SCM site.”

site_extensions

2. Get your license key (browse to https://rpm.newrelic.com/accounts/[accountId] after logging in—the license key will appear on the right side).

screen account settings license key

3. In the app.config of the WebJob add the following appsetting:

<configuration> 
  <appSettings> 
    <add key="NewRelic.AppName" value="[replace_with_the_name_you_want_reported_to_new_relic]" /> 
    <add key="NewRelic.AgentEnabled" value="true" /> 
    <add key="NewRelic.LicenseKey" value="[replace_with_your_key]" /> 
  </appSettings> 
</configuration>

4. Add some instrumentation (for example, to help the agent look for what you feel is important to monitor).

5. In the WebJob, add a folder and file: newrelic\extensions[someuniquename].xml

6. Make sure its Build action is Content.

7. In the file, add your instrumentation.

For instance, let’s say your function.cs has:

namespace WebJobs.Journals
{
  public class Functions
  {         
     public static void JournalOperations(parms...)
     {             
        new JobRunHandler<JobMessage>(parms...)                 
          .Run(parms..);
     }     
  } 
}

The content in the XML instrumentation file will look like this:

<?xml version="1.0" encoding="utf-8"?> 
<extension xmlns="urn:newrelic-extension">   
  <instrumentation>     
    <tracerFactory name="NewRelic.Agent.Core.Tracer.Factories.BackgroundThreadTracerFactory">
      <match assemblyName="WebJobs.Journals" className="WebJobs.Journals.Functions">
        <exactMethodMatcher methodName="JournalOperations" />
      </match>
    </tracerFactory>   
  </instrumentation>
</extension>

8. Finally, restart your host site.

We have now given ourselves X-ray vision into our WebJobs! This allows developers to better understand and tune their applications while providing the visibility to operations to make sure our WebJobs are healthy and scaling appropriately. You can get more information on how to do this for yourself and try it today by heading out to GitHub and getting the code.

Is your APM strategy broken? This ebook explores the latest in Gartner research to help you learn how to close the end-user experience gap in APM, brought to you in partnership with Catchpoint.

Topics:
performance ,cloud ,azure ,.net ,webjobs

Published at DZone with permission of Nick Floyd, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}