To record exceptions handled by a try-catch block, use RevDeBugAPI.Snapshot.RecordException and pass the exception object as a parameter. For example:
try {var product =newProduct();product.convertData(dataFile); }catch (Exception e){ // The exception will be recorded by RevDeBugRevDeBugAPI.Snapshot.RecordException(e); }
The recorded snapshot of code execution that led to the exception will be stored on a Recording Server and visible on the RevDeBug DevOps Monitoring dashboard in the same manner unhandled exceptions are.
Recordings of complex objects
To record inside an object of any class use RevDeBugAPI.RecordObject(object). This function records the interior of the object at a given moment of the program operation.
var product =newProduct();product.convertData(dataFile);// The object will be recorded by RevDeBugRevDeBugAPI.RecordObject(product);
Using the RecordSnapshot function
RevDeBug offers the possibility to create code recordings even when there is no unexpected exception. To use the function of creating snapshots, you should use the RevDeBugAPI.Snapshot.RecordSnapshot(RecordingName) function anywhere in the program code. The place in the code where we used the snapshot function will be the end of the recording.
var product =newProduct();product.convertData(dataFile);// The above states will be recordedRevDeBugAPI.Snapshot.RecordSnapshot("Recording");
How to add RevDeBug Trace ID to your logs
To use RevDeBug API in your ASP.NET Core project you need to add IRevDeBugTraceInfoAccessor to IOC of your controller or middleware and then simply call method GetTraceId()
Example ExceptionMiddleware.cs could look like this:
To add custom tagging to your trace span, you need to add the following changes to your endpoints, please replace TagName and TagValue with your custom tag:
usingSkyApm.Tracing;namespaceSample.Controllers{private IEntrySegmentContextAccessor _entrySegmentContextAccessor;public SampleController(SampleContext sampleContext, IEntrySegmentContextAccessor entrySegmentContextAccessor) { // Your code here _entrySegmentContextAccessor = entrySegmentContextAccessor; }publicSampleResultEdit(string id) {var segmentContext =_entrySegmentContextAccessor.Context;segmentContext.Span.AddTag("TagName","TagValue"); // Your code here }}