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

How this package works - Nextjs #2182

Open
Ramemis opened this issue Oct 19, 2023 · 1 comment
Open

How this package works - Nextjs #2182

Ramemis opened this issue Oct 19, 2023 · 1 comment
Labels

Comments

@Ramemis
Copy link

Ramemis commented Oct 19, 2023

I have nextJs application.

Telemetry.ts

import { ApplicationInsights } from '@microsoft/applicationinsights-web';

const appInsights = new ApplicationInsights({
  config: {
    connectionString:
      'InstrumentationKey=<<connectionString>>',
  },
});

appInsights.loadAppInsights();
export { appInsights };

Document.ts

import { Html, Head, Main, NextScript } from 'next/document';
import Script from 'next/script';
import { appInsights } from 'services/telemetry';

appInsights.trackPageView();
appInsights.startTrackPage();
const Document = () => {
return ();
}
  1. The document page is the homepage. So when ever I hit the homepage I can able to see the PageViews logs are getting populated in the log table. But it doesn't give any information like below. What I expect is atleast the url of the page which loads this application. But the below information doesn't provide anything.
    image

  2. I read that difference between operation vs dependency. That the request will be tagged under operations and the response will be under dependency (correct me if I'm wrong). But in the above case even though I can see the page views in logs. I don't see the graph spike for request count in neither the operation nor the dependency. Is there anything I'm missing.

  3. How to log each request(url and page information) for each page views I'm visiting. Is there anything apart from the above need to be done.

@MSNev
Copy link
Collaborator

MSNev commented Oct 19, 2023

The URL for this Web based SDK is obtained from the location.href, if this code is running on the Server side (in the NextJS runtime), then this would indicate that these values are either not available, or the server request is not supplying a mocked version of the location object.

How to populate this (for the automatic) request (on the server) is unknown (we don't use NextJS). However, if you don't have the automatic PageView enabled (enableAutoRouteTracking) and you are manually calling trackPageView() during the initialization, then you can pass in the uri yourself.

appInsights.trackPageView({
    uri: "https://my.url.com/abc"
});

@MSNev MSNev added the question label Oct 31, 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