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.
Configuration options
Section titled “Configuration options”| Name | Type | Default | Example | Environment variable |
|---|---|---|---|---|
| APIKey | string | "" | "badger01" | HONEYBADGER_API_KEY |
| Root | string | The current working directory | "/path/to/project" | HONEYBADGER_ROOT |
| Env | string | "" | "production" | HONEYBADGER_ENV |
| Hostname | string | The hostname of current server | "badger01" | HONEYBADGER_HOSTNAME |
| Endpoint | string | "https://api.honeybadger.io" | "https://honeybadger.example.com/" | HONEYBADGER_ENDPOINT |
| Sync | bool | false | true | HONEYBADGER_SYNC |
| Timeout | time.Duration | 3 seconds | 10 * time.Second | HONEYBADGER_TIMEOUT (nanoseconds) |
| Logger | honeybadger.Logger | Logs to stderr | CustomLogger{} | n/a |
| Backend | honeybadger.Backend | HTTP backend | CustomBackend{} | n/a |
| EventsBatchSize | int | 1000 | 500 | HONEYBADGER_EVENTS_BATCH_SIZE |
| EventsTimeout | time.Duration | 30 seconds | 10 * time.Second | HONEYBADGER_EVENTS_TIMEOUT (nanoseconds) |
| EventsMaxQueueSize | int | 100000 | 50000 | HONEYBADGER_EVENTS_MAX_QUEUE_SIZE |
| EventsMaxRetries | int | 3 | 5 | HONEYBADGER_EVENTS_MAX_RETRIES |
| EventsThrottleWait | time.Duration | 60 seconds | 30 * time.Second | HONEYBADGER_EVENTS_THROTTLE_WAIT (nanoseconds) |
| EventsDropLogInterval | time.Duration | 60 seconds | 30 * time.Second | HONEYBADGER_EVENTS_DROP_LOG_INTERVAL (nanoseconds) |
Configuration via environment variables
Section titled “Configuration via environment variables”The following environment variables are supported:
HONEYBADGER_API_KEY- Your Honeybadger API keyHONEYBADGER_ENV- The environment name (e.g., “production”, “staging”)HONEYBADGER_ROOT- The project root directoryHONEYBADGER_HOSTNAME- The server hostnameHONEYBADGER_ENDPOINT- Custom API endpoint URLHONEYBADGER_SYNC- Set to “true” for synchronous error reportingHONEYBADGER_TIMEOUT- Request timeout in nanosecondsHONEYBADGER_EVENTS_BATCH_SIZE- Maximum events per batchHONEYBADGER_EVENTS_TIMEOUT- Events request timeout in nanosecondsHONEYBADGER_EVENTS_MAX_QUEUE_SIZE- Maximum events to queueHONEYBADGER_EVENTS_MAX_RETRIES- Maximum retry attempts for eventsHONEYBADGER_EVENTS_THROTTLE_WAIT- Wait time before retrying in nanosecondsHONEYBADGER_EVENTS_DROP_LOG_INTERVAL- Interval for logging dropped events in nanoseconds
Sync mode
Section titled “Sync mode”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()Custom logger
Section titled “Custom logger”You can provide a custom logger by implementing the honeybadger.Logger
interface:
honeybadger.Configure(honeybadger.Configuration{ Logger: myCustomLogger,})Custom backend
Section titled “Custom backend”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(),})Creating a new client
Section titled “Creating a new client”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.")