Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Filtering logs with status code 308 does not work #2252

Open
andreeatirgovatu opened this issue Jan 26, 2024 · 2 comments
Open

[BUG] Filtering logs with status code 308 does not work #2252

andreeatirgovatu opened this issue Jan 26, 2024 · 2 comments
Labels

Comments

@andreeatirgovatu
Copy link

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 .
Screenshot 2024-01-26 at 23 00 32

  • SDK Version [e.g. 22]: "@microsoft/applicationinsights-web": "^2.6.1"

Thank you in advance,
Andreea

@MSNev MSNev added the question label Feb 2, 2024
@MSNev
Copy link
Collaborator

MSNev commented Feb 2, 2024

Is this for requests originating from the browser?

ie. you are sending out HEAD requests?

@MSNev
Copy link
Collaborator

MSNev commented Feb 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants