bugsnag / bugsnag-go

Automatic panic monitoring for Go and Go web frameworks, like negroni, gin, and revel
https://docs.bugsnag.com/platforms/go
MIT License
203 stars 69 forks source link

Why load all os.Environ() envs as metadata? #195

Closed letschers closed 1 year ago

letschers commented 1 year ago

Hello!

I'm implementing bugsnag on my application and something odd occured: some logs started to get duplicated when setting up the bugsnag integration. The log of loading .env variables was being doubled and I was questioning why necessarily the .env load log. Looking in the source code of the project, the Configure function:

func Configure(config Configuration) {
    // Load configuration from the environment, if any
    readEnvConfigOnce.Do(Config.loadEnv)
    Config.update(&config)
    updateSessionConfig()
    // Only do once in case the user overrides the default panichandler, and
    // configures multiple times.
    panicHandlerOnce.Do(Config.PanicHandler)
}

That's alright, the configure function do some magic but the interesting part is the Config.loadEnv() function, that starts loading some related envs, but in the end of the function Config.loadEnv():

metadata := loadEnvMetadata(os.Environ())

Why does the project loads all my local envs? Should not just use the envs related to the bugsnag-go (eg BUGSNAG_API_KEY) ?

johnkiely1 commented 1 year ago

Hi @letschers,

The local envs are loaded in order to determine any occurrences where you have added BUGSNAG_METADATA_xxxx formatted environment variables.

We add these as metadata to the event payload here. As it is somewhat freeform as to what the full environment variable name is, we cannot determine what that might be to just load those specifically, so we have to parse that for any variables that have the BUGSNAG_METADATA prefix

This is described in the docs here: https://docs.bugsnag.com/platforms/go/other/configuration-options/#adding-metadata.