ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

AI (Internal): [Microsoft-ApplicationInsights-Core] Operation to stop does not match the current operation. Telemetry is not tracked.

Open qsdfplkj opened this issue 3 years ago • 2 comments

I get the following in app insights:

AI (Internal): [Microsoft-ApplicationInsights-Core] Operation to stop does not match the current operation. Telemetry is not tracked.

This is documented as a known issue?:

https://docs.microsoft.com/en-us/azure/azure-monitor/app/custom-operations-tracking#parallel-operations-processing-and-tracking

The issue being that a second operationholder should call stopoperation before the firstoperation calls it. Why can't this be solved using AsyncLocal tracking the operation that is currently in scope?

In my setup I have a async operation (DoSomething) that needs to measure it's duration. For it to be measured I wrap it inside a measurement task (MeasureTask)

    public Task MeasuredTask(Func<Task> task, IOperationHolder<DependencyTelemetry> operationHolder)
    {
        async Task result()
        {
            using (operationHolder)
            {
                await task();
            }
        }

        return result();
    }

    public Task DoSomething()
    {
        var operationHolder = _telemetryClient.StartOperation("DoSomething");

        // sync code that needs to be measured also.

        async Task result()
        {
            await Task.Delay(1000);
        }

        return MeasuredTask(() => result(), operationHolder);
    }

The DoSomething is called many times where Task.WhenAll(...do many somethings...)

Is it possible to fix? Should I change my setup such that startoperation is only called inside the measureTask method?

qsdfplkj avatar Mar 28 '21 18:03 qsdfplkj

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar Feb 08 '22 00:02 github-actions[bot]

Please remove the stale label.

qsdfplkj avatar Feb 08 '22 00:02 qsdfplkj

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar Dec 07 '22 00:12 github-actions[bot]

Why even bother.

qsdfplkj avatar Dec 14 '22 00:12 qsdfplkj