-
Notifications
You must be signed in to change notification settings - Fork 240
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
Multiple IA Instances or collection of subscriptions on client side #1595
Comments
Yes you can, as long as all of the subscription(s) all end up in the same region (and therefore get sent to the same location -- without the server sending service side redirects). Then there are 2 simple methods
What this doesn't do for you is that all of the automatic events (PageView, Instrumented XHR or fetch) requests etc will still use be assigned the default instrumentationKey and these will only get sent once (which is fine -- most of the time, except for maybe the Page view for different subscriptions). For the ajax (XHR, fetch) dependency calls this is where the telemetryInitializer option would work better as you can switch the iKey based on the URL. Another option So the following will create 2 global objects
Note: I've not tried this recently, so if you encounter an issue with this let us know as that would be considered a bug. |
Just fixed up the "location" of the name config in the above as it should be at the same level as cfg (doh!) just as is documented in the main readme https://github.com/Microsoft/ApplicationInsights-JS#snippet-setup-ignore-if-using-npm-setup |
@MSNev I've been trying to achieve the same thing and took your suggestion and other various approaches but with no success: 1) Multiple instancesMy first attempt was having 2 global instances as you mentioned and call them separately but this didn't work as expected and only logged it to one of the instances. Apparently the last one that is defined in the HTML is the only one that works as I switched them around and now the instance that was not getting logged, was getting logged, and the other didn't log anymore. I've also tried refactoring the 2 global objects as not to need to have to duplicate the whole js snippet by converting it to NOT be IIFE ( Immediately invoked function expression ) and instead assign it to a variable so I could call it multiple times with different config objects:
This had no difference from the 2 separate global objects and only the last one was getting logged. 2) iKey as an event propertyMy second attempt was specifing the
I tried using different names such as 3) Overriding appInsights.config.instrumentationKeyThen my last idea was to override the
This worked but it seems very inconsistent. Sometimes the event doesn't get logged to the second instance probably due to how the SDK debounces and aggregates as many events as possible before POSTing them to App Insights. I really have no idea.. I think the simplest thing would be to have the ability to override the iKey when calling appInsights.trackEvent(). |
Hi @FredUK |
Hi @FredUK
please let us know if the solution works! |
@FredUK, and just to circle back on your options (sorry I was out last week).
|
Hi @Karlie-777 and @MSNev , thanks for both detailed replies. That really helps understanding why it wasn't working. I have created a small jsfiddle sample here if you want to take a look. If you click the "trackEvent" button and look at the console you will see it will log the first placeholder iKey but for the second log, it says appInsights2 is not defined. It seems the second global one is not initialized at all, even when on initiated on onInit. Just wondering if the suggestion had been tested in the past or if I'm doing something wrong? Thanks. |
Hi @FredUK, The OnInit, needs to be outside of the cfg: {} as it's a snippet config value and not the AI config. I changed your jsFiddle for the 1st instance like this
|
Thanks @MSNev 🏅 , that worked. I guess I spent too much time messing with it that I messed up where I put the onInit. :) |
Ok, a CORB error is a little tricky to diagnose as it's going to depend on what the server returned in the body of the response and the Content-Type header. As such I think the easiest way to track this down (if you can get a consistent repro) would be a fiddler trace with the offending response(s) to https://dc.services.visualstudio.com/vs/track, so this may contain sensitive data attaching to this thread is not advised. So if you can get a trace with this captured let me know (here) and we can find some other way to share the file. |
Hi again, I have managed to capture it in Fiddler just not sure how I will be able to send you the google drive link as Github has no private messaging. As I mentioned this only seems to happen sometimes. Looking at the server response for a working logged event and one that threw a CORB message the only difference I can see is that in the response body for the CORB one there is no appId property returned from the server. This response was fine
This response threw a CORB error
Hope this helps. Let me know if you are still interested in the fiddler session file and how I can make the link get to you. |
@FredUK - excellent, I suspect it's something else in the response. I'm currently setting up an email alias that will enable you to send the trace (or a link) directly to me. It normally takes a few hours to get approved / processed will ping again once it is complete and active. It will be an @microsoft.com email address. |
Thanks @MSNev , email has been sent. You can remove it from comment above if you'd like. |
Thanks @FredUK, I'm reviewing the trace and while the response seems fine there are differences in the outbound request specifically the Content-Type which might be causing the issue -- investigating. |
I've split out the CORB issue to #1653, as the requests that are returning the CORB issue appear to be originating from the _beaconSender() (using the sendBeacon API). Assuming this is the only case this is a non-blocking issue as the JS code doesn't need the response from a sendBeacon request (because the API doesn't return the response). Looking at the trace provided by @FredUK the events where still ingested by the service, so it does not appear that this is blocking events from being ingested |
We are leveraging the ApplicationInsights-JS package in a micro UI architecture where many teams are contributing to overall user experience. These teams would like to be able to monitor and instrument with their own instance of App Insights subscription.
Would like to be able to instantiate or maintain a collection of app insights subscriptions on client side and be able to push data to any of them based on configuration.
We have tried to implement all telemetry to a single app insights instance, but storage threshold is becoming an issue.
Is there any way to be able to selectively push telemetry data to multiple subscriptions in the same application.
The text was updated successfully, but these errors were encountered: