Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TOML configuration file support #1238

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

Tatsh
Copy link

@Tatsh Tatsh commented Oct 15, 2024

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.

@Tatsh Tatsh requested a review from a team as a code owner October 15, 2024 03:28
@CLAassistant
Copy link

CLAassistant commented Oct 15, 2024

CLA assistant check
All committers have signed the CLA.

newrelic/config.py Outdated Show resolved Hide resolved
@Tatsh Tatsh force-pushed the toml-support branch 2 times, most recently from e3cad69 to 5819561 Compare October 23, 2024 04:51
TimPansino
TimPansino previously approved these changes Oct 24, 2024
Copy link
Contributor

@TimPansino TimPansino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving from my end, waiting on @hmstepanek to approve as well before merging.

Copy link
Contributor

@hmstepanek hmstepanek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple more complicated settings that we have that I don't think are currently compatible with this parser. I went through our core config and looked for some others that are more complex like this. transaction_segment_terms is even more complex than the example below that I've noted and looks like:

    transaction_segment_terms = [
      {
        prefix = "WebTransaction/Custom",
        terms = ["one", "two", "three"]
      },
      {
        prefix = "WebTransaction/Uri",
        terms = ["seven", "eight", "nine"]
      }
    ]

tests/agent_features/test_configuration.py Show resolved Hide resolved
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:

[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"]

Environment use the tool.newrelic.env namespace:

[tool.newrelic.env.production]
app_name = "production name"
newrelic/config.py Outdated Show resolved Hide resolved
@Tatsh Tatsh requested a review from hmstepanek October 29, 2024 00:03
@Tatsh
Copy link
Author

Tatsh commented Oct 29, 2024

transaction_segment_terms

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

@TimPansino
Copy link
Contributor

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 = []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants