Application Insights Map not connected between Angular SPA and .Net 6 API
Asked Answered
B

1

6

I have an Angular 13 SPA which calls my .Net 6 API which then calls a Database. For now the whole system is running on my local machine.

I added the Application Insights JS SDK and the Angular Plugin to my SPA and initialized them

package.json

"@microsoft/applicationinsights-web": "2.7.4",
"@microsoft/applicationinsights-angularplugin-js": "2.8.0",

app.component.ts

export class AppComponent {
  title = 'app';
  constructor(
    private router: Router,
    private settings: SettingsService,
  ) {
    const aiInstrumentationKey = 'ApplicationInsights_InstrumentationKey';
    var angularPlugin = new AngularPlugin();
    const appInsights = new ApplicationInsights({
      config: {
        instrumentationKey: settings.settings.extensions[aiInstrumentationKey],
        distributedTracingMode: DistributedTracingModes.W3C,
        disableFetchTracking: false,
        enableCorsCorrelation: true,
        enableDebug: true,
        enableDebugExceptions: true,
        enableRequestHeaderTracking: true,
        enableResponseHeaderTracking: true,
        extensions: [angularPlugin],
        extensionConfig: {
          [angularPlugin.identifier]: { router: this.router }
        }
      }
    });
    appInsights.loadAppInsights();
  }
}

In my API I added the NuGet package and initialized it in my Startup class.

.csproj

<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" />

Startup.cs

services.AddApplicationInsightsTelemetry();

I can see the end-to-end transaction details just fine and they seem to carry the Operation ID (fb0903820fa64ef092fbcd432336e949 in my example) just fine through the whole dependency chain End-to-end Transaction details

However the Application Map does not line up with this. I would expect the red arrow, but instead I'm getting two disconnected graphs. Application Map

When I click on the green-circled-node and drill into the sample, I land on the same end-to-end transaction as if I click on the bottom left node for the SPA.

What can I do to have the graph properly connected?

Barina answered 7/3, 2022 at 21:47 Comment(4)
Application Map has a preview option - which sometimes breaks the map. You can try opting out of the preview.Rely
Turning off the preview actually fixed the problem. If you want to provide this as an answer, I will happily accept it.Barina
In the preview version of Application Map, you may need telemetry between nodes to exist in at least two different minutes before the client-to-server edge is generated. If this was a single test request or two, that might be what's causing the missing edge. Do you see the line appear in preview mode if you send more data?Cernuous
I generated around 50 calls, each 15s apart (so ~12min in total), but the preview Map was still not showing the correct arrow.Barina
R
5

Application Map has a preview option - which sometimes breaks the map. You can try opting out of the preview.

Rely answered 7/3, 2022 at 22:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.