Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

opentelemetry decorator #6

Closed
wants to merge 5 commits into from
Closed

opentelemetry decorator #6

wants to merge 5 commits into from

Conversation

rebkwok
Copy link
Contributor

@rebkwok rebkwok commented Mar 22, 2024

Pulling the @Instrument decorator from airlock into its own package so we can use it elsewhere.
The last commit does some refactoring and makes some improvements to how it finds attributes from function args.

Copy link
Member

@bloodearnest bloodearnest left a comment

Choose a reason for hiding this comment

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

The inspect based improvements in that last commit are really nice, great stuff!

However, I'm not sure about creating a separate dependency for this at this stage. I'd be tempted to let it bake in airlock for a bit before extracting, rather than having an extra dep?

Or are you thinking to release this on pypi as a general open source tool?

attributes_dict = attributes or {}
if func_attributes is not None:
func_signature = signature(func)
bound_args = func_signature.bind(*args, **kwargs).arguments
Copy link
Member

Choose a reason for hiding this comment

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

Huh, TIL. This is really quite nice!

# an argument for this parameter was not passed explicitly in the function call;
# look for a default value
param = func_signature.parameters.get(parameter_name)
if param and param.default is not Parameter.empty:
Copy link
Member

Choose a reason for hiding this comment

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

really slick!

@rebkwok
Copy link
Contributor Author

rebkwok commented Mar 22, 2024

@bloodearnest So, I pulled this out because of your comment about using it in job-server and job-runner too, and I didn't want to copy/paste the decorator code there. But maybe we're best to leave it in just airlock for a while first? I can just update airlock with the changes from the last commit and leave the separate package for now. It's complaining about dependencies on different python versions, and I think job-runner's still on 3.8.

There's nothing opensafely-specific if we were to make it a public package, but it'd probably need a better name.

@bloodearnest
Copy link
Member

@bloodearnest So, I pulled this out because of your comment about using it in job-server and job-runner too, and I didn't want to copy/paste the decorator code there.

Ah, sorry, yes, I meant it "at some point"! But the improvements from working on it are great.

But maybe we're best to leave it in just airlock for a while first? I can just update airlock with the changes from the last commit and leave the separate package for now. It's complaining about dependencies on different python versions, and I think job-runner's still on 3.8.

I just saw and reviewed your PR, nice.

There's nothing opensafely-specific if we were to make it a public package, but it'd probably need a better name.

Agreed, I think it might be worth doing the work to release to the world, but maybe it can wait until post-initiative deck scrubbing?

By using the inspect module to identify the bound arguments passed
to the function, we don't need to separate arg and kwarg attributes,
and we can handle cases different types of function call, where
keywords aren't enforced. We can also now handle keywords captured in
a **kwargs parameter.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants