Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Custom properties added with addTelemetryInitializer are ignored for first PageVisitTime track event #2187

Open
Nosfit opened this issue Oct 26, 2023 · 2 comments
Labels

Comments

@Nosfit
Copy link

Nosfit commented Oct 26, 2023

Description/Screenshot
When I set autoTrackPageVisitTime to true in the ApplicationInsights configuration, the first payload for PageVisitTime does not contain any custom parameters that I added using the addTelemetryInitialiser method.

Screenshot 2023-10-26 at 15 01 54

Steps to Reproduce
init telemetry with custom properties:

const appInsights = new ApplicationInsights({
      config: {
        appId: 'test-bug-report',
        connectionString: this.connectionString,
        autoTrackPageVisitTime: true,
      },
    });
    appInsights.loadAppInsights();
    appInsights.trackPageView();
    appInsights.addTelemetryInitializer(this.enrichTelemetry);

    ///

   enrichTelemetry = (item: ITelemetryItem): void => {
      if (item.tags == null) {
        item.tags = [];
      }
      item.tags['ai.cloud.role'] = 'test-bug-report-roleName';
      item.tags['ai.cloud.roleInstance'] = 'test-bug-report-roleInstance';
    };

then visit your application and see on first track request in network section.

  • OS/Browser:
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36'
  • SDK Version [e.g. 22]:
    "@microsoft/applicationinsights-web": "^3.0.4"
  • How you initialized the SDK:

Expected behavior

Additional context
Add any other context about the problem here.

@MSNev
Copy link
Collaborator

MSNev commented Oct 26, 2023

Yes, this is because you are adding the telemetry initializer "AFTER" you are triggering the page view

flip the order of these 2 functions

    appInsights.trackPageView();
    appInsights.addTelemetryInitializer(this.enrichTelemetry);

to

    appInsights.addTelemetryInitializer(this.enrichTelemetry);
    appInsights.trackPageView();

@Nosfit
Copy link
Author

Nosfit commented Oct 30, 2023

Thanks. That helps

@MSNev MSNev added the question label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants