Access to TelemetryConfiguration object from C# script (csx) in Azure Function

348 views Asked by At

I need to inject a TelemetryProcessor into existing TelemetryConfiguration (Application Insights) to modify default Azure Function behavior.

There are examples how to do it through Dependency Injection for c# projects. I wonder whether there is a way to access it from C# script (csx).

It looks like it is possible to access through TelemetryConfiguration.Active but compiler gives a warning that it is obsolete:

2021-04-17T01:38:35.988 [Warning] run.csx(28,15): warning CS0618: 'TelemetryConfiguration.Active' is obsolete: 'We do not recommend using TelemetryConfiguration.Active on .NET Core. See https://github.com/microsoft/ApplicationInsights-dotnet/issues/1152 for more details'
1

There are 1 answers

1
JayaChatterjee-MSFT On

I believe this might help here : https://github.com/microsoft/ApplicationInsights-dotnet/issues/1222#issuecomment-536034393

Internal team was working on the documentation too : https://github.com/microsoft/ApplicationInsights-dotnet/issues/1336

Re-posting the explanation here :

Activity philosophy is not to throw but swallow errors as typically it's not your application that causes them but different libraries and you have no control over them. Throwing in many cases would break your app without giving you a way to fix it. We can argue about how good or bad it is, but this is the choice that has been made and cannot be changed. Activity has a fluid interface that allows building (starting) it and then working with running activity. After you start Activity, you cannot change certain things that were used to build/start it. I guess what it lacks is good documentation to explain how and why. Here you are dealing with ApplicationInsights API layer and we suggest that you always use this layer when you can.