Skip to content

Trytond integration #548

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 35 commits into from
Jan 7, 2020
Merged

Trytond integration #548

merged 35 commits into from
Jan 7, 2020

Conversation

n1ngu
Copy link
Contributor

@n1ngu n1ngu commented Nov 8, 2019

Sentry SDK integration for the Trytond ERP framework

@n1ngu
Copy link
Contributor Author

n1ngu commented Nov 8, 2019

Waiting for Tryton community feedback https://discuss.tryton.org/t/sentry-sdk-integration/1925

@n1ngu
Copy link
Contributor Author

n1ngu commented Nov 8, 2019

Regarding the failed checks:

  • the Python-3.5 fail is due to a str vs bytes issue
  • the Python-3.4 fail is due to the trytond>5.0 package not being distributed for that version
  • the Python-2.7 and the PyPy failures are rather unexpected because AFAIU they were out of the contributed dependency matrix

If the community agrees, I would settle for the easy solution: only supporting python>=3.6

@untitaker
Copy link
Member

@n1ngu it's ok to remove py3.4-trytond-5.0 from the matrix by having multiple lines (see django)

@untitaker
Copy link
Member

In my eyes there should be no reason to call init() from an integration. This is something we want to enforce for all stable integrations as doing otherwise requires us to replicate the API of init() somewhere else. If people use your logging handler to initialize the SDK, how do they configure before_send or any other option that takes more complex arguments than a DSN?

@n1ngu
Copy link
Contributor Author

n1ngu commented Nov 18, 2019

In my eyes there should be no reason to call init() from an integration. This is something we want to enforce for all stable integrations as doing otherwise requires us to replicate the API of init() somewhere else. If people use your logging handler to initialize the SDK, how do they configure before_send or any other option that takes more complex arguments than a DSN?

That's a good point. This handler should be understood not as a framework integration but as a mean to inject code in tools that won't allow it. Obviously, if the default sdk initialization does not suffice for a particular purpose, neither will this handler. If this is a concern and such a feature was not acceptable for the core sdk I will retire it from this PR so we can focus on the actual trytond wsgi integration above! (but I'll still vendor it in my deployments 😁)

Regarding complex init() options: The "ignored_loggers" feature is already beyond my initial will, it is present because I felt it was extremely straightforward. With a similar schema, other init() options could be exposed, but obviously its complexity grows as with a need for a fair amount of documentation.

That's why I'd settle for the "use this only if the default init() suffices you" as an out-of-the-box mechanism to power people to use Sentry with not easily-hackable tools, even if the Sentry setup is not fully customizable.

@n1ngu
Copy link
Contributor Author

n1ngu commented Nov 18, 2019

@untitaker Stated with different words: this handler could be shipped alongside the EventHandler and BreadcrumbHandler in the sentry_sdk.integrations.logging module. Not to power full Sentry customization but to ease a naive Sentry initialization in honor to your own documentation:

Usually, you don’t need this. You can use this together with default_integrations=False if you want to opt into what the Sentry Python SDK captures. However, correctly setting up logging is difficult. Also, an opt-in approach to capturing data will miss errors you may not think of on your own.
( https://docs.sentry.io/platforms/python/logging/#handler-classes )

The alternative for this kind of not easily-hackable tools is a tedious logging config setup with the EventHandler, and still with the problem of "where to state the DSN"

@untitaker
Copy link
Member

@n1ngu I would much rather separate the discussion of alternative initialization methods from getting this integration merged. The former is more controversial imo

@untitaker
Copy link
Member

@n1ngu could you open a pr against https://github.com/getsentry/sentry-docs?

@untitaker
Copy link
Member

Example PR: getsentry/sentry-docs#867

@untitaker
Copy link
Member

untitaker commented Nov 27, 2019 via email

@n1ngu n1ngu requested a review from untitaker December 7, 2019 19:13
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.

@n1ngu could you open a PR against https://github.com/getsentry/sentry-docs? A good example for adding docs for a new integration is getsentry/sentry-docs#867

@untitaker
Copy link
Member

I tried to push this but failed bc the PR is not editable for me:

diff --git a/sentry_sdk/integrations/trytond.py b/sentry_sdk/integrations/trytond.py
index 152e879..c1a669a 100644
--- a/sentry_sdk/integrations/trytond.py
+++ b/sentry_sdk/integrations/trytond.py
@@ -4,10 +4,14 @@ import sentry_sdk.hub
 import sentry_sdk.utils
 import sentry_sdk.integrations
 import sentry_sdk.integrations.wsgi
+from sentry_sdk._types import MYPY
 
 from trytond.exceptions import TrytonException  # type: ignore
 from trytond.wsgi import app  # type: ignore
 
+if MYPY:
+    from typing import Any
+
 
 # TODO: trytond-worker, trytond-cron and trytond-admin intergations
 
@@ -25,12 +29,19 @@ class TrytondWSGIIntegration(sentry_sdk.integrations.Integration):
 
         def error_handler(e):  # type: (Exception) -> None
             hub = sentry_sdk.hub.Hub.current
+
             if hub.get_integration(TrytondWSGIIntegration) is None:
                 return
             elif isinstance(e, TrytonException):
                 return
             else:
-                (event, hint) = sentry_sdk.utils.event_from_exception(sys.exc_info())
+                # If an integration is there, a client has to be there.
+                client = hub.client  # type: Any
+                event, hint = sentry_sdk.utils.event_from_exception(
+                    sys.exc_info(),
+                    client_options=client.options,
+                    mechanism={"type": "trytond", "handled": False},
+                )
                 hub.capture_event(event, hint=hint)
 
         # Expected error handlers signature was changed

could you apply it manually?

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.

pending:

  • changes as per prev comment need to be applied, otherwise certain init() options do not work with this integration
  • docs

rest lgtm

@n1ngu n1ngu requested a review from untitaker December 9, 2019 15:26
# If an integration is there, a client has to be there.
client = hub.client # type: Any
event, hint = sentry_sdk.utils.event_from_exception(
e,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched back to build the event from the caught exception instead of sys.exc_info() because it feels more elegant to me. Does using sys.exc_info() have any advantatge I am missing?

Copy link
Member

Choose a reason for hiding this comment

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

Under Python 2 this will cause you to lose the traceback, but it should be fine in this context.

@untitaker
Copy link
Member

fwiw this is blocked on the doc changes

@n1ngu
Copy link
Contributor Author

n1ngu commented Jan 7, 2020

My bad. I am aware the ball is in my court. I can only spend here some spare work hours, plus I've been on vacation. But hopefully I'll have the documentation sorted in the short term!

@untitaker untitaker merged commit 1b8644b into getsentry:master Jan 7, 2020
@untitaker
Copy link
Member

Gonna get this out and document later

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.

4 participants