feat(nx-dev): allow sampling rate to be configured through env var (#30193)
The current sample rate for Grafana Faro is the default 100% and is currently around $200 for the month. We want to be able to make changes to it without needing code changes. Once this PR is merged, we can just update the env var, and then redeploy.
This commit is contained in:
parent
0ae4925e43
commit
321a63aac3
@ -2,6 +2,12 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { getWebInstrumentations, initializeFaro } from '@grafana/faro-web-sdk';
|
||||
|
||||
const DEFAULT_SAMPLE_RATE = 0.5;
|
||||
let samplingRate = process.env.NEXT_PUBLIC_FARO_SAMPLING_RATE
|
||||
? parseFloat(process.env.NEXT_PUBLIC_FARO_SAMPLING_RATE)
|
||||
: DEFAULT_SAMPLE_RATE;
|
||||
if (isNaN(samplingRate) || samplingRate > 1) samplingRate = DEFAULT_SAMPLE_RATE;
|
||||
|
||||
export function FrontendObservability() {
|
||||
const initialized = useRef(false);
|
||||
useEffect(() => {
|
||||
@ -24,6 +30,9 @@ export function FrontendObservability() {
|
||||
version,
|
||||
environment,
|
||||
},
|
||||
sessionTracking: {
|
||||
samplingRate,
|
||||
},
|
||||
instrumentations: [...getWebInstrumentations()],
|
||||
});
|
||||
}, []);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user