Sitelet https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/864
Skip to content
This repository was archived by the owner on Jul 5, 2020. It is now read-only.
This repository was archived by the owner on Jul 5, 2020. It is now read-only.

StartOperation dependency is tracked outside of dependency activity #864

Description

@zakimaksyutov

If you are reporting bug/issue, please provide detailed Repro instructions.

Repro Steps

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;

namespace MvcFiveApp.Controllers
{
    public class TestController : ApiController
    {
        private readonly TelemetryClient telemetryClient = new TelemetryClient();

        [System.Web.Http.AcceptVerbs("GET")]
        public async Task<string> DoWork([FromUri] int WorkID)
        {
            try
            {
                Activity.Current.AddTag("WorkID", WorkID.ToString()); // Exists for Request, Dependency, Trace and Exception telemetry

                using (var dependency = this.telemetryClient.StartOperation<DependencyTelemetry>("StoreWork"))
                {
                    Activity.Current.AddTag("DependencyID", Guid.NewGuid().ToString("N")); // Exists only for Trace telemetry. Expectation: exists for Dependency as well

                    this.telemetryClient.TrackTrace("MyTrace");
                    await Task.Delay(TimeSpan.FromMilliseconds(267)).ConfigureAwait(false);
                    this.telemetryClient.TrackTrace("MyTrace2");

                    if (WorkID > 10)
                    {
                        throw new Exception("Too big ID!");
                    }
                }

                return WorkID.ToString();
            }
            catch (Exception ex)
            {
                this.telemetryClient.TrackException(ex);
                throw;
            }
        }
    }
}

Actual Behavior

TelemetryInitializer is called twice (once upon StartOperation and one as a part of Track), both with Activity.Current pointing to RequestTelemetry and not DependencyTelemetry

Expected Behavior

TelemetryInitializer is called once. Activity.Current should point to Dependency activity

Version Info

SDK Version : 2.6-beta2
.NET Version :
How Application was onboarded with SDK(VisualStudio/StatusMonitor/Azure Extension) :
OS :
Hosting Info (IIS/Azure WebApps/ etc) :

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions