How can I log background operations with Amazon X-Ray?
I am not seeing any errors, and also I am not seeing any data logged.
I am using dotnet core SDK but I guess solution will be similar with any other SDK.
The solution is to use AWSXRayRecorderBuilder class, like this:
var xRayTracing = new AWSXRayRecorderBuilder()
.WithContextMissingStrategy(Amazon.XRay.Recorder.Core.Strategies.ContextMissingStrategy.LOG_ERROR)
.WithTraceContext(new AsyncLocalContextContainer())
.Build();
....
You may also consider to fill HttmlInformation so it will be visible on Races list view in AWS Console:
var requestInformation = new Dictionary<string, object>
{
["url"] = "BackgroundProcessor",
["method"] = message.State
};
xRayTracing.AddHttpInformation("request", requestInformation);
and an actual logging could be wrapped in try/catch/finally:
try
{
// some actions here
}
catch (Exception ex)
{
xRayTracing.AddException(ex);
throw;
}
finally {
xRayTracing.EndSegment();
}