codigube
codigube

Reputation: 1256

TelemetryClient.StartOperation always failed when passing an Activity as parameter in Azure function

I have a simple Azure function using BlobTrigger and want to use Application Insights SDK to work with custom telemetry.

    [FunctionName("Create-Thumbnail")]
    [StorageAccount("AzureWebJobsStorage")]
    public static void CreateThumbnail([BlobTrigger("input/{name}")] Stream image,
        [Blob("output/{name}", FileAccess.Write)] Stream imageSmall,
        ILogger log)
    {
        var requestActivity = new Activity("Create-Thumbnail");
        requestActivity.SetParentId("SOME PARENT ID");

        var newConfig = TelemetryConfiguration.CreateDefault();
        TelemetryClient telemetryClient = new TelemetryClient(newConfig);
        var requestOperation = telemetryClient.StartOperation<RequestTelemetry>(requestActivity);
        
        ...

        telemetryClient.StopOperation(requestOperation);

    }

However, this always failed with following error:

Method not found: 'Microsoft.ApplicationInsights.Extensibility.IOperationHolder`1<!!0> Microsoft.ApplicationInsights.TelemetryClientExtensions.StartOperation(Microsoft.ApplicationInsights.TelemetryClient, System.Diagnostics.Activity)'.

According to this GitHub issue: https://github.com/Azure/azure-functions-core-tools/issues/2399, it can be resolved by reverting to 2.14.0. However, I have tried all versions back to 2.8.1. None of them worked.

Passing string instead of Activity did work.

var requestOperation = telemetryClient.StartOperation<RequestTelemetry>("Create-Thumbnail");

But I need to pass Activity for configuring more context.

Does anyone know what can be the issue?

Upvotes: 1

Views: 2003

Answers (2)

Toffer
Toffer

Reputation: 41

I stumbled across this problem as well and found that "Microsoft.ApplicationInsights" version 2.15 worked, but 2.16 did not...but in addition to that...

Microsoft.ApplicationInsights version 2.15 has a dependency on "System.Diagnostics.DiagnosticSource" version 4.6.0...and one of our projects was pulling in version 5.0.0 which caused Microsoft.ApplicationInsights to use the 5.0.0 version instead of the 4.6.0 one that it normally uses...and thus this combination also causes the

Method not found: 'Microsoft.ApplicationInsights.Extensibility.IOperationHolder`1<!!0> Microsoft.ApplicationInsights.TelemetryClientExtensions.StartOperation(Microsoft.ApplicationInsights.TelemetryClient, System.Diagnostics.Activity)'.

to be produced...we downgraded the project referencing 5.0.0 down to 4.6.0 and the method not found issue went away.

Upvotes: 0

Tiny Wang
Tiny Wang

Reputation: 15961

Per my searching, I found this document and it said

There is a Functions-specific version of the Application Insights SDK that you can use to send custom telemetry data from your functions to Application Insights: Microsoft.Azure.WebJobs.Logging.ApplicationInsights

So I followed the sample code and test, but the latest stable version(3.0.27) of this package will return the same error as yours, but when I changed to v3.0.25, the error disappeared.

Upvotes: 1

Related Questions