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

PYINSTRUMENT_SHOW_CALLBACK should not be ignored if PYINSTRUMENT_PROFILE_DIR is defined #342

Open
maingoh opened this issue Oct 4, 2024 · 2 comments

Comments

@maingoh
Copy link

maingoh commented Oct 4, 2024

I defined PYINSTRUMENT_PROFILE_DIR to record multiple requests, but I also would like to ignore some of them to avoid having too much reports being generated. So I would to be able to set PYINSTRUMENT_PROFILE_DIR and also PYINSTRUMENT_SHOW_CALLBACK. But according the the code, when PYINSTRUMENT_PROFILE_DIR is defined, all requests are recorded and PYINSTRUMENT_SHOW_CALLBACK is ignored.

Thus I think we could remove the or condition here

) or profile_dir:
as by default PYINSTRUMENT_SHOW_CALLBACK = True.

@maingoh
Copy link
Author

maingoh commented Oct 4, 2024

It looks like and getattr(settings, "PYINSTRUMENT_URL_ARGUMENT", "profile") in request.GET also prevent from using the callback. I feel it should be:

if (
            show_pyinstrument(request)
            or getattr(settings, "PYINSTRUMENT_URL_ARGUMENT", "profile") in request.GET
        ):

If a user add the profile query param, it would activate it anyway, otherwise it would rely on show_pyinstrument.

If for some reason we don't want to allow ?profile to override all behaviors. We could thus do:

  • If the callback is defined, rely on the callback, which could well have if request.query_params.get('profile')
  • Or rely on the profile query param

@jonmooser
Copy link

I too would like to be able to use PYINSTRUMENT_SHOW_CALLBACK in conjunction with PYINSTRUMENT_PROFILE_DIR

My suggestion might be

if (
    show_pyinstrument(request)
    and ( getattr(settings, "PYINSTRUMENT_URL_ARGUMENT", "profile") in request.GET or profile_dir)
 ) :

That way show_pyinstrument can be used to gate the effects for either a url argument or a profile directory

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

No branches or pull requests

2 participants