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

How can I send events to two different projects from my python code #1000

Closed
yossivainshtein opened this issue Feb 7, 2021 · 1 comment
Closed

Comments

@yossivainshtein
Copy link

Currently, I write error events from my python component to a sentry project.
The way I do this is by adding to logger a handler which writes to sentry.

The code is along those lines:

   class _SentryioHandler(logging.Handler):
        def emit(self, record):
            sentry_sdk.capture_message(self.format(record))
...
    def initialize_logger():
       sentry_sdk.init(dsn=SENTRY_URL,
                            release=f"{env}@{release_major_version}",
                            environment=env,
                            integrations=[SqlalchemyIntegration(), TornadoIntegration(), AioHttpIntegration()])
       with sentry_sdk.configure_scope() as scope:
                scope.set_tag("release-version", release_version)
                scope.set_tag("backend-version", backend_version)

        handler_sentryio = self._SentryioHandler()
        handler_sentryio.setLevel(logging.ERROR)

        self.default_logger = logging.getLogger("default_logger")
        self.default_logger.addHandler(handler_sentryio)

Now I'd like to send some events to a different project, depending on some condition (In my case, one of the event sources sends a lot of events and I want to separate them for clarity, but it can be any condition).

Is there a recommended/supported way to do this?
because the way I use it right now, I call sentry_sdk.initjust once with the project URL, and then use sentry_sdk.capture_message to send it.

I saw this issue, but I'm not sure whether the ways suggested there are officially supported? Also, they rely quite a bit on the current implementation. Is there a recommended way to achieve this?

Thanks

@untitaker
Copy link
Member

both the solution by saifelse and the one I posted should work. We don't have a recommended way to do this, but are working on serverside solutions to throttle traffic based on conditions at the moment.

Aside I would use our own log handlers instead of writing your own.

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