From bbc4dc3867b5e518f40d03939465730157a93176 Mon Sep 17 00:00:00 2001 From: Tobias Skarhed <1438972+tskarhed@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:35:39 +0200 Subject: [PATCH] Frontend Monitoring: Add config option to enable all default instrumentations (#94862) * Add config options to enable all faro instrumentation * Fix ts error * Fix type in test * Add to default config files --- conf/defaults.ini | 3 +++ conf/sample.ini | 3 +++ docs/sources/setup-grafana/configure-grafana/_index.md | 4 ++++ packages/grafana-runtime/src/config.ts | 1 + pkg/setting/setting_grafana_javascript_agent.go | 2 ++ .../GrafanaJavascriptAgentBackend.test.ts | 1 + .../GrafanaJavascriptAgentBackend.ts | 6 +++++- 7 files changed, 19 insertions(+), 1 deletion(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index b61cc964765..0c0eecdcf23 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -1126,6 +1126,9 @@ log_endpoint_requests_per_second_limit = 3 # Max requests accepted per short interval of time for Grafana backend log ingestion endpoint (/log) log_endpoint_burst_limit = 15 +# Enables all Faro default instrumentation by using `getWebInstrumentations`. Overrides other instrumentation flags. +instrumentations_all_enabled = false + # Should error instrumentation be enabled, only affects Grafana Javascript Agent instrumentations_errors_enabled = true diff --git a/conf/sample.ini b/conf/sample.ini index e22e4690f4f..644449780b2 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -1119,6 +1119,9 @@ # Max requests accepted per short interval of time for Grafana backend log ingestion endpoint (/log). ;log_endpoint_burst_limit = 15 +# Enables all Faro default instrumentation by using `getWebInstrumentations`. Overrides other instrumentation flags. +;instrumentations_all_enabled = false + # Should error instrumentation be enabled, only affects Grafana Javascript Agent ;instrumentations_errors_enabled = true diff --git a/docs/sources/setup-grafana/configure-grafana/_index.md b/docs/sources/setup-grafana/configure-grafana/_index.md index f99243a5697..ca45c37396a 100644 --- a/docs/sources/setup-grafana/configure-grafana/_index.md +++ b/docs/sources/setup-grafana/configure-grafana/_index.md @@ -1499,6 +1499,10 @@ Requests per second limit enforced per an extended period, for Grafana backend l Maximum requests accepted per short interval of time for Grafana backend log ingestion endpoint, `/log-grafana-javascript-agent`. Default is `15`. +### instrumentations_all_enabled + +Enables all Faro default instrumentation by using `getWebInstrumentations`. Overrides other instrumentation flags. + ### instrumentations_errors_enabled Turn on error instrumentation. Only affects Grafana Javascript Agent. diff --git a/packages/grafana-runtime/src/config.ts b/packages/grafana-runtime/src/config.ts index 6b751d0e62c..299db15ec35 100644 --- a/packages/grafana-runtime/src/config.ts +++ b/packages/grafana-runtime/src/config.ts @@ -126,6 +126,7 @@ export class GrafanaBootConfig implements GrafanaConfig { enabled: false, customEndpoint: '', apiKey: '', + allInstrumentationsEnabled: false, errorInstrumentalizationEnabled: true, consoleInstrumentalizationEnabled: false, webVitalsInstrumentalizationEnabled: false, diff --git a/pkg/setting/setting_grafana_javascript_agent.go b/pkg/setting/setting_grafana_javascript_agent.go index 0a58b26995a..5d5bb8f1e1b 100644 --- a/pkg/setting/setting_grafana_javascript_agent.go +++ b/pkg/setting/setting_grafana_javascript_agent.go @@ -5,6 +5,7 @@ type GrafanaJavascriptAgent struct { CustomEndpoint string `json:"customEndpoint"` EndpointRPS int `json:"-"` EndpointBurst int `json:"-"` + AllInstrumentationsEnabeld bool `json:"allInstrumentationEnabeld"` ErrorInstrumentalizationEnabled bool `json:"errorInstrumentalizationEnabled"` ConsoleInstrumentalizationEnabled bool `json:"consoleInstrumentalizationEnabled"` WebVitalsInstrumentalizationEnabled bool `json:"webVitalsInstrumentalizationEnabled"` @@ -20,6 +21,7 @@ func (cfg *Cfg) readGrafanaJavascriptAgentConfig() { CustomEndpoint: raw.Key("custom_endpoint").MustString("/log-grafana-javascript-agent"), EndpointRPS: raw.Key("log_endpoint_requests_per_second_limit").MustInt(3), EndpointBurst: raw.Key("log_endpoint_burst_limit").MustInt(15), + AllInstrumentationsEnabeld: raw.Key("instrumentations_all_enabled").MustBool(true), ErrorInstrumentalizationEnabled: raw.Key("instrumentations_errors_enabled").MustBool(true), ConsoleInstrumentalizationEnabled: raw.Key("instrumentations_console_enabled").MustBool(true), WebVitalsInstrumentalizationEnabled: raw.Key("instrumentations_webvitals_enabled").MustBool(true), diff --git a/public/app/core/services/echo/backends/grafana-javascript-agent/GrafanaJavascriptAgentBackend.test.ts b/public/app/core/services/echo/backends/grafana-javascript-agent/GrafanaJavascriptAgentBackend.test.ts index 79001934c54..7cca68e9ee8 100644 --- a/public/app/core/services/echo/backends/grafana-javascript-agent/GrafanaJavascriptAgentBackend.test.ts +++ b/public/app/core/services/echo/backends/grafana-javascript-agent/GrafanaJavascriptAgentBackend.test.ts @@ -65,6 +65,7 @@ describe('GrafanaJavascriptAgentEchoBackend', () => { app: { version: '1.0', }, + allInstrumentationsEnabled: true, errorInstrumentalizationEnabled: true, consoleInstrumentalizationEnabled: true, webVitalsInstrumentalizationEnabled: true, diff --git a/public/app/core/services/echo/backends/grafana-javascript-agent/GrafanaJavascriptAgentBackend.ts b/public/app/core/services/echo/backends/grafana-javascript-agent/GrafanaJavascriptAgentBackend.ts index abf06039856..65c821fbfd6 100644 --- a/public/app/core/services/echo/backends/grafana-javascript-agent/GrafanaJavascriptAgentBackend.ts +++ b/public/app/core/services/echo/backends/grafana-javascript-agent/GrafanaJavascriptAgentBackend.ts @@ -9,6 +9,7 @@ import { SessionInstrumentation, FetchTransport, type Instrumentation, + getWebInstrumentations, } from '@grafana/faro-web-sdk'; import { TracingInstrumentation } from '@grafana/faro-web-tracing'; import { EchoBackend, EchoEvent, EchoEventType } from '@grafana/runtime'; @@ -20,6 +21,7 @@ export interface GrafanaJavascriptAgentBackendOptions extends BrowserConfig { buildInfo: BuildInfo; customEndpoint: string; user: User; + allInstrumentationsEnabled: boolean; errorInstrumentalizationEnabled: boolean; consoleInstrumentalizationEnabled: boolean; webVitalsInstrumentalizationEnabled: boolean; @@ -67,7 +69,9 @@ export class GrafanaJavascriptAgentBackend version: options.buildInfo.version, environment: options.buildInfo.env, }, - instrumentations, + instrumentations: options.allInstrumentationsEnabled + ? instrumentations + : [...getWebInstrumentations(), new TracingInstrumentation()], transports, ignoreErrors: [ 'ResizeObserver loop limit exceeded',