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] No auto dependency tracking when application insights is initialized and running on web worker #1483

Closed
riteshbhoi opened this issue Feb 20, 2021 · 5 comments

Comments

@riteshbhoi
Copy link

  • SDK Version [e.g. 22]: 2.5.7
  • How you initialized the SDK: In the web worker role

So have offloaded the app insights initialization and logging to a web worker. And we invoke the required methods from web worker to log to application insights. But it seems as the dependency calls are taking place on main thread and worker is unaware of this, dependency calls are not getting tracker. Is there any resolution to this issue?

@riteshbhoi riteshbhoi changed the title [BUG] No auto dependency tracking when application insights in initialized and running on web worker [BUG] No auto dependency tracking when application insights is initialized and running on web worker Feb 22, 2021
@MSNev
Copy link
Collaborator

MSNev commented Feb 23, 2021

Correct, a web worker is a self contained javascript instance and do not share the same XMLHttpRequest / fetch references.

If you want to track dependency calls from both the main thread and any worker(s) then all instances would need to be instrumented.

In your case as you are offloading the initialization into a worker, you would need to wrap and track the dependency calls (same as the dependency plugin) and then delegate the request (trackDependencyData) call to your worker.

@riteshbhoi
Copy link
Author

If i just delegate the XMLHttpRequest/Fetch calls to my worker and my worker makes the call (not sure if that is the right pattern), won't the dependency calls be tracked automatically, as worker has application insights initialized? Do i need to wrap and track the dependency calls separately as such?

@MSNev
Copy link
Collaborator

MSNev commented Feb 23, 2021

If i just delegate the XMLHttpRequest/Fetch calls to my worker and my worker makes the call (not sure if that is the right pattern)

You could, but I wouldn't as you would incur additional marshalling costs for every request.

won't the dependency calls be tracked automatically

Yes, they should as long as you have also enabled fetch tracking (currently disabled by default), but as above I don't believe this would be the best approach -- it does of course depend on your application and performance requirements etc.

Do i need to wrap and track the dependency calls separately as such?

There are really 2 general approaches (or 3 based on your delegation pattern), so for the 2

  1. Wrapping: Yes, you would need to wrap the request and once you have a response (same as the dependency code) you could then delegate the "track" call to your worker. And you would have to wrap the XHR and fetch yourself -- potentially taking the dependency extension as a guide on how you would do this
  2. Initialize on page: As mentioned above, just initialize an instance of the AI SDK in the main (page/document) of your application and this will automatically wrap etc. But this of course depends on why you have created the delegation pattern in the first place and whether this would work, it may also cause some event duplication depending on how your measuring the automatic events such as page load / performance -- so you would probably need to have a telemetry initializer so you can drop the events on the page or worker that you don't want to have reported twice.

@MSNev
Copy link
Collaborator

MSNev commented Mar 18, 2021

Closing as this doesn't seem to an issue that we can address directly in the SDK (as a bug/enhancement)

@MSNev MSNev closed this as completed Mar 18, 2021
@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 Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants