Manual logging with opt-in telemetry?
See original GitHub issueHi guys,
I’m trying to utilize this SDK in a way that lets user opt-in into using telemetry by clicking a button located in the cookie consent. However, even if the user declines, I would like to keep sending some essential errors, warnings or debug logs into my Application Insights instance (similar to server logging). Currently, this seems to be impossible since the disableTelemetry
config option behaves like a global killswitch - i. e. it doesn’t even let me do the following:
appInsights = new ApplicationInsights({
config: {
instrumentationKey,
disableTelemetry: true,
extensions: [reactPlugin],
extensionConfig: {
[reactPlugin.identifier]: {
history: browserHistory,
},
},
},
})
...
const insights = getAppInsights()
insights.trackException(obj) // does nothing
Describe the solution you’d like
The disableTelemetry
should not disable the manual event tracking, or it should provide some kind of state other than globally on/globally off.
Describe alternatives you’ve considered I’ve considered keeping the telemetry enabled and disabling all other available configuration options:
disableTelemetry: false,
enableAutoRouteTracking: false,
disableCookiesUsage: true,
disableAjaxTracking: true,
disableFetchTracking: true,
However, there is no guarantee that the telemetry is indeed disabled (which can have legal implications in some states) and I’m still getting pageView events.
Am I missing something? Is there some other configuration option I haven’t considered?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
No, you are correct the
disableTelemetry
is a global switch as from the SDK perspective we would have the same potential legal implications (globally) if we didn’t.If your using NPM instead of the CDN, one option would be to create your own SKU (group of components) which perhaps only included the Core and Sender (there may be other required components that I’m not currently thinking of), but with just these all of the automatic collection code should not be getting instantiated and therefore hooked up.
You can use the new Chrome Extension to view all of the telemetry that is getting sent from you local instance (during development) or the in-proc Debug Extension.
You can see from the AISKU initialization that this is the default plugins that are added https://github.com/microsoft/ApplicationInsights-JS/blob/master/AISKU/src/Initialization.ts#L143-L148 which is initialized here https://github.com/microsoft/ApplicationInsights-JS/blob/master/AISKU/src/Initialization.ts#L393-L401
So to help here is a quick detail of what these plugins do
_self.appInsights = new ApplicationInsights()
(this is all of the “web hooks”) – I’d excluded this one. This is also where “currently” theTelemetryInitializers
are added. The beta that I’m currently working on is moving the telemetryInitializer’s support to the AppInsightsCore (among other things) – the beta will most likely be called v2.8.0 and is still at least a month away (early April, 2022)_self.properties = new PropertiesPlugin()
(this accesses a log of the cookiesai_user
etc and sets a bunch of default common values) – you may want to include but still set thedisable
properties_self.dependencies = new DependenciesPlugin()
(this is the code that intercepts and tracks XMLHttpRequest and fetch requests) – you probably want to disable_self.core = new AppInsightsCore()
this is required and you would want to probably expose and call the track method directly for your internal stuff_self.sender = new Sender()
(Required, this is the code the “packages” and “sends” the events to the backend)@MSNev - thanks again for the reply, it seems that the
ai_user
/ai_session
cookie pair in my browser was coming from the Browser Link (since I serve my local UI through ASP.NET backend running in Visual Studio).I’ve tried deploying the application to a proper test environment and all cookie settings work as expected there!