question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Manual logging with opt-in telemetry?

See original GitHub issue

Hi 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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MSNevcommented, Feb 28, 2022

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” the TelemetryInitializers 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 cookies ai_user etc and sets a bunch of default common values) – you may want to include but still set the disable 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)
0reactions
baxxoscommented, Mar 2, 2022

@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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

An Essential Guide to OpenTelemetry - Logz.io
Start your journey with OpenTelemetry to generate and collect traces, metrics and logs from your system, with this useful tutorial and reference hub....
Read more >
OpenTelemetry Logging Instrumentation
The OpenTelemetry logging integration automatically injects tracing context into log statements. The integration registers a custom log record factory with ...
Read more >
How to Setup OpenTelemetry Logging in .NET - YouTube
You've discovered that OpenTelemetry can send logs as well as traces but you're not sure how set this up? This OpenTelemetry tutorial will ......
Read more >
Manual Instrumentation | OpenTelemetry
InMemoryMetricExporter : keeps the data in memory, useful for testing and debugging. · Logging Exporter: saves the telemetry data into log streams.
Read more >
Application Insights logging with .NET - Azure Monitor
Learn how to use Application Insights with the ILogger interface in .NET.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found