huang-julien / nuxt-applicationinsights

ApplicationInsights module for Nuxt 3.
15 stars 0 forks source link

Correlate Page Views with backend traceIds #3

Closed mcremer-able closed 6 months ago

mcremer-able commented 7 months ago

Currently I do this

 $appInsights.trackPageView({ uri: basePath + currentRoute.fullPath });

This creates the Page View entry, but totally decouples them from the backend process. In https://github.com/huang-julien/nitro-applicationinsights/blob/683f2ed0a3ab8c58b846bae0b2aeee8e674dde52/src/plugin.ts#L38C1-L38C1 we try to get the parentId from the headers and find the traceParent

It would be great if we could use that to add the page view to that Parent Trace

huang-julien commented 7 months ago

Hi :wave: Do you mean you want the continuity of the operation between the initial SSR request and the first page view ?

Like

I'm working on this, some fixes will probably come this weekend

mcremer-able commented 7 months ago

Hello,

thanks for the quick answer.

Kind of. There are 2 ways we render a Page and should call trackPageView

  1. First Request that gets rendered via SSR on the Server
  2. Following Navigation controlled by Client-Side-Routing

Correlating 2 seems difficult, but 1 seems simple because all the calls logging that runs on the server is connected to the same URL as the logging that gets attached to that PageView.

One solution would be:

  1. Server Request start
  2. Get traceId
  3. Set Response Header to something like x-traceId:<traceId>
  4. In the browser get the traceId from the header
  5. Use this id as parent for this Page View

This would already fill a huge hole in our logging