Tracing: expose HTTP response in `sampling_context`
Problem Statement
Afaik there's currently no way to filter out transaction events of HTTP requests by status code (e.g. HTTP 404) using the traces_sampler configuration option. sampling_context currently exposes the request but not the response context.
Solution Brainstorm
There's a way to filter out transaction events by HTTP status code.
You can manually call start_transaction and set a custom_sampling_context. (Like in our AWS Lambda integration: https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/aws_lambda.py#L147-L153)
The custom_sampling_context is available to the traces_sampler. So if you put your status code (or the whole response) in the custom_sampling_context you can filter by it in traces_sampler.
Does this solve your issue?
Hey @antonpirker thank you for the additional context! 🙌
I can definitely make it work but I was wondering if this is something other users might benefit as well. If yes, we could probably make this context available as default instead of having to manually do the override.
What do you think?
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
hi @guidoiaquinti this is not really possible in a normal WSGI/ASGI integration due to lifecycle issues. We start and sample a transaction at the beginning of the request flow and the response is available at the end after the sampling is already done.
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀