Menu
AWS X-Ray
Developer Guide

Creating Additional Subsegments

You can add subsegments to request segments with BeginSubsegment and EndSubsegment. Perform any work in the subsegment in a try block and use AddException to trace exceptions. Call EndSubsegment in a finally block to ensure that the subsegment is closed.

Example Controller.cs – Custom Subsegment

AWSXRayRecorder.Instance.BeginSubsegment("custom method"); try { DoWork(); } catch (Exception e) { AWSXRayRecorder.Instance.AddException(e); } finally { AWSXRayRecorder.Instance.EndSubsegment(); }

When you create a subsegment within a segment or another subsegment, the X-Ray SDK for .NET generates an ID for it and records the start time and end time.

Example Subsegment with Metadata

"subsegments": [{ "id": "6f1605cd8a07cb70", "start_time": 1.480305974194E9, "end_time": 1.4803059742E9, "name": "Custom subsegment for UserModel.saveUser function", "metadata": { "debug": { "test": "Metadata string from UserModel.saveUser" } },