Documentation ¶
Overview ¶
Package bugsnag exposes an alternative implementation of the Bugsnag Go notifier.
Create a new *bugsnag.Notifier:
n, err := bugsnag.New(bugsnag.Configuration{ APIKey: "<<YOUR API KEY HERE>>", AppVersion: "1.3.5", // Some semver ReleaseStage: "production", }) if err != nil { panic(err) } defer n.Close() // Close once you know there are no further calls to n.Notify or n.StartSession.
Note: There are other configuration options you may set, which enable some advanced and very powerful features of the Notifier. See bugsnag.Configuration for more information.
After creating the notifier, you can then report any errors that appear in your application:
n.Notify(ctx, err)
You can attach a lot of useful data to context.Context instances that get reflected in your dashboard. See the various With*(ctx, ...) funcs for more details. You can also attach a stacktrace to your errors by calling
err = Wrap(ctx, err)
to wrap another error. Another benefit of using Wrap is that the diagnostic data attached to the ctx given in the call to Wrap is preserved in the returned err. Meaning that you can call n.Notify in a single location without worrying about losing the location of the original error or the diagnostic data that was available at that point in time. If you are reporting a panic or errors you were unable to handle, then you may set the Panic and Unhandled fields of the *bugsnag.Error returned from Wrap.
To start using session tracking to enable your stability score calculation you should call n.StartSession on a per-request basis.
ctx = n.StartSession(ctx)
Index ¶
- Constants
- type Breadcrumb
- type Configuration
- type Error
- type ErrorReportSanitizer
- type JSONApp
- type JSONBreadcrumb
- type JSONDevice
- type JSONErrorReport
- type JSONEvent
- type JSONException
- type JSONNotifier
- type JSONRequest
- type JSONSession
- type JSONSessionCounts
- type JSONSessionEvents
- type JSONSessionReport
- type JSONSeverityReason
- type JSONStackframe
- type JSONUser
- type Notifier
- func (n *Notifier) Close()
- func (n *Notifier) Deserialize(ctx context.Context, data []byte) context.Context
- func (n *Notifier) Metadata(ctx context.Context) map[string]map[string]interface{}
- func (n *Notifier) Notify(ctx context.Context, err error)
- func (n *Notifier) Serialize(ctx context.Context) []byte
- func (n *Notifier) StartSession(ctx context.Context) context.Context
- func (n *Notifier) WithBreadcrumb(ctx context.Context, breadcrumb Breadcrumb) context.Context
- func (n *Notifier) WithBugsnagContext(ctx context.Context, bContext string) context.Context
- func (n *Notifier) WithMetadata(ctx context.Context, tab string, data map[string]interface{}) context.Context
- func (n *Notifier) WithMetadatum(ctx context.Context, tab, key string, value interface{}) context.Context
- func (n *Notifier) WithUser(ctx context.Context, user User) context.Context
- func (n *Notifier) Wrap(ctx context.Context, err error, msgAndFmtArgs ...interface{}) error
- type SessionReportSanitizer
- type User
Constants ¶
const ( // BCTypeManual is the type of breadcrumb representing user-defined, // manually added breadcrumbs BCTypeManual bcType = iota // listed first to make it the default // or content being displayed, with a defined destination and optionally a // previous location. BCTypeNavigation // BCTypeRequest is the type of breadcrumb representing sending and // receiving requests and responses. BCTypeRequest // BCTypeProcess is the type of breadcrumb representing performing an // intensive task or query. BCTypeProcess // BCTypeLog is the type of breadcrumb representing messages and severity // sent to a logging platform. BCTypeLog // BCTypeUser is the type of breadcrumb representing actions performed by // the user, like text input, button presses, or confirming/canceling an // alert dialog. BCTypeUser // BCTypeState is the type of breadcrumb representing changing the overall // state of an app, such as closing, pausing, or being moved to the // background, as well as device state changes like memory or battery // warnings and network connectivity changes. BCTypeState // BCTypeError is the type of breadcrumb representing an error which was // reported to Bugsnag encountered in the same session. BCTypeError )
const ( // SeverityInfo indicates that the severity of the Error is "info" SeverityInfo severity // SeverityWarning indicates that the severity of the Error is "warning" SeverityWarning // SeverityError indicates that the severity of the Error is "error" SeverityError )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Breadcrumb ¶
type Breadcrumb struct { // A short summary describing the breadcrumb, such as entering a new // application state Name string `json:"na"` // Type is a category which describes the breadcrumb, from the list of // allowed values. Accepted values are of the form bugsnag.BCType*. Type bcType `json:"ty"` // Metadata contains any additional information about the breadcrumb, as // key/value pairs. Metadata map[string]interface{} `json:"md"` // Timestamp is set automatically to the current timestamp if not set. Timestamp time.Time `json:"ts"` }
Breadcrumb represents user- and system-initiated events which led up to an error, providing additional context.
type Configuration ¶
type Configuration struct { // The 32 hex-character API Key that identifies your Bugsnag project. APIKey string // The version of your application, as semver. // **Strictly** speaking, Bugsnag doesn't require you to use semver, but in // Go this is **highly** recommended (esp. with go mod). If you absolutely // *have* to use a non-semver AppVersion, set this configuration option to // any valid semver, and change the AppVersion as part of of your // ErrorReportSanitizer. AppVersion string // The stage in your release cycle, e.g. "development", "production", etc. // Any non-empty value is valid. // **Strictly** speaking, Bugsnag doesn't require you to set this field. // However, **a lot** of the features in Bugsnag are // significantly improved by setting this field, so it is required in this // package. ReleaseStage string // The endpoint to send error reports to. Configure if you're // using an on-premise installation of Bugsnag. Defaults to // https://notify.bugsnag.com // If this field is set you must also set EndpointSessions. EndpointNotify string // The endpoint to send sessions to. Configure if you're using an // on-premise installation of Bugsnag. Defaults to // https://sessions.bugsnag.com // If this field is set you must also set EndpointNotify. EndpointSessions string // If defined it will be invoked just before each error report API call to // Bugsnag. See the GoDoc on the ErrorReportSanitizer type for more details. ErrorReportSanitizer ErrorReportSanitizer // If defined it will be invoked just before each session report API call // to Bugsnag. See the GoDoc on the SessionReportSanitizer type for more details. SessionReportSanitizer SessionReportSanitizer // InternalErrorCallback gets invoked with a descriptive error for any // internal issues in the notifier that's preventing normal operation. // Configuring this function may be useful if you need to debug missing // reports or sessions. InternalErrorCallback func(err error) // contains filtered or unexported fields }
Configuration represents all of the possible configurations for the notifier. Only APIKey, AppVersion, and ReleaseStage is required.
type Error ¶
type Error struct { Unhandled bool Panic bool Severity severity // contains filtered or unexported fields }
Error allows you to specify certain properties of an error in the Bugsnag dashboard. Setting Unhandled to true indicates that the application was not able to gracefully handle an error or panic that occurred in the system. This will make the reported error affect your app's stability score. Setting panic to true indicates that the application experienced a (caught) panic, as opposed to just reporting an error. You may specify what severity your error should be reported with. Values can be one of SeverityInfo, SeverityWarning, and SeverityError. The default severity for unhandled or panicking Errors is "error", and "warning" otherwise.
type ErrorReportSanitizer ¶
type ErrorReportSanitizer func(ctx context.Context, p *JSONErrorReport) error
ErrorReportSanitizer allows you to modify the payload being sent to Bugsnag just before it's being sent. The ctx param provided will be the ctx from the deepest location where Wrap is called, falling back to the ctx given to Notify. You may return a non-nil error in order to prevent the payload from being sent at all. This error is then forwarded to the InternalErrorCallback. No further modifications to the payload will happen to the payload after this is run.
type JSONApp ¶ added in v0.3.0
type JSONApp struct { // ID is a unique ID for the application ID string `json:"id,omitempty"` // Version number of the application which generated the error. Version string `json:"version,omitempty"` // ReleaseStage is the release stage (e.g. "staging" or "production") // Should be set to "production" by default. ReleaseStage string `json:"releaseStage,omitempty"` // Type is the specialized type of the application, such as the worker // queue or web framework used. Type string `json:"type,omitempty"` // Duration is how long the app has been running for in milliseconds. Duration int64 `json:"duration"` }
JSONApp is information about the app where the error occurred. These fields are optional but highly recommended. To display custom app data alongside these standard fields on the Bugsnag website, the custom data should be included in the metaData object in an app object.
type JSONBreadcrumb ¶ added in v0.3.0
type JSONBreadcrumb struct { // The time at which the event breadcrumb occurred, in ISO8601 Timestamp string `json:"timestamp,omitempty"` // A short summary describing the breadcrumb, such as entering a new application state Name string `json:"name"` // Type is a category which describes the breadcrumb, from the list of allowed values. // Accepted values are: ["navigation", "request", "process", "log", "user", "state", "error", "manual"] Type string `json:"type"` // Metadata contains any additional information about the breadcrumb, as key/value pairs. Metadata map[string]interface{} `json:"metaData,omitempty"` }
JSONBreadcrumb represents user- and system-initiated events which led up to an error, providing additional context.
type JSONDevice ¶ added in v0.3.0
type JSONDevice struct { // Rather than faff about with trying to find something that matches the // API exactly, just fit all easily fetchable metric data and abuse // the fact you can just add to the device struct whatever you want. // Obviously, this may well stop working in the future. RuntimeMetrics map[string]interface{} `json:"runtimeMetrics,omitempty"` // GoroutineCount is the number of goroutines running in the app at the // time that Notify was called. GoroutineCount int `json:"goroutineCount,omitempty"` // Hostname of the server running your code. Hostname string `json:"hostname,omitempty"` // OSName is the name of the operating system. OSName string `json:"osName,omitempty"` // OSVersion is the version of the operating system, only applies to *NIX // systems, as defined by "uname -r". OSVersion string `json:"osVersion,omitempty"` RuntimeVersions map[string]string `json:"runtimeVersions"` }
JSONDevice is information about the computer/device running the app. These fields are optional but highly recommended. To display custom device data alongside these standard fields on the Bugsnag website, the custom data should be included in the metaData object in a device object.
type JSONErrorReport ¶ added in v0.3.0
type JSONErrorReport struct { // The API Key associated with the project. Informs Bugsnag which project has generated this error. // This is provided for legacy notifiers. It is preferable to use the Bugsnag-Api-Key header instead. APIKey string `json:"apiKey"` Notifier *JSONNotifier `json:"notifier"` Events []*JSONEvent `json:"events"` }
JSONErrorReport is the top level struct that encompasses the entire payload that's being sent to the Bugsnag's servers upon reporting an error.
type JSONEvent ¶ added in v0.3.0
type JSONEvent struct { // The version number of the payload. This is provided for legacy notifiers. // It is preferable to use the Bugsnag-Payload-Version header instead. PayloadVersion string `json:"payloadVersion,omitempty"` // Context is 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. Context string `json:"context,omitempty"` // Unhandled indicates 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 error was handled and reported using Notify. Unhandled bool `json:"unhandled"` // Severity can take values in ["error", "warning", "info"]. // "error" should be the default for panics. // "warning" should be the default for Notify() calls. // "info" can be specified by the user. // Severity does not affect the stability score in your dashboard. Severity string `json:"severity"` SeverityReason *JSONSeverityReason `json:"severityReason,omitempty"` // Most of the time there will only be one exception, but multiple // (nested/caused-by) errors may be added individually. // The innermost error should be first in this array. Exceptions []*JSONException `json:"exceptions,omitempty"` // This list is sequential and ordered newest to oldest. Breadcrumbs []*JSONBreadcrumb `json:"breadcrumbs,omitempty"` Request *JSONRequest `json:"request,omitempty"` User *JSONUser `json:"user,omitempty"` App *JSONApp `json:"app,omitempty"` Device *JSONDevice `json:"device,omitempty"` Session *JSONSession `json:"session,omitempty"` // An object containing any further data you wish to attach to this error // event. The key of the outermost map indicates the tab under which to display this information in Bugsnag. // The key of the innermost map indicates the property name, and the value is it's value Metadata map[string]map[string]interface{} `json:"metaData,omitempty"` // GroupingHash is a unique value that can be set in order to override the // grouping on the Bugsnag dashboard. // **Warning: Do not set unless you're 100% sure of what you're doing.** GroupingHash string `json:"groupingHash,omitempty"` }
JSONEvent is the event that Bugsnag should be notified of.
type JSONException ¶ added in v0.3.0
type JSONException struct { // The name of the type of error/panic which occurred. This is used to // group errors together so should not ocntain any contextual information // that would prevent correct grouping. ErrorClass string `json:"errorClass"` // The error message associated with the error. Usually this will contain // some information about this specific instance of the error and is not // used to group the errors. Message string `json:"message,omitempty"` Stacktrace []*JSONStackframe `json:"stacktrace"` }
JSONException is the error or panic that occurred during this the surrounding event.
type JSONNotifier ¶ added in v0.3.0
type JSONNotifier struct { Name string `json:"name"` Version string `json:"version"` URL string `json:"url"` }
JSONNotifier describes the package that triggers the sending of this report (the 'notifier'). These properties are used within Bugsnag to track error rates from a notifier.
type JSONRequest ¶ added in v0.3.0
type JSONRequest struct { // ClientIP identifies the IP address of the client that sent the request that caused the error. ClientIP string `json:"clientIp,omitempty"` Headers map[string]string `json:"headers,omitempty"` HTTPMethod string `json:"httpMethod,omitempty"` URL string `json:"url,omitempty"` Referer string `json:"referer,omitempty"` }
JSONRequest contains details about the web request from the client that experienced the error, if relevant. To display custom request data alongside these standard fields on the Bugsnag website, the custom data should be included in the metaData object in a request object.
type JSONSession ¶ added in v0.3.0
type JSONSession struct { // ID is a unique identifier of this session. ID string `json:"id"` // The time (in ISO8601 format) at which the session started. StartedAt string `json:"startedAt"` Events *JSONSessionEvents `json:"events"` }
JSONSession is information associated with the event. This can be used alongside the Bugsnag Session Tracking API to associate the event with a session so that a release's crash rate can be determined.
type JSONSessionCounts ¶ added in v0.3.0
type JSONSessionCounts struct { StartedAt string `json:"startedAt"` SessionsStarted int `json:"sessionsStarted"` }
JSONSessionCounts defines the .sessionCounts subobject of the payload.
type JSONSessionEvents ¶ added in v0.3.0
type JSONSessionEvents struct { // The number of handled events that have occurred in this session (including this event). Handled int `json:"handled,omitempty"` // The number of unhandled events that have occurred in this session // (including this event). Unlikely to be more than 1, as in Go, unhandled // events typically indicate that the app is shutting down. Unhandled int `json:"unhandled,omitempty"` }
JSONSessionEvents contain details of the number of handled and unhandled events that happened as part of this session (including this event).
type JSONSessionReport ¶ added in v0.3.0
type JSONSessionReport struct { Notifier *JSONNotifier `json:"notifier"` App *JSONApp `json:"app"` Device *JSONDevice `json:"device"` SessionCounts []JSONSessionCounts `json:"sessionCounts"` }
JSONSessionReport defines the top level payload object.
type JSONSeverityReason ¶ added in v0.3.0
type JSONSeverityReason struct { // "handledPanic" should be used when a panic has been recovered. // "unhandledPanic" should be used when a panic has happened without being recovered. // "handledError" should be used when reporting an error // "errorClass" should be used when the severity is defined because of the type of error that was reported. // "log" should be used when a notification is sent as part of a log call and the severity is set based on the log level // "signal" should be used when the application has received a signal from the operating system // "userCallbackSetSeverity" should be used when the user sets it as part of a callback. Type string `json:"type,omitempty"` }
JSONSeverityReason contains information about why the severity was picked.
type JSONStackframe ¶ added in v0.3.0
type JSONStackframe struct { // File identifies the name of the file that this frame of the stack was in. // This name should be stripped of any unnecessary from the beginning of the path. // In addition to error grouping, Bugsnag is able to go to the correct file // in GitHub etc. if the path is relative to the root of your repository. File string `json:"file"` // LineNumber is the line in the file, that this frame of the stack was in. // In addition to error grouping, this will be used to navigate to the // correct line in a file when source control is properly integrated. LineNumber int `json:"lineNumber"` // Method identifies the method or function that this particular stackframe was in. Method string `json:"method"` // InProject identifies if the stackframe is part of the application // written by the user, or if it was part of a third party dependency. InProject bool `json:"inProject"` }
JSONStackframe represents one line in the Exception's stacktrace. Bugsnag uses this information to help with error grouping, as well as displaying it to the user.
type JSONUser ¶ added in v0.3.0
type JSONUser = User
JSONUser is user information about the user affected by the error. These fields are optional but highly recommended. To display 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.
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier is the key type of this package, and exposes methods for reporting errors and tracking sessions.
func New ¶
func New(config Configuration) (*Notifier, error)
New constructs a new Notifier with the given configuration. You should call Close before shutting down your app in order to ensure that all sessions and reports have been sent.
func (*Notifier) Close ¶ added in v0.6.0
func (n *Notifier) Close()
Close shuts down the notifier, flushing any unsent reports and sessions. Any further calls to StartSession and Notify will call the InternalErrorCallback, if provided, with an error.
func (*Notifier) Deserialize ¶ added in v0.8.0
Deserialize extracts diagnostic data that has previously been serialized with Serialize and attaches it to the given ctx. Intended to be called in server middleware to attach diagnostic data identified from upstream services. As a result, any existing diagnostic data (session data from StartSession not inclusive) will be wiped. Note: If the upstream service attaches sensitive data this service should not report (e.g. user info), then this too will be propagated in this context, and you will have to use the ErrorReportSanitizer to remove this data.
func (*Notifier) Metadata ¶ added in v0.8.0
Metadata pulls out all the metadata known by this package as a map[tab]map[key]value from the given context.
func (*Notifier) Notify ¶
Notify reports the given error to Bugsnag. Extracts diagnostic data from the context and any *bugsnag.Error errors, including wrapped errors. Invokes the ErrorReportSanitizer, if set, before sending the error report.
func (*Notifier) Serialize ¶ added in v0.8.0
Serialize extracts all the diagnostic data tracked within the given ctx to a []byte that can later be deserialized using Deserialize. Useful for passing diagnostic to downstream services in header values.
func (*Notifier) StartSession ¶
StartSession attaches Bugsnag session data to a copy of the given context.Context, and returns the new context.Context. Records the newly started session and will at some point flush this session.
func (*Notifier) WithBreadcrumb ¶ added in v0.8.0
WithBreadcrumb attaches a breadcrumb to the top of the stack of breadcrumbs stored in the given context.
func (*Notifier) WithBugsnagContext ¶ added in v0.8.0
WithBugsnagContext applies the given bContext as the "Context" for the errors that show up in your Bugsnag dashboard. The naming here is unfortunate, but to be fair, Bugsnag had this nomenclature before Go did...
func (*Notifier) WithMetadata ¶ added in v0.8.0
func (n *Notifier) WithMetadata(ctx context.Context, tab string, data map[string]interface{}) context.Context
WithMetadata attaches the given data under the provided tab in the Bugsnag dashboard. You may use the following tab names to add data to existing/common tabs in the dashboard with the same name:
"user", "app", "device", "request"
func (*Notifier) WithMetadatum ¶ added in v0.8.0
func (n *Notifier) WithMetadatum(ctx context.Context, tab, key string, value interface{}) context.Context
WithMetadatum attaches the given key and value under the provided tab in the Bugsnag dashboard. You may use the following tab names to add data to existing/common tabs in the dashboard with the same name:
"user", "app", "device", "request"
func (*Notifier) WithUser ¶ added in v0.8.0
WithUser attaches the given User data to the given context, such that it can later be provided to the Notify method, and have this data show up in your dashboard.
func (*Notifier) Wrap ¶
Wrap attaches ctx data and wraps the given error with message, and associates a stacktrace to the error based on the frame at which Wrap was called. Any attached diagnostic data from this ctx will be preserved should you return the returned error further up the stack. You may use bugsnag.Wrap directly in order to get a *bugsnag.Error type returned without needing to do any type assertions.
type SessionReportSanitizer ¶ added in v0.4.1
type SessionReportSanitizer func(p *JSONSessionReport) error
SessionReportSanitizer allows you to modify the payload being sent to Bugsnag just before it's being sent. You may return a non-nil error in order to prevent the payload from being sent at all. This error is then forwarded to the InternalErrorCallback. No further modifications will happen to the payload after this is run.
type User ¶
type User struct { // ID is a unique identifier for a user affected by the event. // This could be any distinct identifier that makes sense for your app. ID string `json:"id,omitempty"` // Name is a human readable name of the user affected. Name string `json:"name,omitempty"` // Email is the user's email address, if known. Email string `json:"email,omitempty"` }
User information about the user affected by the error. These fields are optional but highly recommended. To display 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.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package builds is a package for sending build requests to the Bugsnag Build API, as defined here: https://bugsnagbuildapi.docs.apiary.io/
|
Package builds is a package for sending build requests to the Bugsnag Build API, as defined here: https://bugsnagbuildapi.docs.apiary.io/ |
cmd
|
|
bugsnag
Package main is the entrypoint for the bugsnag command-line tool.
|
Package main is the entrypoint for the bugsnag command-line tool. |
examples
module
|