Skip to content

Configuration

You can configure Honeybadger using the honeybadger.Configure method:

honeybadger.Configure(honeybadger.Configuration{
APIKey: "PROJECT_API_KEY",
Env: "production",
})

You can also configure most options via environment variables.

NameTypeDefaultExampleEnvironment variable
APIKeystring"""badger01"HONEYBADGER_API_KEY
RootstringThe current working directory"/path/to/project"HONEYBADGER_ROOT
Envstring"""production"HONEYBADGER_ENV
HostnamestringThe hostname of current server"badger01"HONEYBADGER_HOSTNAME
Endpointstring"https://api.honeybadger.io""https://honeybadger.example.com/"HONEYBADGER_ENDPOINT
SyncboolfalsetrueHONEYBADGER_SYNC
Timeouttime.Duration3 seconds10 * time.SecondHONEYBADGER_TIMEOUT (nanoseconds)
Loggerhoneybadger.LoggerLogs to stderrCustomLogger{}n/a
Backendhoneybadger.BackendHTTP backendCustomBackend{}n/a
EventsBatchSizeint1000500HONEYBADGER_EVENTS_BATCH_SIZE
EventsTimeouttime.Duration30 seconds10 * time.SecondHONEYBADGER_EVENTS_TIMEOUT (nanoseconds)
EventsMaxQueueSizeint10000050000HONEYBADGER_EVENTS_MAX_QUEUE_SIZE
EventsMaxRetriesint35HONEYBADGER_EVENTS_MAX_RETRIES
EventsThrottleWaittime.Duration60 seconds30 * time.SecondHONEYBADGER_EVENTS_THROTTLE_WAIT (nanoseconds)
EventsDropLogIntervaltime.Duration60 seconds30 * time.SecondHONEYBADGER_EVENTS_DROP_LOG_INTERVAL (nanoseconds)

The following environment variables are supported:

  • HONEYBADGER_API_KEY - Your Honeybadger API key
  • HONEYBADGER_ENV - The environment name (e.g., “production”, “staging”)
  • HONEYBADGER_ROOT - The project root directory
  • HONEYBADGER_HOSTNAME - The server hostname
  • HONEYBADGER_ENDPOINT - Custom API endpoint URL
  • HONEYBADGER_SYNC - Set to “true” for synchronous error reporting
  • HONEYBADGER_TIMEOUT - Request timeout in nanoseconds
  • HONEYBADGER_EVENTS_BATCH_SIZE - Maximum events per batch
  • HONEYBADGER_EVENTS_TIMEOUT - Events request timeout in nanoseconds
  • HONEYBADGER_EVENTS_MAX_QUEUE_SIZE - Maximum events to queue
  • HONEYBADGER_EVENTS_MAX_RETRIES - Maximum retry attempts for events
  • HONEYBADGER_EVENTS_THROTTLE_WAIT - Wait time before retrying in nanoseconds
  • HONEYBADGER_EVENTS_DROP_LOG_INTERVAL - Interval for logging dropped events in nanoseconds

By default, notices are sent via a separate worker goroutine. This is ideal for long-running applications as it keeps Honeybadger from blocking during execution. However, this can be a problem for short-running applications (lambdas, for example) as the program might terminate before all messages are processed.

To combat this, you can configure Honeybadger to work in “Sync” mode which blocks until notices are sent when honeybadger.Notify is executed:

honeybadger.Configure(honeybadger.Configuration{Sync: true})

Alternatively, if you want asynchronous behavior but need to ensure notices are sent before your program exits, you can call honeybadger.Flush:

honeybadger.Notify("I errored.")
honeybadger.Flush()

You can provide a custom logger by implementing the honeybadger.Logger interface:

honeybadger.Configure(honeybadger.Configuration{
Logger: myCustomLogger,
})

For testing or custom integrations, you can provide a custom backend:

honeybadger.Configure(honeybadger.Configuration{
Backend: myCustomBackend,
})

To disable error reporting entirely (useful for development), use the null backend:

honeybadger.Configure(honeybadger.Configuration{
Backend: honeybadger.NewNullBackend(),
})

In the same way that the log library provides a predefined “standard” logger, honeybadger defines a standard client which may be accessed directly via honeybadger. A new client may also be created by calling honeybadger.New:

hb := honeybadger.New(honeybadger.Configuration{APIKey: "some other api key"})
hb.Notify("This error was reported by an alternate client.")