Developer

Error tracking in the cloud with Raygun.io lets you focus on building apps

​Learn how Raygun.io simplifies application error tracking and notifications by seeing how to integrate it with an ASP.NET app.

cloud-computing-button-blue.jpg

The number of avenues and options available for building and scaling web applications is surprising, especially when I reflect on the same task that years ago would require you to build a server, find a host, and basically manage all aspects of the application.

These days you can focus on building the application while leveraging services for everything from web hosting to data analytics. A good example is Raygun.io, which handles tracking application errors and notifies you when errors occur. Let's take a closer look at what Raygun.io offers by integrating it with an existing ASP.NET application.

Error tracking in the cloud

The Raygun.io site promises a setup time of five minutes; it took approximately 20 minutes for an ASP.NET application, but that included the time needed to set up a trial account with the site. The Raygun.io service is not free; they have a rate structure depending on number of applications, errors, and so forth. However, you can take it for a spin with a 30-day free trial (no credit card needed), which is what I use in this article.

Once an account is set up, you are ready to integrate the service into your application. It supports the following platforms: .NET (including ASP.NET), Android, iOS, Java, JavaScript, Node.js, PHP, Python, and Ruby on Rails. The online documentation provides details on the service as well as integrating with your code.

Before diving into the code, let's discuss setup on the Raygun.io side. The service organizes your logging into applications. You define an application by name and the technology being used. Figure A shows the initial screen presented when adding a new application to your Raygun.io account. You assign a name along with notification (via email) options. Figure B is presented once the Create Application button is selected. Figure C loads when the technology is selected (ASP.NET in this case).

Every Raygun.io application you create has a unique Application API Key that is used in your code for identification. The api key will appear on the screen shown in Figure C (at the top and in the step #3 area). Note, they have been removed in the examples to avoid reuse. Once you have the key value, it is time to configure the actual code to use the server. My first interaction with the Raygun.io service was in ASP.NET, so I'll show this approach.

Figure A

raygunfiga080714.jpg

Creating a new Raygun.io application.

Figure B

raygunfigb080714.jpg

Specifying the platform for your Raygun.io application.

Figure C

raygunfigc080714.jpg

The final setup screen provides information on using the service.

Using the service in ASP.NET

The setup steps for the client or the code side are straightforward. These steps are spelled out each time a new application is created, as shown in Figure C. While my numbers do not directly correspond to their list, the following items provide the basics of using the service.

1. Install the Raygun.io package via NuGet in your application.

2. Add ConfigSections to your App.config (or Web.config for ASP.NET) for Raygun.io settings. In addition, the RaygunSettings element with the apikey attribute is added.

3. Choose whether you will use the service via code the global Application_Error event or add the HttpModule (called RaygunErrorModule) to the application via the system.web or system.webServer elements in the configuration file.

I used the service in the previously built NancyFX example that is hosted on Microsoft Azure. Figure D shows the NuGet Package Manager with Raygun.io package located (search for raygun4net) and installed. Once installed, you will see a reference to Mindscape.Raygun4Net package in the solution. The next step is configuring the application to use Raygun.io.

Figure D

raygunfigd080714.jpg

Locating and installing the Raygun.io NuGet package in Visual Studio.

The following listing has the complete web.config for the ASP.NET application using Raygun.io. The three areas added to incorporate Raygun.io are in bold; this includes the addition of the RaygunSettings section, the RaygunErrorModule element within the system.webServer element, and the apikey identified in the RaygunSettings element. With the web.config changes saved, the application is now configured to use Raygun.io. This sample application is hosted on Microsoft Azure, so I publish it once packages are installed and configuration changes saved.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="RaygunSettings" type="Mindscape.Raygun4Net.RaygunSettings, Mindscape.Raygun4Net" />
</configSections>
 <system.web>
 <compilation debug="true" targetFramework="4.5.1" />
<customErrors mode="Off" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
 <validation validateIntegratedModeConfiguration="false" />
<httpErrors existingResponse="PassThrough" />
<handlers>
<add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<modules>
<add name="RaygunErrorModule" type="Mindscape.Raygun4Net.RaygunHttpModule" />
</modules>
</system.webServer>
<RaygunSettings apikey="f0f0f0f0f0f0f0f0f0f0f0f0" />
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Processing errors

Once the application is configured, you will be notified of application errors via email (if configured), or you can visit the Raygun.io site to view application activity.

Figure E shows errors generated for this application. Notice that applications are categorized as Active, Resolved, Ignored, or Permanently Ignored. They are categorized when you drill into the individual errors as shown in Figure F; the dropdown list at the top right of the exception detail page allows you to appropriately mark it. In addition, the tabs shown at the bottom of Figure F allow you to drill into further error details, including the summary page displayed by default and Error Details, Request (details on HTTP request), and Raw Data (JSON view of the error data).

Figure E

raygunfige080714.jpg

Error activity recorded for the ASP.NET application.

Figure F

raygunfigf080714.jpg

Individual error details along with dropdown to categorize.

Another piece of the puzzle

With all of the cloud services available today, you have everything necessary to piece together an application once you have an idea. For example, you can choose to host on AWS (Raygun.io uses it) or Heroku with MongoLab for the backend database and process/analyze errors with a service like Raygun.io.

Raygun.io is not the only option with this type of service -- other options include Airbrake and Crashlytics -- but it is one that allows you to focus on building and maintaining code without the hassle of dealing with infrastructure (beyond managing cloud services).

About

Tony Patton has worn many hats over his 15+ years in the IT industry while witnessing many technologies come and go. He currently focuses on .NET and Web Development while trying to grasp the many facets of supporting such technologies in a productio...

2 comments
Eamon_Walsh1
Eamon_Walsh1

This is certainly a step up. Mongo has already set in motion some good features, but Raygun does add to its allure by partition of their error alerts, crash notifications etc. and db/ infrastructure management. For those who just seek an 'application module' to let them check their code and customize it, it is a great tool. Remains to be seen how well it helps keep track of issues while also integrating a back-up of affected data. Perhaps something like http://ibm.co/1qOBpOW? 

Editor's Picks