newrelic / newrelic-python-agent

New Relic Python Agent
https://docs.newrelic.com/docs/agents/python-agent
Apache License 2.0
178 stars 102 forks source link

Add TOML configuration file support #1238

Closed Tatsh closed 1 week ago

Tatsh commented 1 month ago

Overview

This adds support for reading configuration from a TOML file such as pyproject.toml to reduce clutter.

Layout is:

[tool.newrelic]
app_name = "app name"

Keys with . in them are expanded to be subkeys:

[tool.newrelic.browser_monitoring]
enabled = true

Anything that is a list in the layout is made into a string joined with a single space.

import-hook:... is translated as such and requires quotes in the keys:

[tool.newrelic.import-hook.module_name]
"sub.sub" = ["item1", "item2"]

error_collector.ignore_errors:

[tool.newrelic.error_collector]
ignore_errors = ["module.name:ClassName", "module.name:ClassName2"]

Environments use the tool.newrelic.env namespace:

[tool.newrelic.env.production]
app_name = "production name"

Expansion of the subkeys includes doing so in an environment section:

[tool.newrelic.env.production.transaction_tracer]
enabled = false

Related Github Issue

1229

Testing

Tests have been added.

CLAassistant commented 1 month ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

:white_check_mark: TimPansino
:white_check_mark: Tatsh
:x: mergify[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

Tatsh commented 2 weeks ago

transaction_segment_terms

That also appears to be one that is processed separately like url_rules and not taken from the configuration.

TimPansino commented 2 weeks ago

transaction_segment_terms

That also appears to be one that is processed separately like url_rules and not taken from the configuration.

Yes all 4 of these settings are not possible to configure with a config file.

_settings.url_rules = []
_settings.metric_name_rules = []
_settings.transaction_name_rules = []
_settings.transaction_segment_terms = []
TimPansino commented 1 week ago

We'll get this cleaned up and merged after we fix the failing tests from main.