Frontend instrumentation: Fix bug, where allInstrumentationsEnabled=false resulted in all instrumentation being active (#103979)

Fix allInstrumentationsEnabled flag
pull/103982/head^2
Andrej Ocenas 3 months ago committed by GitHub
parent daa5a48ef1
commit 9748b16ee8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 26
      public/app/core/services/echo/backends/grafana-javascript-agent/GrafanaJavascriptAgentBackend.test.ts
  2. 4
      public/app/core/services/echo/backends/grafana-javascript-agent/GrafanaJavascriptAgentBackend.ts

@ -2,7 +2,8 @@ import { BuildInfo } from '@grafana/data';
import { GrafanaEdition } from '@grafana/data/internal'; import { GrafanaEdition } from '@grafana/data/internal';
import { Faro, Instrumentation } from '@grafana/faro-core'; import { Faro, Instrumentation } from '@grafana/faro-core';
import * as faroWebSdkModule from '@grafana/faro-web-sdk'; import * as faroWebSdkModule from '@grafana/faro-web-sdk';
import { BrowserConfig, FetchTransport } from '@grafana/faro-web-sdk'; import { BrowserConfig, FetchTransport, SessionInstrumentation } from '@grafana/faro-web-sdk';
import { TracingInstrumentation } from '@grafana/faro-web-tracing';
import { EchoSrvTransport } from './EchoSrvTransport'; import { EchoSrvTransport } from './EchoSrvTransport';
import { import {
@ -32,7 +33,7 @@ describe('GrafanaJavascriptAgentEchoBackend', () => {
error: jest.fn(), error: jest.fn(),
}; };
initializeFaroMock = jest.spyOn(faroWebSdkModule, 'initializeFaro').mockReturnValueOnce({ initializeFaroMock = jest.spyOn(faroWebSdkModule, 'initializeFaro').mockReturnValue({
...faroWebSdkModule.faro, ...faroWebSdkModule.faro,
api: { api: {
...faroWebSdkModule.faro.api, ...faroWebSdkModule.faro.api,
@ -130,6 +131,27 @@ describe('GrafanaJavascriptAgentEchoBackend', () => {
expect(end - start).toBeLessThanOrEqual(maxExecutionTime); expect(end - start).toBeLessThanOrEqual(maxExecutionTime);
}); });
it('correctly set instrumentation based on options', async () => {
let opts = {
...options,
allInstrumentationsEnabled: false,
errorInstrumentalizationEnabled: false,
consoleInstrumentalizationEnabled: false,
webVitalsInstrumentalizationEnabled: false,
tracingInstrumentalizationEnabled: false,
};
new GrafanaJavascriptAgentBackend(opts);
expect(initializeFaroMock.mock.calls[0][0].instrumentations?.length).toEqual(1);
expect(initializeFaroMock.mock.calls[0][0].instrumentations?.[0]).toBeInstanceOf(SessionInstrumentation);
opts.tracingInstrumentalizationEnabled = true;
new GrafanaJavascriptAgentBackend(opts);
expect(initializeFaroMock.mock.calls[1][0].instrumentations?.length).toEqual(2);
expect(initializeFaroMock.mock.calls[1][0].instrumentations?.[0]).toBeInstanceOf(TracingInstrumentation);
expect(initializeFaroMock.mock.calls[1][0].instrumentations?.[1]).toBeInstanceOf(SessionInstrumentation);
});
//@FIXME - make integration test work //@FIXME - make integration test work
// it('integration test with EchoSrv and GrafanaJavascriptAgent', async () => { // it('integration test with EchoSrv and GrafanaJavascriptAgent', async () => {

@ -99,8 +99,8 @@ export class GrafanaJavascriptAgentBackend
environment: options.buildInfo.env, environment: options.buildInfo.env,
}, },
instrumentations: options.allInstrumentationsEnabled instrumentations: options.allInstrumentationsEnabled
? instrumentations ? [...getWebInstrumentations(), new TracingInstrumentation()]
: [...getWebInstrumentations(), new TracingInstrumentation()], : instrumentations,
consoleInstrumentation: consoleInstrumentationOptions, consoleInstrumentation: consoleInstrumentationOptions,
trackWebVitalsAttribution: options.webVitalsInstrumentalizationEnabled || options.allInstrumentationsEnabled, trackWebVitalsAttribution: options.webVitalsInstrumentalizationEnabled || options.allInstrumentationsEnabled,
transports, transports,

Loading…
Cancel
Save