Announcing support for automatic C++ exception tracking

| 3 min. (488 words)

Today we’d like to highlight a currently undocumented feature of Raygun that is available for use – C++ exception tracking!

While we currently don’t have an official provider for the language, the Raygun back-end does feature support for automatic grouping of C++ exceptions. Due to platform, compiler and implementation concerns only the raw entries API endpoint is supported, but this allows you to POST to Raygun with the exception data in a manner that best suits your application.

What you get with C++ exception tracking

Just like the other languages we support, instances of C++ exceptions are grouped according to their actual code path, which doesn’t use potentially instance-specific data to construct the group. For instance, differing line numbers and paths are ignored, and the message can contain random user data which will be ignored so similar exceptions can be grouped together.

This stops you from drowning in log files by having your team focusing on individual bugs while ignoring data that isn’t relevant.

Creating the stack/back trace

One known good implementation for walking the callstack to reconstruct the stack trace with Visual C++ environments is StackWalker. A variety of other approaches for systems with GCC, LLVM and others are detailed here. In particular look into backtrace() from execinfo.h, then demangle the output with abi::__cxa_demangle() and sscanf() or dladdr().

POSTing your C++ exception to Raygun

If the resulting JSON payload contains the following client name the included C++ exception will be automatically grouped according to its code path:

"client": {
  "name": "raygun4cpp",
  "version": "version_string",
  "clientUrl": "url_string"
}

The version and URL can be of your choosing. That client value should be placed beneath the top-level details object. As for the rest of the payload, it should follow the structure of the entries API as outlined in the docs. After your application has constructed the stack trace for a caught exception (see below), it should include the class name and message as strings, and an array of stack trace frames containing the line number, class name, file name and method name. You can then implement other supported features if you desire, such as environment data, user tracking, custom data or tags. That JSON payload should then be POSTed to https://api.raygun.com/entries, with an X-ApiKey header key set to your key (available from the Raygun dashboard).

If you would like a complete example JSON payload you can contact us, or you can grab one of our other providers (for instance the C#, Java or JavaScript providers), then throw a test exception to see how they manage the sending.

Interested? We’re here to help

We’d like to hear about your experiences if you are implementing this in your code. The automatic grouping logic for C++ is ready to go on our back-end, so have at it! When you’re ready to send exceptions to Raygun start your 30-day free trial here. And if you have any questions or comments, let us know below.