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

Custom Error Grouping for PHP With Raygun

DZone's Guide to

Custom Error Grouping for PHP With Raygun

Raygun Crash Reporting has released custom grouping for PHP. Let's see it in action!

· Web Dev Zone
Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

Intelligently grouping errors is one of Raygun Crash Reporting’s primary features.

However, we understand that sometimes you may need to be able to manually group your errors according to specific criteria.

For example, if you use Amazon Beanstalk, there could be many machines under one application but you may only find an error under a single machine. In this case, it becomes quite handy to be able to see exactly which machine is finding the error.

This is why Raygun has released custom grouping for PHP.

This means Raygun4PHP provider now has the ability to allow you to define your own grouping hash for PHP errors and exceptions before you send them.

(Raygun also provides custom error grouping for .NET exceptions, here’s how to start)

How Raygun Groups Errors

Raygun uses a group hash to determine which group the error should go into. Generally, the payload hits the Raygun servers, which runs a hashing algorithm over it and sorts it into the correct group. In most situations, this is an effective way to manage the volume of errors arriving into your 'Active' tab. The same error won’t keep sending notifications, and the error can be resolved quickly if it keeps occurring:

custom error grouping for PHP is Raygun's latest provider update

Errors land in your ‘Active’ tab already grouped by Raygun


However, there is the chance that Raygun’s hasher doesn’t group your error how you desire.

Custom Error Grouping for PHP

Step #1  Execute the SetGroupingKey method on the RaygunClient and attach a callback. Which will then give you Error details that Raygun4PHP has created.

Step #2  Send back the key you want to use for grouping that error. If you don’t set a grouping key, we use our normal hashing routine.

Here’s an Example:

$client = new \Raygun4php\RaygunClient($apiKey);

$client->SetGroupingKey(function($payload, $stackTrace) {

  // Group errors by hostname
  $hash = gethostname();

  // ClassName, File, and LineNumber which contained them
  foreach( $stackTrace as $trace ) {
    $hash .= $trace->ClassName . $trace->FileName . $trace->LineNumber;
  }

  return sha1( $hash );
});


This will set the custom grouping key for any Exception to be a hash of the hostname, plus the class name, file name, and line number of each item in the stack trace. Allowing you to see the individual errors on each machine, just like in the Amazon Beanstalk example above.

The grouping key you produce should be less than 100 characters. Although we don’t actually restrict you here, but if it’s longer than that we will SHA1 hash your key and use the results of that. It’s quite unlikely that this will produce duplicates, but it’s worth mentioning.

Recommended Use

We recommend that a custom hasher is the last resort when Raygun’s error grouping is unsuitable for the task at hand.

Need Help? 

Do you have any questions about custom error groups? Contact a team member or leave a comment.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:
crash ,servers ,beanstalk ,raygun ,error ,reporting

Published at DZone with permission of Freyja Spaven, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

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

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}