packages feed

bugsnag-types-1.1.0.1: src/Data/Bugsnag/Types/Event.hs

module Data.Bugsnag.Types.Event
  ( Event (..)
  , exampleEvent
  ) where

import Data.Bugsnag.Types.Prelude

import Data.Bugsnag.Types.Exception
import Data.Bugsnag.Types.Breadcrumb
import Data.Bugsnag.Types.Request
import Data.Bugsnag.Types.Thread
import Data.Bugsnag.Types.Severity
import Data.Bugsnag.Types.SeverityReason
import Data.Bugsnag.Types.User
import Data.Bugsnag.Types.Application
import Data.Bugsnag.Types.Device
import Data.Bugsnag.Types.Session
import Data.Bugsnag.Types.FeatureFlag

data Event = Event
  { exceptions :: [Exception]
  -- ^ An array of exceptions that occurred during this event. There must be at
  -- least one entry. Most of the time there will only be one exception, but
  -- some languages support \"nested\" or \"caused by\" exceptions. In this
  -- case, exceptions should be unwrapped and added to the array one at a
  -- time. The array should be in order from the outermost error to the
  -- innermost. For example, the first element in the array should be the
  -- error caused by the second element, and so on.
  , breadcrumbs :: Maybe [Breadcrumb]
  -- ^ An array of user- and system-initiated events which led up to an error,
  -- providing additional context. This list is sequential and ordered newest
  -- to oldest.
  , request :: Maybe Request
  , threads :: Maybe [Thread]
  -- ^ An array of background threads. This is optional but recommended for
  -- apps that rely heavily on threading. Threads should be in an order that
  -- makes sense for your application.
  , context :: Maybe Text
  -- ^ A string representing what was happening in the application at the time
  -- of the error. This string could be used for grouping purposes, depending
  -- on the event. Usually this would represent the controller and action in
  -- a server based project. It could represent the screen that the user was
  -- interacting with in a client side project. For example:
  --
  -- -   On Ruby on Rails the context could be @controller#action@.
  --
  -- -   In Android, the context could be the top most Activity.
  --
  -- -   In iOS, the context could be the name of the top most
  --     UIViewController.
  , groupingHash :: Maybe Text
  -- ^ The
  -- <https://docs.bugsnag.com/product/error-grouping default error grouping>
  -- can be overridden by specifying a custom grouping hash.
  , unhandled :: Maybe Bool
  -- ^ Whether the error was unhandled. If true, the error was detected by the
  -- notifier because it was not handled by the application. If false, the
  -- errors was handled and reported using Bugsnag.notify.
  , severity :: Maybe Severity
  -- ^ The severity of the error
  --
  -- -   @error@ - The default for unhandled errors.
  --
  -- -   @warning@ - The default when Bugsnag.notify is called.
  --
  -- -   @info@ - Can be used in manual Bugsnag.notify calls.
  , severityReason :: Maybe SeverityReason
  , projectPackages :: Maybe [Text]
  -- ^ Sets which package names should be considered as a part of the running
  -- application. We mark stacktrace lines as in-project if they originate
  -- from any of these packages and this allows us to improve the visual
  -- display of the stacktrace on the dashboard.
  , user :: Maybe User
  , app :: Maybe Application
  , device :: Maybe Device
  , session :: Maybe Session
  , featureFlags :: Maybe [FeatureFlag]
  -- ^ Details of the feature flags (experiments) and associated variants that
  -- were active when the error occurred.
  , metaData :: Maybe (KeyMap (KeyMap Text))
  -- ^ An object containing any further data you wish to attach to this error
  -- event. This should contain one or more objects, with each object being
  -- displayed in its own tab on the event details on the dashboard.
  --
  -- >   {
  -- >       // Custom user data to be displayed in the User tab along with standard
  -- >       // user fields on the dashboard.
  -- >       "user": {
  -- >          ...
  -- >       },
  -- >
  -- >       // Custom app data to be displayed in the App tab along with standard
  -- >       // app fields on the dashboard.
  -- >       "app": {
  -- >          ...
  -- >       },
  -- >
  -- >       // Custom device data to be displayed in the Device tab along with
  -- >       //standard device fields on the dashboard.
  -- >       "device": {
  -- >          ...
  -- >       },
  -- >
  -- >       Custom request data to be displayed in the Request tab along with
  -- >       standard request fields on the dashboard.
  -- >       "request": {
  -- >          ...
  -- >       },
  -- >
  -- >       // This will be displayed as an extra tab on the dashboard.
  -- >       "Some data": {
  -- >
  -- >           // A key value pair that will be displayed in the first tab.
  -- >           "key": "value",
  -- >
  -- >           // Key value pairs can be contained in nested objects which helps
  -- >           // to organize the information presented in the tab.
  -- >           "setOfKeys": {
  -- >               "key": "value",
  -- >               "key2": "value"
  -- >           }
  -- >       },
  -- >
  -- >       // This would be the second extra tab on the dashboard.
  -- >       "Some more data": {
  -- >           ...
  -- >       }
  -- >   }
  }
  deriving stock (Eq, Show, Generic)

instance FromJSON Event where
  parseJSON = genericParseJSON aesonOptions

instance ToJSON Event where
  toJSON = genericToJSON aesonOptions
  toEncoding = genericToEncoding aesonOptions

exampleEvent :: Event
exampleEvent = Event
  { exceptions = [exampleException]
  , breadcrumbs = Just [exampleBreadcrumb]
  , request = Just exampleRequest
  , threads = Just [exampleThread]
  , context = Just "auth/session#create"
  , groupingHash = Just "buggy_file.rb"
  , unhandled = Just True
  , severity = Just exampleSeverity
  , severityReason = Just exampleSeverityReason
  , projectPackages = Just ["com.example.package1","com.example.package2"]
  , user = Just exampleUser
  , app = Just exampleApplication
  , device = Just exampleDevice
  , session = Just exampleSession
  , featureFlags = Just [exampleFeatureFlag]
  , metaData = Nothing
  }