in PetAdoptions/cdk/pet_stack/resources/microservices/petsite/petsite/Controllers/HomeController.cs [137:191]
public async Task<IActionResult> Index(string selectedPetType, string selectedPetColor, string petid)
{
Console.WriteLine(
$"AWS_XRAY_DAEMON_ADDRESS:- {Environment.GetEnvironmentVariable("AWS_XRAY_DAEMON_ADDRESS")}");
AWSXRayRecorder.Instance.BeginSubsegment("Calling Search API");
AWSXRayRecorder.Instance.AddMetadata("PetType", selectedPetType);
AWSXRayRecorder.Instance.AddMetadata("PetId", petid);
AWSXRayRecorder.Instance.AddMetadata("PetColor", selectedPetColor);
Console.WriteLine(
$"[{AWSXRayRecorder.Instance.TraceContext.GetEntity().RootSegment.TraceId}]- Search string - PetType:{selectedPetType} PetColor:{selectedPetColor} PetId:{petid}");
// | SegmentId: [{AWSXRayRecorder.Instance.TraceContext.GetEntity().RootSegment.Id}
string result;
try
{
result = await GetPetDetails(selectedPetType, selectedPetColor, petid);
}
catch (Exception e)
{
AWSXRayRecorder.Instance.AddException(e);
throw e;
}
finally
{
AWSXRayRecorder.Instance.EndSubsegment();
}
var Pets = JsonSerializer.Deserialize<List<Pet>>(result);
var PetDetails = new PetDetails()
{
Pets = Pets,
Varieties = new Variety
{
PetTypes = _variety.PetTypes,
PetColors = _variety.PetColors,
SelectedPetColor = selectedPetColor,
SelectedPetType = selectedPetType
}
};
AWSXRayRecorder.Instance.AddMetadata("results", System.Text.Json.JsonSerializer.Serialize(PetDetails));
Console.WriteLine(
$" TraceId: [{AWSXRayRecorder.Instance.GetEntity().TraceId}] - {JsonSerializer.Serialize(PetDetails)}");
// Sets the metric value to the number of pets available for adoption at the moment
PetsWaitingForAdoption.Set(Pets.Where(pet => pet.availability == "yes").Count());
return View(PetDetails);
}