I have a function app written in C# and deployed on Azure. In order to achieve correlation, I want to add some Custom Properties into the default RequestTelemetry of the Azure Function:
My function looks like as follow:
[FunctionName("Upload")]
[StorageAccount("AzureWebJobsStorage")]
public static async Task<IActionResult> Upload(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "upload/{name}")] HttpRequest req,
string name,
ILogger log,
ExecutionContext context)
{
var requestTelemetry = req.HttpContext?.Features.Get<RequestTelemetry>();
....
return new OkObjectResult(name + "Uploaded successfully.");
}
According to my research, most people suggest using following code:
requestTelemetry.Context.GlobalProperties.Add("someproperty", "123");
or
// Deprecated
requestTelemetry.Context.Properties.Add("someproperty", "123");
But it doesn't work.
So I wonder if it is even possible to modify the Custom Properties of the default RequestTelemetry in Azure Function(V3). Does anyone have other tips about how to achieve this?