Search code examples
c#azureazure-application-insightsazure-api-apps

How to add Values to custom dimension at runtime - Azure application insights


I'm trying to add my own custom dimension values for each API request in the azure app insights.

As per here, we can use ITelemetryInitializer interface to initialize and add our own custom dimension values. But while doing that we are simply hardcoding the values, but my values will change at runtime

For E.g this S.O is showed he added custom property "LoggedInUserName" under the Custom group of request properties, by hardcoding the value as DummyUser

But my values will get changed during the runtime. So how will I track that for each request?

If it's not possible to track at the request level. Can we track this at trace level?

Thanks in Advance,
Jay


Solution

  • For request-specific custom dimensions the recommendation is: 1) Populate needed data as Tags on Activity object 2) Add TelemetryInitializer which will copy Tags from Activity to custom dimensions

    For more details you can refer to this answer: https://stackoverflow.com/a/49392526/3646920