8000 feat: Bottle integration by shenek · Pull Request #300 · getsentry/sentry-python · GitHub
[go: up one dir, main page]

Skip to content

feat: Bottle integration #300

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

Merged
merged 8 commits into from
Mar 29, 2019
Merged

Conversation

shenek
Copy link
Contributor
@shenek shenek commented Mar 21, 2019

After some struggle I was finally able to prepare this MR, which provides some basic integration with Bottle web framework.

I was mostly inspired by Flask and Pyramid integrations source code.
The code itself doesn't handle any session/login logic and it contains a few bottle specific stuff.

In a couple of days I plan to do some real life testing and I tend to prepare some kind of a tutorial.

Right now I will be grateful for any feedback or advice.

@shenek shenek changed the title Bottle intergration feat: Bottle intergration Mar 21, 2019
@shenek shenek force-pushed the bottle_intergration branch 2 times, most recently from 37424a8 to ff17437 Compare March 21, 2019 18:15
shenek added 2 commits March 22, 2019 09:59
* inspired by flask and pyramid framework integrations
* doesn't contain any login handling logic
@shenek shenek force-pushed the bottle_intergration branch from ff17437 to 243d260 Compare March 22, 2019 08:59
Copy link
Member
@untitaker untitaker left a comment

Choose a reason for hiding this comment

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

This seems great! I left some comments though. If you want to start writing docs for this, these PRs should give you a clue: https://github.com/getsentry/sentry-docs/pulls?utf8=%E2%9C%93&q=is%3Apr+author%3Auntitaker+is%3Aclosed+python

# to monkey patch route.call
old_match = self.router.match

def patched_match(self, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

All this patching is occuring within sentry_patched_wsgi_app, but it should occur outside of it. There's no reason to patch on every request unless I am missing something.

Fixing this should make the use of types.MethodType unnecessary as well.

Copy link
Contributor Author
@shenek shenek Mar 26, 2019

Choose a reason for hiding this comment

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

I agree the patching done in this way is not really nice and a bit confusing. I tried to patch the other functions outside of sentry_patched_wsgi_app and I was more or less successful.

Just instead of Route.call (which is a cached_property) I managed to patch Router._make_callback. The tests on my machine seem to work.

# if the request is gone we are fine not logging the data from
# it. This might happen if the processor is pushed away to
# another thread.
if request is None:
Copy link
Member
@untitaker untitaker Mar 25, 2019

Choose a reason for hiding this comment

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

This can never be None, it will always be that singleton instance of bottle.LocalRequest.

In Flask this exists because we make a weakref of the current request object, such that when a user copies the scope explicitly to a new thread or even into a job queue, the original request data is still there as long as the request is still alive (and not the current request from a thread that probably doesn't have request data). I am not sure if we can get a request object without threadlocals from a LocalRequest, but it doesn't seem so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. Thanks for the explanation.

@shenek
Copy link
Contributor Author
shenek commented Mar 26, 2019

Thanks for the review. I'll try to process all the comments shortly. Also thanks for the documentation hint/link.

@shenek shenek force-pushed the bottle_intergration branch from b04be8d to cae0a96 Compare March 26, 2019 08:23
test only 0.x version (not every bugfix)
@shenek shenek force-pushed the bottle_intergration branch from cae0a96 to 9297aac Compare March 26, 2019 08:29
shenek added 3 commits March 26, 2019 09:53
using handy `transaction_from_function` function
useless `request is None` comparison removed
@untitaker
Copy link
Member

Almost there.

  • We can ignore OSX, it's broken on Travis
  • Could you run formatting? CONTRIBUTING.md should have some commands to enable this

@shenek
Copy link
Contributor Author
shenek commented Mar 26, 2019

I just pushed two other fixups. The first updates the patching a bit and the second should reformat the source code using make format.

@untitaker
Copy link
Member

LGTM, however I can't release without docs. If you need assistance let me know

@shenek
Copy link
Contributor Author
shenek commented Mar 27, 2019

Thanks. I'll look into it.

@shenek
Copy link
Contributor Author
shenek commented Mar 28, 2019

I just managed to prepare a pull request for the docs. see getsentry/sentry-docs#867

@untitaker
Copy link
Member
untitaker commented Mar 29, 2019

@shenek I would plan to merge + release this as-is. This is really great work.

In a couple of days I plan to do some real life testing and I tend to prepare some kind of a tutorial.

Any updates here?

@shenek
Copy link
Contributor Author
shenek commented Mar 29, 2019

Thanks.

I tried to hook some sample application against a production sentry instance and it seems that it captures events.

sentry-captured

sentry-bottle-detail

I plan to do some more test during next week.

@untitaker untitaker changed the title feat: Bottle intergration feat: Bottle integration Mar 29, 2019
@untitaker untitaker merged commit 8e63b3f into getsentry:master Mar 29, 2019
@untitaker
Copy link
Member
untitaker commented Mar 29, 2019 via email

@untitaker
Copy link
Member

@shenek so this is out as 0.7.9: https://sentry.io/for/bottle/

@shenek
Copy link
Contributor Author
shenek commented Apr 1, 2019

Super. Thank you very much for your help.

@shenek shenek deleted the bottle_intergration branch April 2, 2019 15:11
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.

2 participants
0