Skip to content

[BUG] calling trackPageView does not create new traceparent #2652

@Stralos

Description

@Stralos

Description/Screenshot
When enableAutoRouteTracking is enabled, route changes in SPA result into a new Traceparent header being generated for all outgoing requests

If we disable this property, and call .trackPageView manually, this does not result to a new Traceparent being generated for all ongoing requests

Steps to Reproduce

  • OS/Browser: Edge (should behave same on any browser)
  • SDK Version [e.g. 22]: 3.3.9
  • How you initialized the SDK:
import {
  ApplicationInsights,
  DistributedTracingModes,
  ITelemetryItem,
} from "@microsoft/applicationinsights-web";

const APP_VERSION = import.meta.env.APP_VERSION || "unknown";

function injectAppData(envelope: ITelemetryItem) {
  if (!envelope.data) {
    return;
  }

  envelope.data.appName = "app name";
  envelope.data.appVersion = APP_VERSION;

  envelope.data.origin = window.location.origin;
  envelope.data.href = window.location.href;

  envelope.data.viewportWidth = window.innerWidth;
  envelope.data.viewportHeight = window.innerHeight;
}

export async function getInsights() {
  const appInsights = new ApplicationInsights({
    config: {
      autoTrackPageVisitTime: false,
      connectionString: 'key'
      distributedTracingMode: DistributedTracingModes.W3C,
      enableAutoRouteTracking: false,
      enableCorsCorrelation: true,
      enableUnhandledPromiseRejectionTracking: true,
    },
  });
  appInsights.loadAppInsights();
  appInsights.addTelemetryInitializer(injectAppData);
  appInsights.context.application.ver = APP_VERSION;
  appInsights.trackPageView();

  return appInsights;
}

Expected behavior

  • Calling .trackPageView() should update the Traceparent header

Additional context
I can see in this issue there is a discussion about this behaviour, and solutions are presented here

Is this the expected solution to this issue ? If yes, should it be documented somewhere ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions