-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
35 lines (29 loc) · 999 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package restqlnewrelic
import (
"fmt"
"os"
"strconv"
"github.com/newrelic/go-agent/v3/newrelic"
)
const transactionEventsMaxSamples = "NEW_RELIC_TRANSACTION_EVENTS_MAX_SAMPLES_STORED"
func ExtraConfigFromEnvironment() newrelic.ConfigOption {
return extraConfigFromEnvironment(os.Getenv)
}
func extraConfigFromEnvironment(getenv func(string) string) newrelic.ConfigOption {
return func(cfg *newrelic.Config) {
// Because fields could have been assigned in a previous
// ConfigOption, we only want to assign fields using environment
// variables that have been populated. This is especially
// relevant for the string case where no processing occurs.
assignInt := func(field *int, name string) {
if env := getenv(name); env != "" {
if i, err := strconv.Atoi(env); nil != err {
cfg.Error = fmt.Errorf("invalid %s value: %s", name, env)
} else {
*field = i
}
}
}
assignInt(&cfg.TransactionEvents.MaxSamplesStored, transactionEventsMaxSamples)
}
}