I have an Azure Function (v2) where data is passed in as JSON via the HTTP body. I want to log some of this JSON data in Application Insights, using the standard Trace and Request events.
What I've tried so far:
- Use a custom
ITelemetryInitializerwhich parses the body and adds properties toISupportProperties.Properties. This has 2 disadvantages though: the body is read and parsed multiple times for each request (once in my Function, and multiple times in the telemetry initializer), and sometimes accessing the body throws an exception because it has been disposed (probably it goes out of scope at the end of the Function call). - Use an
TelemetryClientinside my Function. But this client doesn't seem to have an appropriate property to set:TelemetryClient.Context.GlobalPropertiesis meant for global properties, and not for request-scoped properties;TelemetryClient.Context.Propertiesis obsolete, and I don't see how I can use the recommended replacementISupportProperties.Propertiesthere.
Ideally I want to use the data which is parsed inside my Function, and use that data to initialize the telemetry data.