Unit Testing
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 theCaptureEvent
method and its implementationSentryClient
is 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 extendsISentryClient
and 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 IHub
.
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 ISentryClient
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
- Package:
- nuget:Sentry.AzureFunctions.Worker
- Version:
- 3.33.0-beta.1
- Repository:
- https://github.com/getsentry/sentry-dotnet