-
Notifications
You must be signed in to change notification settings - Fork 237
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] App Insights not auto-capturing from a Web Worker #1995
Comments
Suggest that you use the following // https://docs.microsoft.com/en-us/azure/azure-monitor/app/javascript#configuration
const appInsights = new ApplicationInsights({
config: {
connectionString: config.appInsightsConnectionString, // use connection string instead of just key
disableXhr: true, // don't use XMLHttpRequest
enableCorsCorrelation: true, // correlate requests with backend requests
},
}); |
Thanks for the info. I tried it with your suggestion but still no auto-tracking. I then enabled the debug settings and there's nothing in the logs, Side note, it's an interesting point about |
Hmm, sounds like either the SDK is not initializing, our hooked (instrumented) // Framework
let cachedFetch = fetch;
// Initialize Application Insights (which wraps fetch)
initialize(...);
// So now usages of
fetch(...); // are reported
// not reported as this is still pointing to the original (real) implementation
cachedFetch(...); If this is occurring then possible ways to fix this would be
InstrumentFunc(globalThis, "fetch", {
ns: "pre-rwrapped"
// you don't need to provide an req or rsp callback functions
}); I guess another possibility is that we are replacing/wrapping |
Is there a way to know definitively if |
Not that I am aware of - none of our other dependencies should have app insights and they certainly shouldn't be instrumenting their own instance. We aren't using any polyfills for XHR or fetch, we are using the browser-shipped global |
I tried with both cached fetch and the version after
I tried this too and still nothing. I see my manually-tracked exception, but no Am I crazy??? Is there something I'm missing? I basically copied the setup code from the main thread to the worker. This is so strange. |
Something like this should work
|
You could use the |
This (should) be working, the next stop sounds like debugging into your worker and setting break points to ensure that the SDK is running the code we think it is, as it's sounding like it's not for some reason. I don't currently have cycles to try and repo locally, so atm it will probably be a few weeks before we can look into this more deeply. |
I even added all 4 funcs to |
Ok, lets enumerate all of them then, can you try the following you will not likely get all 4 of them from the worker, but this will tell us if any of them are hooked.
And then after this lets find out which one is the "default"
If we get a hit on the _aiHooks that doesn't match the first hist on the 2nd then we have our initial answer and a way to identify how to fix the issue. If we get nothing, then we have another set of issues, either your code is not running and therefore the SDK is not getting initialized (this would include your InstrumentFunc call) OR (more likely) the runtime is not letting us "replace" (hook) the fetch function... |
None of the 4 have _aiHooks. Only I think I have it narrowed down to something in the Edit: In |
I wonder if this is a problem with Comlink, or just with SharedWorkers. I'll try to test it without using Comlink and see if it works any differently - perhaps they're clobbering |
This might be the issue as there is a recent change in some browsers where we have to check the getOwnPropertyDescriptor (which we are doing in the |
Can you also try |
Nope, it returns |
I did actually try the latest beta but it did not work. I went back to latest stable before making the issue. |
Thanks for trying the beta -- apart from this issue, was there anything unexpected that occurred etc. I'm going to create another issue about adding "in" check to the Instrument code and I'll link to this issue. |
I don't think there was anything else. I saw all of the manual events (Exceptions, Events, etc) just fine. It was only the auto-tracking that was not working. Thank you for taking the time to work with me! I hope to be able to try the beta (again) soon! |
Potentially unrelated, when I call |
Yes, by default that would occur, however, if you set I can feel a SharedWorker sample in my future. |
Sure thing:
Keep in mind you do have to have the |
Thanks, I obviously didn't drill down far enough when debugging the Shared Worker. I'm now in the process of migrating this to |
The _getOwner() is effectivelly called recursively, where it tries to find the ultimate owner from the target instance so it effective "cycles" the This is required because for a WebWorker it's not the current global but it's parent that "owns" the |
Ok, I've got the migrated code working in 2.8.x and I've tracked down the "exception" for the trackPageView. And it's not actually an exception, as the page view event is still sent. So I'll look at either reducing this to once or just disable when running in a web worker. I'm now going to check if the max ajax counts are reset and if not I'll fix that also for this case. |
We should be good on the max ajax calls -- they look like the count is getting reset here |
Great, thanks for the info! I still worry that even though AI has been instrumented, it's for some reason still not auto-tracking. I didn't see anything being sent to my azure instance in the network logs. To be more precise, according to the docs, I need to call |
No this is not necessary, it's just generally the first thing most people want to do for their page and as soon as the page is "operational". Its also (by default) not triggered (and won't be for a WebWorker) from the URL location change.
No, as soon as you call "initialize" and it's successful (doesn't fail for some reason) all automatic tracking (fetch in this case)
No, but by default events are batched and only sent every 15 seconds, you can change this with the Also, instrumenting the "worker" will NOT instrument the main page as they operate in different runtimes and do not share the |
Ah, makes sense!
Yep, this makes total sense. In our case we're funneling ALL So it sounds like this should be working, but I'm not seeing any Dependency data in the I don't suppose you have any other handy tips? 😅 |
I just checked with the SharedWorker example that I created and it is reporting the remote dependencies So with the |
Last nights For the beta, I'm currently merging the suppression back to beta and the plan is to start promoting the |
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. |
Description/Screenshot
I am trying to auto-capture
fetch
calls from a shared web worker. I can manually track exceptions, but I don't want to manually track all of the request/response dependencies. I am using aSharedWorker
(a regularWorker
exhibits the same issue) using the Comlink library.I've searched and read the other issues (#1149, #1264, #1436, #1483, and #1727). They are either fixed or don't apply to my situation, and the most recent one is now over a year old which has since been fixed.
Steps to Reproduce
fetch
call from the workerClient Info
@microsoft/applicationinsights-web: 2.8.10
Expected behavior
App Insights should auto-capture request and response information.
Additional context
Add any other context about the problem here.
Here is my initialization code. If I try to call
trackPageView
like I have before, it throws an exception (but only whenenableDebug
orenableDebugExceptions
is true).The text was updated successfully, but these errors were encountered: