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

Single Page Application Page View Tracking #176

Closed
gregjhogan opened this issue Apr 25, 2016 · 14 comments
Closed

Single Page Application Page View Tracking #176

gregjhogan opened this issue Apr 25, 2016 · 14 comments

Comments

@gregjhogan
Copy link
Contributor

Single page apps (such as AngularJS) need an easy way (using publicly documented APIs) to change the Operation ID each time the SPA changes the route.

@AlexBulankou
Copy link
Contributor

@gregjhogan regarding your comment on the related issue, where you said the roadblock for you was to find how to renew operation ID. Would this be easier for others we added documentation educating users on the possible (I hesitate to say "recommended", because it is not universal) approach of renewing operation ID when SPA page transition starts.
Basically a section on the homepage on SPAs. Would it help?

@gregjhogan
Copy link
Contributor Author

Yes, for example should we use Util.newId, or the Operation constructor (both of which are not in the public documentation)? Also, I hope that creates a commitment to keeping the AI side of that integration stable. Thanks!

@RichiCoder1
Copy link

Old issue, but I'd personally love to see some official docs on SPA + AI integration.

@jsgoupil
Copy link

jsgoupil commented May 8, 2017

I need to set this operation id differently.

In some does, it's mentioned that to track the POST data, we need to send a trackTrace. But it doesn't talk about this operation id. After a lot of searching, I figured out that the operation id has to be the same here. The AJAX requests are automatically tracked, and when they fail, I issue a trackTrace the POST body. However, I don't have this operation id. This is quite complicated for tracking requests together here.

@boydc2014
Copy link

So, in 2018/7/5, do we have a method to renew OperationID for SPA at each route change

@andrejpk
Copy link

andrejpk commented Mar 3, 2019

I agree that this needs better integrated tooling. This is a very common scenario and we shouldn't need a hack to make this work as most would expect.

That all said, here's my hack for my tracing to put a new operationId on each client-side route navigation (here in an angular.js app in Typescript):

      const ApplicationInsights =
        window['Microsoft'] && window['Microsoft'].ApplicationInsights;
      if (ApplicationInsights && appInsights && appInsights.context.operation) {
        appInsights.context.operation.id = ApplicationInsights.Util.newId();
        appInsights.context.operation.name = toState.name;
      }
      appInsights.startTrackPage(toState.name);

@pviotti
Copy link

pviotti commented Mar 3, 2019

For React apps you can try react-appinsights: https://github.com/Azure/react-appinsights
There's a beta version of react-appinsights supporting the upcoming AI SDK 2.0 that you can install with npm install --save react-appinsights@beta.

@mdressel
Copy link

mdressel commented May 5, 2020

@pviotti I have tried the latest React Extension (https://github.com/microsoft/ApplicationInsights-JS/blob/master/extensions/applicationinsights-react-js). It doesn't seem to address this specific issue.

While it is fairly easy to implement with the example application, all of the requests being tracked are considered the same operation as you can see below. I am not sure if I am just using this wrong or if I need to develop my own version of the extension that would utilize similar logic to what @andrejpk provided.

image

If this is an issue witht he applicationinsights-react-js extension, I can log a specific issue.

@MSNev
Copy link
Collaborator

MSNev commented May 20, 2022

Adding for completeness that currently in v2.x the approach currently is almost the same as v1

      if (appInsights && appInsights.context && appInsights.context.telemetryTrace) {
        appInsights.context.telemetryTrace.traceID = generateW3CId(); // <- Sets the new Id using the generate W3c helper function 
        appInsights.context.telemetryTrace.name = toState.name;
      }

@MSNev MSNev self-assigned this May 20, 2022
@MSNev MSNev added the investigating Investigating the issue label May 20, 2022
MSNev added a commit that referenced this issue May 23, 2022
…d during initialization

- Single Page Application Page View Tracking #176
- Run-time Telemetry initializers for Ajax requests #198
- How to modify traceflag in traceparent header? #1776
MSNev added a commit that referenced this issue May 23, 2022
…d during initialization

- Single Page Application Page View Tracking #176
- Run-time Telemetry initializers for Ajax requests #198
- How to modify traceflag in traceparent header? #1776
@MSNev MSNev removed the investigating Investigating the issue label May 23, 2022
MSNev added a commit that referenced this issue May 23, 2022
…d during initialization

- Single Page Application Page View Tracking #176
- Run-time Telemetry initializers for Ajax requests #198
- How to modify traceflag in traceparent header? #1776
@MSNev
Copy link
Collaborator

MSNev commented May 23, 2022

As part of #1705, I'm abstracting the distributed tracing support and providing another way of setting the traceId, spanId and traceFlags directly on the AI instance.

Under the covers it will still be setting the appInsights.context.telemetryTrace values, so both the above and the new functionality are identical.

The new approach will be appInsights.getTraceCtx().setTraceId("..."), the only real difference is that this will also validate that the ID is a W3C compliant traceId before setting it.

MSNev added a commit that referenced this issue May 24, 2022
…d during initialization

- Single Page Application Page View Tracking #176
- Run-time Telemetry initializers for Ajax requests #198
- How to modify traceflag in traceparent header? #1776
@MSNev MSNev added this to the 2.8.4 milestone May 25, 2022
MSNev added a commit that referenced this issue May 25, 2022
…d during initialization

- Single Page Application Page View Tracking #176
- Run-time Telemetry initializers for Ajax requests #198
- How to modify traceflag in traceparent header? #1776
MSNev added a commit that referenced this issue May 25, 2022
…d during initialization

- Single Page Application Page View Tracking #176
- Run-time Telemetry initializers for Ajax requests #198
- How to modify traceflag in traceparent header? #1776
MSNev added a commit that referenced this issue May 26, 2022
…d during initialization

- Single Page Application Page View Tracking #176
- Run-time Telemetry initializers for Ajax requests #198
- How to modify traceflag in traceparent header? #1776
@MSNev
Copy link
Collaborator

MSNev commented May 27, 2022

Splitting out from the previous PR and linking to #1846

MSNev added a commit that referenced this issue May 27, 2022
…or the core #1846

- Single Page Application Page View Tracking #176
- Run-time Telemetry initializers for Ajax requests #198
- How to modify traceflag in traceparent header? #1776
MSNev added a commit that referenced this issue May 31, 2022
…or the core #1846

- Single Page Application Page View Tracking #176
- Run-time Telemetry initializers for Ajax requests #198
- How to modify traceflag in traceparent header? #1776
MSNev added a commit that referenced this issue May 31, 2022
…or the core #1846 (#1847)

* Task 7496325: Add Distributed tracing population for the properties for the core #1846
- Single Page Application Page View Tracking #176
- Run-time Telemetry initializers for Ajax requests #198
- How to modify traceflag in traceparent header? #1776

* Add initialization from previously set values.
Also address CodeQL issues
@MSNev MSNev removed the fixed - waiting release PR Committed and waiting deployment label Jun 1, 2022
@johnib
Copy link

johnib commented Jun 6, 2022

Why different page views of the same session should be considered as different operation?

@MSNev
Copy link
Collaborator

MSNev commented Jun 6, 2022

This is generally used to separate page views in the portal for SPA, the values are set / updated here via the code listening to the location change events.

What is your expectation for multiple page views with a SPA?
As the alternative would be to set the "spanId" (using the underlying parentID) so that all of the traces (events) from the same page are linked?
Additionally, as a session is persisted across multiple page views (via cookies if enabled), this would also become problematic identifying different page views in the portal...

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants