Interface ErrorContext
-
public interface ErrorContext
This library provides an easy way to store application errors in your service's local (e.g. Postgres) database. This interface defines the general contract, and instances are built usingErrorContextBuilder
.This acts much like a Dropwizard bundle in that it creates an
ApplicationErrorDao
for use anywhere in your application, and registers anApplicationErrorResource
which exposes application errors via REST. TheerrorDao()
method provides the DAO once anErrorContext
has been built by one of the build methods inErrorContextBuilder
.It also registers a health check that reports healthy if no errors have occurred in a configurable time window. The default value is the last 15 minutes. If desired, you can disable the creation of the health check by calling
ErrorContextBuilder.skipHealthCheck()
when constructing the instance.We currently support storing errors to a relational database with JDBI 3. If your application does not currently have a database or uses something else, then we also provide an option to use an in-memory H2 database.
JDBI Note: To start creating application errors you will first need to create the database table (unless you are using the in-memory H2 database). See
dropwizard-app-errors-migrations.xml
in the source code for more details; this is a Liquibase migration file. Once the table exists, build an instance usingErrorContextBuilder
. You can then supply theApplicationErrorDao
to anywhere in your application, e.g. other services or DAOs, resources, etc. Once your application has started, clients can retrieve and resolve application errors via the REST endpoint.- See Also:
ErrorContextBuilder
- Implementation Note:
- The reason this is not a Dropwizard bundle is mainly because it would not have the necessary
components (such as a Dropwizard
DataSourceFactory
or JDBI 3Jdbi
instance) during the Dropwizard bundle initialization lifecycle.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description DataStoreType
dataStoreType()
Return the type of data store this instance uses.ApplicationErrorDao
errorDao()
Return theApplicationErrorDao
singleton that can be shared by an entire application.Optional<RecentErrorsHealthCheck>
recentErrorsHealthCheck()
Return theRecentErrorsHealthCheck
, mainly so that the time window information can be obtained if it is needed for some reason, e.g.
-
-
-
Method Detail
-
dataStoreType
DataStoreType dataStoreType()
Return the type of data store this instance uses.- Returns:
- the
DataStoreType
-
errorDao
ApplicationErrorDao errorDao()
Return theApplicationErrorDao
singleton that can be shared by an entire application.- Returns:
- the thread-safe ApplicationErrorDao
-
recentErrorsHealthCheck
Optional<RecentErrorsHealthCheck> recentErrorsHealthCheck()
Return theRecentErrorsHealthCheck
, mainly so that the time window information can be obtained if it is needed for some reason, e.g. logging it at application startup. Note ifErrorContextBuilder.skipHealthCheck()
was called this will return an emptyOptional
.- Returns:
- an Optional containing the
RecentErrorsHealthCheck
, or an empty Optional
-
-