-
Notifications
You must be signed in to change notification settings - Fork 305
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
[feature request] Filter at end of activity #2464
Comments
HI @DannyRichardsonWG, So for context we're talking about; Incoming Http Request --> Your Application --> Outbound Http Request You added an Activity Processor, which is successfully filtering the Outbound Requests, but not the root Incoming Request. Next Steps, Can you share a minimal repro app? |
Thanks for taking a look. Yeah your summary sounds correct. I think the filter is running before the request gets processed by the authentication middleware so the status code isn't 401 when the filter looks. I've created a small demo here: LogFilteringExample.zip Rather than implement authentication I'm just having one of the endpoints return a 401. I setup the filter to stop logging on either of these two conditions
So calling /weatherforecast works as expected. The log appears Calling /testUnauth shouldn't log as it returns 401 but it still ends up in the log. If you put a breakpoint on the filter you'll see it hits before the endpoint sets the status code so neither condition is met for preventing logging. Calling /neverLog the filter successfully prevents the trace ending up in the log So it's like there needs to be an additional EndFilter on AspNetCoreTraceInstrumentationOptions that gets called when the activity is about to stop and export Cheers, Danny |
So I got an answer about the current The Activity Processor is going to be the recommend solution since this runs after the request. You had another question about also filtering the dependencies of your unauthorized request. I would expect that if the request is unauthorized than the dependencies wouldn't execute. Regardless, if you need to make a filtering decision about a dependencies parent, you can do that in an Activity Processor as well by referencing For example:
Please let me know if you have any other questions. |
Component
OpenTelemetry.Instrumentation.AspNetCore
Is your feature request related to a problem?
I'd like the ability to be able to filter logged items based on the status code of the HTTP Response.
What is the expected behavior?
At the end of the activity processing have a filter that is able to exclude items. Similar to the filter that is applied at the start of the activity.
Which alternative solutions or features have you considered?
The goal is to drop any logging for a request to a specific endpoint with a certain status code
e.g. anything sent to / with a 401 response code.
So I call UseAzureMonitor
And added a processor
Which when hooked up partially worked, it removes the dependencies of the request but the parent request was still getting logged in the requests table in application insights.
After a bit more digging I found you can add a filter to the AddAspNetCoreInstrumentation call but as we're calling UseAzureMonitor we need to call configure using AspNetCoreTraceInstrumentationOptions
The problem is the StatusCode is 200 and not 401, I'm assuming because the logging/filter fires before the authentication middleware has kicked in as the filter runs in OnStartActivity in HttpInListener.
Is there a filter that fires at the end of the request like the OnEnd of the processor or is there a better way of achieving the goal?
Cheers,
Danny
Additional context
No response
The text was updated successfully, but these errors were encountered: