microsoft / microsoft/ApplicationInsights-dotnet

ApplicationInsights changes to AvailabilityTelemetry logging in v3.x loses AvailabilityTelemetry trace/span info

Open
#3,166 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

keep-open
Dominant language
C#
Stars
613
Forks
301
PR merge metrics
No merged PRs in 30d

Description

Working packages:

  • Microsoft.ApplicationInsights 2.23.0
  • Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel 2.23.0

Broken packages

  • Microsoft.ApplicationInsights 3.x

Runtime: aspnetcore9.0
Hosting environment: any

The changes to proxy AvailabilityTelemetry through ILogger + the OpenTelemetry exporter in the 3.x builds lose the otel trace/span info that previously worked. This previously worked:

    private static void AddAvailabilitySpanInfo(AvailabilityTelemetry telemetryItem, Activity? activity)
    {
        if (activity != null)
        {
            telemetryItem.Id = activity.SpanId.ToString();
        }

        AddTelemetryParentIds(telemetryItem, activity);
    }

    private static void AddTelemetryParentIds(ITelemetry telemetryItem, Activity? activity)
    {
        if (activity != null)
        {
            telemetryItem.Context.Operation.Id       = activity.TraceId.ToString();
            if (activity.ParentId != null)
            {
                telemetryItem.Context.Operation.ParentId = activity.ParentSpanId.ToString();
            }
        }
    }

but now the otel trace/span info is lost. I've verified by code reviewing both this repo and the otel exporter in the azure-sdk-for-net that the span info in the legacy TelemetryContext.Operation is not accounted for.

Modelling an AvailabilityResult as a LogRecord is potentially problematic because an AvailabilityResult has span semantics (it has a duration and can be a non-leaf node in the trace tree). The ApplicationInsights UI gets this correct, eg this is how our health reporting looks using ApplicationInsights 2.23.0 client lib:

Image

So if you want to push an AvailabilityTelemetry through an ILogger to a LogRecord you're going to have to come up with a representation for the TraceId and ParentSpanId that can be restored within the Availability entry in the otel exporter.

We are 90% migrated to OpenTelemetry - the only reason we still have a dependency on the ApplicationInsights (classic/legacy) library is for Availability reporting. So it would be better for us to be able to log Availability entries directly (via the otel exporter or preferably an Api client), then we could drop the ApplicationInsights libraries. But we'd still need a way to specify the activity/span info for each Availability entry - currently there is none. I've tried doing this purely using ILogger and using the Availability properties, and I can create the Availability telemetry this way except for the span properties.

Of course I would feel more comfortable if there was a strong API (eg service API client) for reporting availability telemetry, vs a set of dictionary keys passed to an ILogger that could change at any time.

To be clear: We can't upgrade to ApplicationInsights 3.x until this is addressed, and/or we can't migrate to the otel exporter library only until there is a way to report AvailabilityTelemetry where we can specify the TraceId and ParentSpanId.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare AvailabilityTelemetry handling in the 2.23.0 and 3.x builds, starting with the v3.x ILogger and OpenTelemetry exporter path. Review the referenced AddAvailabilitySpanInfo and AddTelemetryParentIds behavior, then inspect the azure-sdk-for-net exporter’s LogRecord handling. Reproduce the loss under aspnetcore9.0 and define a way for availability entries to retain TraceId and ParentSpanId.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
observability
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.