An Azure service that provides an event-driven serverless compute platform.
I reproduced this to see exactly what reaches Application Insights. In the .NET isolated worker, two things decide whether your scope values show up in customDimensions.
1. The log has to reach Application Insights at all
With AddApplicationInsightsTelemetryWorkerService(), the Application Insights logger only sends Warning and above by default. In my test, a LogInformation call inside a scope sent nothing at all, while LogWarning arrived with the scope values. The current func init template registers Application Insights but doesn't remove this rule, so new apps hit it straight away.
Remove the default rule in Program.cs:
var
2. Pass the scope as key/value pairs
What you pass to BeginScope decides how it's stored. These are the results from my test:
Scope passed to BeginScope |
What appears in customDimensions |
|---|---|
Dictionary<string, object> |
Each key as its own field: OrderId, CustomerId |
Dictionary<string, object> |
Each key as its own field: OrderId, CustomerId |
Message template: BeginScope("Processing order {OrderId}", orderId) |
OrderId as its own field |
Plain string: BeginScope("OrderId=A-1001") |
One Scope field containing the text |
Anonymous object: BeginScope(new { OrderId = "A-1001" }) |
One Scope field containing the text |
So use a dictionary:
using
Then check in Application Insights:
traces
| where timestamp > ago(30m)
| where message == "Order received"
| project timestamp, message, customDimensions
You should see OrderId and CustomerId as separate entries in customDimensions.
If your app uses the in-process model (FUNCTIONS_WORKER_RUNTIME = dotnet), the logs go through the Functions host instead, and the keys may appear with a prop__ prefix, as Tejaswini mentioned.