Skip to content

Commit

Permalink
Merge pull request #19320 from hmstepanek/python-release-10-3-0
Browse files Browse the repository at this point in the history
Python release 10.3.0 -- Please merge Nov 19 AM
  • Loading branch information
adutta-newrelic authored Nov 20, 2024
2 parents 301ffb5 + 351c1b6 commit 0b67413
Show file tree
Hide file tree
Showing 3 changed files with 295 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,44 @@ Here are detailed descriptions of each configuration method:
OR
* Set the `NEW_RELIC_CONFIG_FILE` environment variable. If you use the `newrelic-admin` wrapper script, you must use the environment variable because the wrapper script calls the agent automatically.

The configuration file uses a structure similar to Microsoft Windows `.ini` files. For more information, see the Python ConfigParser module's [file format documentation](http://docs.python.org/library/configparser.html).
The agent supports two types of configuration files, agents v10.2.0 and older must use the `.ini` syntax while agent versions v10.3.0 and above running on Python versions 3.11 and above support `.toml` files as well.

<Collapser
className="freq-link"
id="agent-configuration-file-ini"
title="`.ini` configuration file format"
>
The configuration file uses a structure similar to Microsoft Windows `.ini` files. For more information, see the Python ConfigParser module's [file format documentation](https://docs.python.org/3/library/configparser.html).

The basic structure should look like the following:

```ini
[newrelic]
license_key = <license key>
app_name = Python Application
```
</Collapser>

<Collapser
className="freq-link"
id="agent-configuration-file-toml"
title="`.toml` configuration file format"
>
<Callout variant="tip">
Starting with Python 3.11 the newer `.toml` syntax for configuration was added to the [standard library](https://docs.python.org/3/library/tomllib.html). Agent version `10.3.0` added support for using this newer format.
</Callout>
The configuration file uses Tom's Obvious Minimal Language `.toml` files. For more information, see the [official file format documentation](https://toml.io/en/).
To use the `.toml` syntax, the configuration file's name must end with `.toml` to indicate the syntax type. The standard `pyproject.toml` may be used alongside configuration for other libraries, or you may use a more specific file like `newrelic.toml`.

The basic structure should look like the following:

```ini
[tool.newrelic]
license_key = <license key>
app_name = Python Application
```
</Collapser>

<Callout variant="tip">
A sample configuration file is included with the Python agent as `newrelic/newrelic.ini`. You can also generate one from the `newrelic-admin` script using the `generate-config` command, or download a copy from [our download repo](https://download.newrelic.com/python_agent/release/).
Expand Down Expand Up @@ -425,7 +462,7 @@ Here are detailed descriptions of each configuration method:

## Multiple environment configuration [#config-file-deployment-environments]

The agent reads its primary configuration from an agent config section called `newrelic`. You can provide overrides for specific deployment environments (for example, Development, Staging, Production) in additional sections. Preface these sections with `[newrelic:environment]`, where `environment` is replaced with the name of your environment.
The agent reads its primary configuration from an agent config section called `[newrelic]` for `ini` files, or `[tool.newrelic]` for `.toml` files. You can provide overrides for specific deployment environments (for example, Development, Staging, Production) in additional sections. Preface these sections with `[newrelic:environment]` for `.ini` files, or `[tool.newrelic.env.environment]` for `.toml` files (where `environment` is replaced with the name of your environment).

To specify that the agent should use an environment-based configuration, use one of these methods:

Expand All @@ -438,6 +475,12 @@ If no environment is specified, the agent will use the default settings as speci

The basic structure of the configuration file is:


<Collapser
className="freq-link"
id="config-file-format-example-ini"
title="`.ini` configuration file format"
>
```ini
[newrelic]
... default settings
Expand All @@ -451,6 +494,27 @@ The basic structure of the configuration file is:
[newrelic:production]
... override settings
```
</Collapser>

<Collapser
className="freq-link"
id="config-file-format-example-toml"
title="`.toml` configuration file format"
>
```ini
[tool.newrelic]
... default settings

[tool.newrelic.env.development]
... override settings

[tool.newrelic.env.staging]
... override settings

[tool.newrelic.env.production]
... override settings
```
</Collapser>

## General configuration settings [#general-settings]

Expand Down Expand Up @@ -4166,6 +4230,160 @@ For some tips on configuring logs for the Python agent, see [Configure Python lo
</Callout>
</Collapser>
<Collapser
id="application_logging.forwarding.custom_attributes"
title="application_logging.forwarding.custom_attributes"
>
<table>
<tbody>
<tr>
<th>
Type
</th>
<td>
String
</td>
</tr>
<tr>
<th>
Default
</th>
<td>
(none)
</td>
</tr>
<tr>
<th>
[Set in](#options)
</th>
<td>
Config file, environment variable
</td>
</tr>
<tr>
<th>
[Environ variable](#environment-variables)
</th>
<td>
`NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CUSTOM_ATTRIBUTES`
</td>
</tr>
</tbody>
</table>
A hash with key/value pairs to add as custom attributes to all log events forwarded to New Relic. The value must be formatted like: "key1:value1;key2:value2"
</Collapser>
<Collapser
id="application_logging.forwarding.labels.enabled"
title="application_logging.forwarding.labels.enabled"
>
<table>
<tbody>
<tr>
<th>
Type
</th>
<td>
Boolean
</td>
</tr>
<tr>
<th>
Default
</th>
<td>
`false`
</td>
</tr>
<tr>
<th>
[Set in](#options)
</th>
<td>
Config file, environment variable
</td>
</tr>
<tr>
<th>
[Environ variable](#environment-variables)
</th>
<td>
`NEW_RELIC_APPLICATION_LOGGING_FORWARDING_LABELS_ENABLED`
</td>
</tr>
</tbody>
</table>
Toggles whether the agent will add labels to log records for sending to New Relic.
</Collapser>
<Collapser
id="application_logging.forwarding.labels.exclude"
title="application_logging.forwarding.labels.exclude"
>
<table>
<tbody>
<tr>
<th>
Type
</th>
<td>
List of strings
</td>
</tr>
<tr>
<th>
Default
</th>
<td>
(none)
</td>
</tr>
<tr>
<th>
[Set in](#options)
</th>
<td>
Config file, environment variable
</td>
</tr>
<tr>
<th>
[Environ variable](#environment-variables)
</th>
<td>
`NEW_RELIC_APPLICATION_LOGGING_FORWARDING_LABELS_EXCLUDE`
</td>
</tr>
</tbody>
</table>
A case-insensitive list of label names to exclude when you enable including labels in logs. This attribute does not support wildcards or regex.
<Callout variant="important">When adding labels as attributes, the agent prefixes the keys with `tags.`. This prefix is <b>NOT</b> included when matching against the exclude filtering rules.</Callout>
</Collapser>
<Collapser
id="application_logging.forwarding.context_data.enabled"
title="application_logging.forwarding.context_data.enabled"
Expand Down Expand Up @@ -5585,11 +5803,19 @@ To disable default instrumentation, provide a special `import-hook` section corr
id="example-disable-mysqldb"
title="Example: Disabling MySQLdb database query instrumentation"
>
Add the following to the configuration file:
Add the following to the `.ini` configuration file:

```ini
[import-hook:MySQLdb]
enabled = false
```

Or for `.toml` configuration files add the following:

```ini
[tool.newrelic.import-hook.MySQLdb]
enabled = false
```

</Collapser>
</CollapserGroup>
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ tags:
- Tag
- Labels
metaDescription: For apps monitored by New relic language agents, learn how to add custome tags (labels) to logs.
redirects:
- /docs/enable-logs-context
- /docs/apm/agents/net-agent/configuration/net-agent-configuration
- /docs.newrelic.com/docs/apm/agents/ruby-agent/configuration/ruby-agent-configuration/
- /docs/logs/new-relic-logs/enable-logs-context/enable-logs-context-go
freshnessValidatedDate: 2024-11-17
---

Expand All @@ -28,4 +23,5 @@ Supported languages:
* [Ruby](/docs.newrelic.com/docs/apm/agents/ruby-agent/configuration/ruby-agent-configuration/) agent versions 9.16.0 or higher.
* Go: coming soon
* Java: coming soon
* Node.js: coming soon
* Node.js: coming soon
* [Python](/docs/apm/agents/python-agent/configuration/python-agent-configuration) agent versions 10.3.0 or higher.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
subject: 'Python agent'
releaseDate: '2024-11-18'
version: 10.3.0
downloadLink: 'https://pypi.python.org/pypi/newrelic'
features: ['Add Valkey support', 'Add TOML configuration file support', 'Add protobuf v5 support for infinite tracing', 'Add support for attaching custom attributes to logs', 'Add support for attaching labels to logs', 'Minor cleanup of HTTPX instrumentation']
bugs: ['Collect module information periodically']
security: []
---

## Notes

This release of the Python agent adds support for Valkey, configuration via TOML file, protobuf v5 for infinite tracing, attaching custom attributes and labels to log events, and some minor cleanup of HTTPX instrumentation. HTTP/2 support was validated for [Daphne](https://pypi.org/project/daphne/), [Hypercorn](https://pypi.org/project/Hypercorn/), and [HTTPX](https://pypi.org/project/httpx/). Module information is now collected periodically which fixes a bug where the CPU usage would spike on application startup.

The Python agent now allows you to opt-in to adding your custom tags (labels) to agent-forwarded logs. With custom tags on logs, platform engineers can easily filter, search, and correlate log data for faster and more efficient troubleshooting, improved performance, and optimized resource utilization. To learn more about this feature see the [documentation](/docs/logs/logs-context/Custom-tags-agent-forwarder-logs).

Install the agent using `easy_install/pip/distribute` via the [Python Package Index](https://pypi.python.org/pypi/newrelic) or download it directly from the [New Relic download site](https://download.newrelic.com/python_agent/release).

## New features

* Add support for Valkey

* Add instrumentation for [Valkey](https://pypi.org/project/valkey/). Thanks [@jairhenrique](https://github.com/jairhenrique) for the contribution!

* Add TOML configuration file support

* Support to read TOML configuration is now available. Thanks [@Tatsh](https://github.com/Tatsh) for the contribution!

* Add infinite tracing pb2 file for protobuf v5

* This adds an additional pb2 file used for infinite tracing that is compatible with [protobuf](https://pypi.org/project/protobuf/) v5.

* Add support for attaching custom attributes to logs

* A new configuration option has been added called `application_logging.forwarding.custom_attributes` that will add custom attributes to all log events when set.

* Add support for attaching labels to log events

* Labels as attributes can now be added to log events. When `application_logging.forwarding.labels.enabled` is set the values in `labels` will be added to all log events. Labels can be excluded by setting `application_logging.forwarding.labels.exclude`.

## Enhancements

* Minor cleanup of HTTPX instrumentation

* Some minor cleanup was done in the HTTPX instrumentation.

* Validate HTTP/2 support

* Added tests to ensure HTTP/2 support for the following frameworks:
* [Daphne](https://pypi.org/project/daphne/)
* [Hypercorn](https://pypi.org/project/Hypercorn/)
* [HTTPX](https://pypi.org/project/httpx/)

## Bug fixes

* Collect module information from application periodically instead of at startup

* Previously, the New Relic Python agent collected the application's module information all at once during startup. In some extreme cases this would cause a large spike in CPU usage. This enhancement allows the agent to do this incrementally throughout the application's operation, preventing potential memory spikes during agent startup.

## Support statement

We recommend updating to the latest agent version as soon as it's available. If you can't upgrade to the latest version, update your agents to a version no more than 90 days old. Read [more](/docs/new-relic-solutions/new-relic-one/install-configure/update-new-relic-agent/) about keeping agents up to date.

See the New Relic Python agent [EOL policy](/docs/apm/agents/python-agent/getting-started/python-agent-eol-policy/) for information about agent releases and support dates.

0 comments on commit 0b67413

Please sign in to comment.