Send error reports to bugsnag.
import BugsnagElm exposing (Bugsnag)
import Task exposing (Task)
-- initialize bugsnag. You will probably need to pull values from the env or flags
bugsnag : Bugsnag
bugsnug =
BugsnagElm.start
{ apiKey = "abcdef1234...."
, appVersion = "xyz0101010......"
, releaseStage = "test"
, enabledReleaseStages = ["production", "staging", "test"]
, user =
Just
{ id = flags.currentUserId
, username = flags.username
, email = flags.email
}
}
-- send error reports within your app's update function
update msg model =
.... ->
-- log some debug info
( model
, bugsnag.info
"Hitting the slothNinja API."
"Page.Customer.Login.Main"
Dict.empty
|> Task.attempt (\() -> NoOp) -- convert the Task into a Cmd
)
.... ->
-- log an error
( model
, [ ( "Payload", toString payload ) ]
|> Dict.fromList
|> bugsnag.error
"Unexpected payload from the slothNinja API."
"Page.Customer.Login.Main"
|> Task.attempt (\() -> NoOp) -- convert the Task into a Cmd
)
start : BugsnagConfig -> Bugsnag
Return a Bugsnag
record configured with the given BugsnagConfig details.
bugsnag = BugsnagElm.start
{ apiKey = "abcdef1234...."
, appVersion = "xyz0101010......"
, releaseStage = "test"
, enabledReleaseStages = ["production", "staging", "test"]
, user =
Just
{ id = "42"
, username = "Grace Hopper"
, email = "support@bugsnag.com"
}
}
{ error : String -> String -> Dict String Json.Encode.Value -> Task Http.Error ()
, warning : String -> String -> Dict String Json.Encode.Value -> Task Http.Error ()
, info : String -> String -> Dict String Json.Encode.Value -> Task Http.Error ()
}
Functions preapplied with apiKey, code version, user info and releaseStage,
separated by Severity
.
Create one using start
, and then throughout your app you can call bugsnag.error
to send the error report.
When calling any of the functions herein, it will return Task.succeed ()
if the message was successfully sent to Bugsnag. Otherwise it fails with the Http.Error
responsible. I recommend you ignore the error in your code; although it is possible for the bugsnag api to go down, it is exceedingly rare, and not something worth disrupting your user's experience for.
bugsnag.error "problem accessing the database." "Page.Checkout" Dict.empty
|> Task.attempt (\() -> NoOp) -- convert the Task into a Cmd
{ apiKey : String
, appVersion : String
, releaseStage : String
, enabledReleaseStages : List String
, user : Maybe User
}
Basic data needed to define the local client for a BugsnagElm instance.
Applies to all error reports that may occur in the app,
with error-specific data added later in notify
apiKey
- The Bugsnag API apiKey required to authenticate the request.appVersion
- However your app identifies its versions, include it here as a stringreleaseStage
- usually "production"
, "development"
, "staging"
, etc., but bugsnag accepts any valueenabledReleaseStages
- explictly define which stages you want to report, omitting any you'd prefer to drop (e.g. "development"). Empty list will report ALL error stages.user
- if available, report default user data (id, name, email){ id : String
, username : String
, email : String
}
A record of datapoints bugsnag's api can accept for user data.
To display additional custom user data alongside these standard fields on the Bugsnag website,
the custom data should be included in the 'metadata' object in a user
object.
learn more
Severity levels - bugsnag only accepts these three.
notify : BugsnagConfig -> Severity -> String -> String -> Dict String Json.Encode.Value -> Task Http.Error ()
Send a message to bugsnag. start
provides a nice wrapper around this.
Arguments:
BugsnagConfig
Severity
- severity, one of: Error
, Warning
, or Info
String
- message, e.g. "Auth server was down when user tried to sign in."String
- context, where the error occurred e.g. module or file name "Page.Customer.Login.Main"Dict String Value
- arbitrary metadata, e.g. `{"accountType": "premium", "region": "NW"}If the message was successfully sent to Bugsnag, it returns Task.succeed ()
Otherwise it fails with the Http.Error
responsible. I recommend you ignore this error in your code; although it is possible for the bugsnag api to go down, it is exceedingly rare, and not something worth disrupting your user's experience for.
notify bugsnagConfig Error "cannot connect to database" "Page.Login" Dict.empty