Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.29k stars 429 forks source link

Azure Functions Tools gives runtime error using Application Insights 2.16 #2399

Open FiddlerKing opened 3 years ago

FiddlerKing commented 3 years ago

Got a very simple function to illustrate the problem:

[FunctionName("Function1")]
public void Run([TimerTrigger("0 */5 * * * *", RunOnStartup =true)]TimerInfo myTimer, ILogger log)
{
    var requestActivity = new System.Diagnostics.Activity($"Test");
    requestActivity.SetIdFormat(System.Diagnostics.ActivityIdFormat.W3C);
    requestActivity.SetParentId(Guid.Empty.ToString());

    using (var activity = telemetryClient.StartOperation<Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry>(requestActivity))
    {
    }
}

Running that function gives this error: Executed 'Function1' (Failed, Id=5d9ccc3f-2e1d-4f0a-b235-6384b86ae777, Duration=4258ms) System.Private.CoreLib: Exception while executing function: Function1. TestApp1: Method not found: 'Microsoft.ApplicationInsights.Extensibility.IOperationHolder`1<!!0> Microsoft.ApplicationInsights.TelemetryClientExtensions.StartOperation(Microsoft.ApplicationInsights.TelemetryClient, System.Diagnostics.Activity)'.

Downgrading Application Insights to 2.15 or 2.14 solves the problem. TelemetryClient is injected.

This happens on the latest updates of VS2019 (16.8.4). What am I doing wrong here? Or is Functions Tools not compatible with AI 2.16?

apawast commented 3 years ago

@brettsam could you please take a look at this?

fabiocav commented 3 years ago

@brettsam double checking, but this looks like a breaking change in 2.16

smartpcr commented 3 years ago

any update on this? seems it's quite brittle when using different nuget package versions than included in runtime, are there any best practice setting up dependency injection?

CarlosLanderas commented 3 years ago

I'm having the same issue and I had to downgrade application insights version and suppress version downgrade errors. Any update on this?

vyarymovych commented 3 years ago

@CarlosLanderas I tried downgrading as well but it didn't work. Which version did you downgrade to?

CarlosLanderas commented 3 years ago

@vyarymovych 2.14 is working properly I'm now able to do distributed tracing by starting operations using System.Diagnostics.Activity

vyarymovych commented 3 years ago

@CarlosLanderas thanks, I just tried again and still the same error. Sending the package versions that I use Capture_Packages Capture_Error

snapfisher commented 3 years ago

2.17 is also broken. Reverting to 2.14 does work

santhoshtns commented 2 years ago

Faced the same issue upgrading to v2.18. Reverting to v2.14 works.

JatinSanghvi commented 2 years ago

Is this issue expected to be fixed now with Azure/azure-functions-host/pull/8041 merged?