[BUG] Filtering logs with status code 308 does not work
Hi,
I was wondering is there the ability to prevent logs with status code 308 (HEAD method) and static files requests. I tried some things within react app like :
const filteringFn = (envelope: ITelemetryItem) => {
if (envelope.baseData?.responseCode === 308 || envelope.baseData?.name?.includes('_next')) {
return false;
}
return true;
};
const initAppInsights = () => {
if (isBrowser() && config.appInsightsKey && !window.appInsights) {
const appInsights = new ApplicationInsights({
config: {
instrumentationKey: config.appInsightsKey,
loggingLevelConsole: config.logLevel || 0,
loggingLevelTelemetry: config.logLevel || 0,
},
});
appInsights.loadAppInsights();
appInsights.addTelemetryInitializer(filteringFn);
window.appInsights = appInsights;
}
};
useEffect(() => {
initAppInsights();
}, []);
but it is not working. In app insights I can still see the logs .
- SDK Version [e.g. 22]: "@microsoft/applicationinsights-web": "^2.6.1"
Thank you in advance, Andreea
Is this for requests originating from the browser?
ie. you are sending out HEAD requests?
If so we added the ability to add a dependency listener / initializer (the initializer is what you would want here), where you can "inspect" the events before they are "tracked" -- https://github.com/Microsoft/ApplicationInsights-JS?tab=readme-ov-file#dependency-listeners
- These where added in 2.8.7
Failing that you can use a standard telemetryInitializer() to inspect every event and just return false when you detect that is an event you don't want to include. https://github.com/Microsoft/ApplicationInsights-JS?tab=readme-ov-file#dependency-listeners