0

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'
ZakiMa
  • 5,637
  • 1
  • 24
  • 48
  • Not sure if and how it is possible using script. Anyway, I would advice you to not use scripting but a regular project. Much more (documented) options. Is there a reason you are using scripting? – Peter Bons Apr 17 '21 at 12:11
  • 1
    Yes, the goal is to provide a simple template to our customers. C# scripting gives more or less simple flow even for people not having deep expertise with development tools. – ZakiMa Apr 17 '21 at 21:41
  • Understood. What exactly would the processor do? Maybe there is another way to reach the same behavior. – Peter Bons Apr 18 '21 at 05:40
  • @PeterBons, Azure Function emits a RequestTelemetry item for every function execution. I would like to either adjust it or even replace it (for instance, emit AvailabilityTelemetry instead of RequestTelemetry using TelemetryProcessor). – ZakiMa Apr 19 '21 at 23:55

1 Answers1

0

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.

  • Sorry, not sure how it is related to the question above. There is documentation available which explains how to get a hold of TelemetryConfiguration instance through dependency injection for C# projects. The question was whether it is possible to do it in C# script. – ZakiMa Apr 19 '21 at 23:53