MindscapeHQ / serilog-sinks-raygun

A Serilog sink that writes events to Raygun
Apache License 2.0
11 stars 20 forks source link

Capture http request/response details #32

Closed QuantumNightmare closed 3 years ago

QuantumNightmare commented 3 years ago

As the branch name suggests, the focus for this PR was to capture HTTP request and response details and include them in the Raygun payloads where relevant. I did this because I noticed one of the options is "ignoredFormFieldNames" which is related to the HTTP request section of the Raygun payload, and yet this sink no longer captures these details.

The way I have added this support is by replacing the Send(message) call with a Send(exception) call. In order to maintain all the functionality that this Sink currently has, we attach an event handler to the SendingMessage event on the Raygun client. This event is fired whenever a message is about to be sent to Raygun, and provides the message payload model for reading and mutating. In the event handler, most of the logic will read the UserCustomData (which is set to be the log properties) and then use those values to add/update various other parts of the message model.

This worked out very smoothly, apart from the timestamp which I maintained by introducing a new property key. This gets set before sending the exception, then gets read and removed from the properties list in the SendingMessage event handler.

The result of this has regained support for capturing HTTP request/response details, but also unlocks other features provided by Raygun4Net:

Additionally, this PR resolves https://github.com/serilog/serilog-sinks-raygun/issues/31 by removing the null/whitespace check on the api key.