Add Tracking ID or Number to Unhandled Exceptions within Web API
PhilAI
Posted on
Aug 10 2017
This is a C# Web API using Framework 4.6.2.
We use the RaygunWebApiClient within our API, but we would like to supply a custom tracking ID that our consumers can use to help us locate their exact exception.
For example, our client makes a request to our Web API, an unhandled exception occurs, we respond with a Tracking ID and then we are able to attach that ID to the exception logged to Raygun.
Issue is the code that responds to the client is within an Exception Handler, but Raygun has already started processing the exception. Is there another mechanism we could use to attach a Tracking ID to a message sent to Raygun which we could provide to the user to supply to our Support team?
Jason Fauchelle
Raygun
Posted on
Aug 11 2017
Hi PhilAI
Take a look at the SendingMessage event. Here is the relevant documentation for web api: https://raygun.com/docs/languages/net/webapi#modify-cancel-message
The example above shows how to cancel a message, but instead of doing that, you can modify the RaygunMessage object in just about any way you like, such as attaching tags or custom data. For an exception tracking id, I'd recommend adding it as custom data. Make sure to include null checks when getting various properties of the RaygunMessage. Hopefully you have access to the tracking ID from this event handler.
An overload of that Attach method can allow the function to take an HttpRequestMessage if that helps.
Let us know if you have further questions about this.
-Jason Fauchelle