Closed scott-lin closed 4 years ago
We were facing same issue for version 2.0.12961.0 and issue got resolved after updating default host.json
Before- { "version": "2.0", "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[1.*, 2.0.0)" } }
Working- { "version": "2.0" }
Thanks for the info. Unfortunately, my host file from the terminal dump above shows I'm using the same host.json content { "version": "2.0" }
.
On 1/22 this began affecting one of my functions running on a Consumption Plan host (V2 functions on .Net Core 2.2). I've been unable to resolve it by upgrading/downgrading Microsoft.ApplicationInsights. Kind of at my wits' end at this point...
Ultimately I had to work around this by creating a working TelemetryClient
in my extension of Microsoft.Azure.Functions.Extensions.DependencyInjection.FunctionsStartup
and injecting that.
Update: Works in Azure but not using Azure Functions Core Tools (2.7.1948 Commit hash: 29a0626ded3ae99c4111f66763f27bb9fb564103)
Function Runtime Version: 2.0.12888.0
@ankitkumarr, are you able to help here?
This is blocking release of our functions because we will not have any telemetry on them, which is a no-go. Running locally and in a Consumption plan in Azure are both not working with the issue called out.
Does not work on function runtime 3.0 either. This is really blocking us.
I apologize for the delay here, I was away for a bit. I will see if I can repro this on my end.
@scott-lin, do you use Startup
(FunctionsStartup
) to register TelemetryConfiguration
? If so, would you mind sharing a full repro with us?
Additionally, is this a new issue you are seeing in recent releases, or has this never worked?
cc: @brettsam, are you the right person to help with this (Application Insights + DI)?
I do not use a Startup
to register TelemetryConfiguration
. My original repro steps should be complete. This has never worked for me.
I'm led to believe a custom Startup
isn't necessary because of these docs.microsoft.com articles:
Specifically, in the latter article, the "Warning" in the section I linked to says,
Do not register your own TelemetryConfiguration or TelemetryClient if you are using the built-in Application Insights functionality.
These docs lead me to believe creating a function with the following aspects will result in a TelemetryConfiguration
instance to be dependency injected into my function's constructor:
Microsoft.ApplicationInsights
public MyFunction( TelemetryConfiguration telemetryConfiguration ) { ... }
APPINSIGHTS_INSTRUMENTATIONKEY
is present at runtimeI believe there's two issues you're running into but we should be able to get you running:
<SkipFunctionsDepsCopy>true</SkipFunctionsDepsCopy>
to your project file. This will prevent a deps.json file from being deployed and redirecting the App Insights reference.Make sure to rebuild or fully clean as the deps.json file may hang around if you don't.
The good news is that both of these restrictions will go away soon. This PR has fixed the issue (I just did some testing again to maks sure): https://github.com/Azure/azure-functions-host/pull/5551. You can see that for some other issues that are also impacted by this.
Thanks @brettsam, I was able to repro the behavior @scott-lin was experiencing. With your suggestions, I was able to fix the issue for now.
@scott-lin, please let us know if that works for you in the meanwhile. Sounds like we'll have a proper fix rolling out soon.
I confirmed Brett's workaround works.
Thanks for confirming. Will close this issue as the PR above fixes it and it'll be in our next release.
I am trying to run my Azure Function locally in Visual Studio 2019. I am relying on AppInsights + dependency injection to get an instance of
TelemetryConfiguration
, so I can construct aTelementryClient
for logging.When I run my function locally, I run into this error,
I tried the suggestions in related issues (#4682 and https://github.com/MicrosoftDocs/azure-docs/issues/35181), however, I had no luck. Namely, I tried installing downgraded versions of AppInsights nuget package. See repro steps for full details.
Edit: I tried running in Azure instead of just locally, and it fails there as well.
Investigative information
Repro steps
TelemetryConfiguration
similar toAPPINSIGHTS_INSTRUMENTATIONKEY
environment variable tolocal.settings.json
Here is a complete picture of my function project's nuget dependencies:
Expected behavior
After performing step 5, I expect the function to start and my break point in the constructor to be hit.
Actual behavior
Azure Functions Core Tools terminal shows error
"Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type 'Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration' while attempting to activate 'DocfxPipelineFunctions.CategoryHydrationFunction'."
Here is the complete transcript from the terminal in case it helps:
Related information
[TimerTrigger( "0 */1 * * * *" )]TimerInfo timer