diff --git a/README.md b/README.md index f724b93..da04182 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ This plugin can be configured [through environment variables](https://github.com - `NEW_RELIC_UTILIZATION_BILLING_HOSTNAME`: sets Utilization.BillingHostname - `NEW_RELIC_UTILIZATION_LOGICAL_PROCESSORS`: sets Utilization.LogicalProcessors using [strconv.Atoi](https://golang.org/pkg/strconv/#Atoi). - `NEW_RELIC_UTILIZATION_TOTAL_RAM_MIB`: sets Utilization.TotalRAMMIB using [strconv.Atoi](https://golang.org/pkg/strconv/#Atoi). +- `NEW_RELIC_TRANSACTION_EVENTS_MAX_SAMPLES_STORED`: sets TransactionEvents.MaxSamplesStored using [strconv.Atoi](https://golang.org/pkg/strconv/#Atoi). ## License diff --git a/config.go b/config.go new file mode 100644 index 0000000..5aaf8d1 --- /dev/null +++ b/config.go @@ -0,0 +1,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) + } +} diff --git a/main.go b/main.go index e28469c..d8439ca 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,10 @@ func init() { } func MakeNewRelicPlugin(logger restql.Logger) (restql.LifecyclePlugin, error) { - app, err := newrelic.NewApplication(newrelic.ConfigFromEnvironment()) + app, err := newrelic.NewApplication( + newrelic.ConfigFromEnvironment(), + ExtraConfigFromEnvironment(), + ) if err != nil { logger.Error("failed to initialize new relic", err)