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

[core] Add import hook module #769

Merged
merged 20 commits into from
Feb 9, 2019
Merged

[core] Add import hook module #769

merged 20 commits into from
Feb 9, 2019

Conversation

Kyle-Verhoog
Copy link
Member

This PR introduces a modified version of wrapt's import hook mechanism that is better suited to our needs. The fundamentals stay the same the notable differences from the wrapt system are:

  • hooks are no longer removed after being called
  • deregister_post_import_hook is introduced to allow the removal of hooks
  • logging is added if the module is already imported

Tests are also added for this new functionality.

@Kyle-Verhoog Kyle-Verhoog added this to the 0.18.0 milestone Dec 7, 2018
Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor tweaks, but otherwise good to go.

ddtrace/utils/hook.py Outdated Show resolved Hide resolved
tests/utils/test_hook.py Outdated Show resolved Hide resolved
tests/utils/test_hook.py Outdated Show resolved Hide resolved
tests/utils/test_hook.py Outdated Show resolved Hide resolved
@brettlangdon brettlangdon modified the milestones: 0.18.0, 0.19.0 Dec 10, 2018
- fix test
- add dedup check and log
tests/utils/test_hook.py Outdated Show resolved Hide resolved
tests/utils/test_hook.py Outdated Show resolved Hide resolved
ddtrace/utils/hook.py Show resolved Hide resolved
@brettlangdon brettlangdon changed the base branch from 0.18-dev to 0.19-dev December 13, 2018 11:59
@brettlangdon brettlangdon modified the milestones: 0.19.0, 0.20.0 Dec 21, 2018
@brettlangdon brettlangdon removed this from the 0.20.0 milestone Jan 7, 2019
@Kyle-Verhoog
Copy link
Member Author

@brettlangdon this should be good to look at again when you get the chance! 😄

Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor suggestions, but otherwise this is good to go.

ddtrace/utils/hook.py Show resolved Hide resolved
ddtrace/utils/hook.py Outdated Show resolved Hide resolved
ddtrace/utils/hook.py Outdated Show resolved Hide resolved
ddtrace/utils/hook.py Outdated Show resolved Hide resolved


@synchronized(_post_import_hooks_lock)
def deregister_post_import_hook(modulename, matcher):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remind me, why this approach vs:

def hook():
    pass

register_post_import_hook('module_name', hook)
deregister_post_import_hook('module_name', hook)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in my initial implementation I had the idea of attaching an 'enabled' property on the hooks that would be checked. The matcher would allow us to easily filter out the disabled hooks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, as long as it makes sense with the plan

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm getting myself back up to speed to see if we still want to go in this direction.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to just accept the hook. If I recall correctly, our plan was to have a layer on top of this that would be meant for enabling and disabling hooks which can interface with this general api.

@brettlangdon brettlangdon changed the base branch from 0.19-dev to master January 28, 2019 23:33
@brettlangdon brettlangdon added this to the 0.21.0 milestone Jan 28, 2019
@brettlangdon brettlangdon changed the base branch from master to 0.21-dev February 8, 2019 22:51
ddtrace/utils/__init__.py Show resolved Hide resolved
ddtrace/utils/hook.py Outdated Show resolved Hide resolved
ddtrace/utils/hook.py Show resolved Hide resolved
ddtrace/utils/hook.py Outdated Show resolved Hide resolved
ddtrace/utils/hook.py Show resolved Hide resolved
ddtrace/utils/hook.py Show resolved Hide resolved
tests/subprocesstest.py Show resolved Hide resolved
brettlangdon and others added 4 commits February 8, 2019 18:11
Co-Authored-By: Kyle-Verhoog <kyle.verhoog@datadoghq.com>
Co-Authored-By: Kyle-Verhoog <kyle.verhoog@datadoghq.com>
@brettlangdon brettlangdon merged commit d2f5644 into 0.21-dev Feb 9, 2019
@brettlangdon brettlangdon deleted the kyle-verhoog/poi-hook branch February 9, 2019 02:46
@brettlangdon brettlangdon mentioned this pull request Feb 14, 2019
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

Successfully merging this pull request may close these issues.

None yet

2 participants