If you don't want to couple your code with a static class like
SentrySdk, especially to allow your code to be testable, you can use two abstractions:
ISentryClient: exposes the
CaptureEventmethod and its implementation
SentryClientis responsible for queueing the event to be sent to Sentry. It also abstracts away the internal transport.
IHub: holds a client and the current scope. In fact, it extends
ISentryClientand is able to dispatch calls to the right client depending on the current scope.
To allow different events to hold different contextual data, you need to know in which scope you are in, which is managed by the
Hub. It holds the scope management as well as a client.
If all you are only sending events without modification/access to the current scope, then you depend on
ISentryClient. If you would like to have access to the current scope by configuring it or binding a different client to it, you depend on
An example using
IHub for testability is SentryLogger and its unit tests SentryLoggerTests.
SentryLogger depends on
IHub because it does modify the scope (through
AddBreadcrumb). In case it only sent events, it should instead depend on
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").