-
Notifications
You must be signed in to change notification settings - Fork 544
Using multiple DSNs, choosing based on the logger #198
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
Comments
What you can do is:
We don't have a good story right now for using multiple clients transparently, although explicitly rebinding clients is something that we do aim to support:
|
@untitaker : Finally picking this back up 😅, and thanks for the suggestion. I wanted to double-check my understanding of your workaround. The gist of it is that there will be three clients configured: two of which are configured just to have their DSN set properly so that we indirectly instantiate two HTTP transports, and then one more that is automatically configured via sentry_sdk.init which is fully configured correctly and uses a function as the transport that just switches between the two explicitly instantiated clients. However, a few things that seem off about this approach:
It seems like the thing I truly want looks closer to:
with usage like:
Getting a bit more in the weeds here, but does this approach seem sound? |
We have the same scenario - multiple projects for different types of issues/messages. Currently, we are just switching between two projects on the fly using sentry_sdk.init(). This seems to work just fine - but I'm pretty sure we are heavily leaking memory somewhere by doing this... Help please. :-) +1 |
@wss-chadical Calling @saifelse's approach is good, but whether it's suitable for you depends on whether you want to have separate client config besides DSN for each sentry project. |
btw sorry @saifelse for the lack of response. Passing a function as a transport is only used for testing purposes. I think your approach is fine. Something we could improve is to put a |
@untitaker I'll start with the close() - Thank you 👍 |
to be clear I still strongly recommend against this approach because it will likely impact perf. If you need multiple clients and can't use transports, I will post a solution but it takes a while to write. |
This is a data integration server (zato) - the transactional volume is not high - a little extra overhead is not a problem. If the hub.close reduces the thread/mem leaks it will work for us. |
Hub.current.client.close() has slowed the bleeding, but not stopped it. I decided to better understand the thread above... and it looks like I have it figured out. :-)
|
Yes, this can work as well. You might encounter odd issues since this will trim too large strings twice (because an event goes through two clients) but I am not sure if it even matters. It's certainly a flexible solution. |
that's good to know - I'll keep an eye on it. I do pass quite a bit of extra. It's very nice to have support here guys. @saifelse Thanks for getting this started! |
I'll close this since the original question has been answered by now. |
What is the easiest way to use multiple dsn nowadays? I do not need to configure somehow, I just need 2 dns supported simultaneously. |
@kiddick I'm still using the method from 4/19 |
We have the same use case, is there yet a supported way to implement this? |
Replaces our custom Sentry WSGI middleware with middleware shipped by sentry-sdk. Adds sentry-sdk ASGI middleware. Our custom sentry middleware also allowed logging slow requests to sentry. I have dropped this for now, and if we still want this in the future, we should probably implement this as a custom logging middleware instead, which would automatically appear in Sentry as well. We used to hardcode the log level for events to WARNING, and the Sentry default is ERROR now, which I think is a good idea. I've made this configurable using the sentry_event_level config variable. It does not seem to be possible to connect multiple dsn's in the same app, unless we start hacking (getsentry/sentry-python#198), so I dropped the custom_dsn from the sentry error reporting plugin (which has been broken anyway, so shouldn't be a big deal).
Replaces our custom Sentry WSGI middleware with middleware shipped by sentry-sdk. Adds sentry-sdk ASGI middleware. Our custom sentry middleware also allowed logging slow requests to sentry. I have dropped this for now, and if we still want this in the future, we should probably implement this as a custom logging middleware instead, which would automatically appear in Sentry as well. We used to hardcode the log level for events to WARNING, and the Sentry default is ERROR now, which I think is a good idea. I've made this configurable using the sentry_event_level config variable. It does not seem to be possible to connect multiple dsn's in the same app, unless we start hacking (getsentry/sentry-python#198), so I dropped the custom_dsn from the sentry error reporting plugin (which has been broken anyway, so shouldn't be a big deal).
Replaces our custom Sentry WSGI middleware with middleware shipped by sentry-sdk. Adds sentry-sdk ASGI middleware. Our custom sentry middleware also allowed logging slow requests to sentry. I have dropped this for now, and if we still want this in the future, we should probably implement this as a custom logging middleware instead, which would automatically appear in Sentry as well. We used to hardcode the log level for events to WARNING, and the Sentry default is ERROR now, which I think is a good idea. I've made this configurable using the sentry_event_level config variable. It does not seem to be possible to connect multiple dsn's in the same app, unless we start hacking (getsentry/sentry-python#198), so I dropped the custom_dsn from the sentry error reporting plugin (which has been broken anyway, so shouldn't be a big deal).
@untitaker Are the above approaches still valid? I stumbled over this, because I'm trying to migrate a project, which uses multiple DSNs, from the legacy raven sdk to the new sentry sdk and I've seen randomly occurring warnings in my pytests like this:
While digging through sentry's code I found out, that since 4/2019 there is a new |
@th3hamm0r you have to make a subclass of Transport and implement both of those methods to dispatch-and-defer similarly to how the function-based transports work. Either that or you disable sending of sessions and transactions, which will leave you only with error-monitoring. |
@untitaker hi! I also need to use two dnses.
But uncaught errors aren't logged anywhere with such configuration. Could you advice how to fix it? |
I have multiple clients working, but I get this error whenever the server refreshes or an error is captured
I tried implementing a custom transport but that was not successful. Anyone else solve this? |
@jeffchuber just implementing |
@sl0thentr0py thank you! did not think to check the discussions tab |
no worries! we just started using discussions for more 'support' like threads, so it's fairly new. |
I'm looking to upgrade from raven-python[flask] to sentry-sdk[flask]. We previous had two DSNs for our backend: one for errors and one to log performance issues (e.g. slow requests / high DB query count).
We were previously able to configure this via:
With the new architecture, this seems hard to do since the DSN is configured once via sentry_sdk.init where the LoggingIntegration simply listens to the root logger. I was able to hack around this by monkey-patching the logging_integration's handler as follows:
Two questions:
sentry_sdk.init
let you specify this mapping?The text was updated successfully, but these errors were encountered: