Skip to content

Incorrect Parent ID #2142

@ghost

Description

Describe the bug

The parent Id seems incorrect using DependencyTrackingTelemetryModule.IncludeDiagnosticSourceActivities

To Reproduce

public class SomeDependencyDiagnosticSource
{
    public const string DiagnosticListenerName = "Company.SomeDependency";
    public const string ActivityName = DiagnosticListenerName + ".RequestOut";
    public const string ActivityStartName = ActivityName + ".Start";
    public const string ActivityStopName = ActivityName + ".Stop";

    private static readonly DiagnosticListener _diagnostic = new DiagnosticListener(DiagnosticListenerName);

    public static SomeDependencyDiagnosticSource Instance => new SomeDependencyDiagnosticSource();

    public Activity? StartActivity()
    {
        if (_diagnostic == null)
        {
            return null;
        }

        Activity? activity = null;
        if (_diagnostic.IsEnabled() && _diagnostic.IsEnabled(DiagnosticListenerName))
        {
            activity = new Activity(ActivityName);

            // add some tags/baggages to activity.
            activity.AddTag("http.url", "https://somedependency.company.net");

            if (_diagnostic.IsEnabled(ActivityStartName))
            {
                _diagnostic.StartActivity(activity, null);
            }
            else
            {
                activity.Start();
            }
        }

        return activity;
    }

    public void StopActivity(Activity? activity)
    {
        if (activity == null)
        {
            return;
        }

        // set some tags like dependency result.

        if (_diagnostic != null && _diagnostic.IsEnabled(ActivityStopName))
        {
            _diagnostic.StopActivity(activity, null);
        }
        else
        {
            activity.Stop();
        }
    }
}

Usage :

public Task<DependencyResult> CallDependency()
{
    var activity = SomeDependencyDiagnosticSource.Instance.StartActivity();
    try
    {
        // Call the dependency
    }
    finally
    {
        SomeDependencyDiagnosticSource.Instance.StopActivity(activity);
    }
}

Application Insights configuration in ASP.NET Core startup :

services.AddApplicationInsightsTelemetry(options =>
{
    options.InstrumentationKey = Configuration["ApplicationInsights:InstrumentationKey"];
});
services.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((m, o) =>
{
    m.IncludeDiagnosticSourceActivities.Add(SomeDependencyDiagnosticSource.DiagnosticListenerName);
});

Current result in Application Insights:

Request:

  • Operation Id: 4384d4025a4b0d4fa1ef565161c22fb0
  • Parent Id: 4384d4025a4b0d4fa1ef565161c22fb0
  • Request Id: 4894327993ba8d4b

Dependency:

  • Operation Id: 4384d4025a4b0d4fa1ef565161c22fb0
  • Parent Id: 00-4384d4025a4b0d4fa1ef565161c22fb0-4894327993ba8d4b-00
  • Dependency Id: 00-4384d4025a4b0d4fa1ef565161c22fb0-de5c292e9b06574c-00

image

The request and the dependency are at the same level. Dependency should be nested in the request in this case.

Environment:

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64

Host (useful for support):
Version: 5.0.1
Commit: b02e13abab

.NET SDKs installed:
5.0.101 [C:\Program Files\dotnet\sdk]

Application Insights SDK version : 2.16.0
Target framework in csproj: net5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions