Skip to content

Commit

Permalink
Merge pull request newrelic#15807 from TimPansino/feature-python-agen…
Browse files Browse the repository at this point in the history
…t-9-5-0

docs: Python Agent v9.5.0 Release
  • Loading branch information
ally-sassman authored Jan 13, 2024
2 parents 470696f + 64fe13d commit e6a0803
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3895,7 +3895,7 @@ For some tips on configuring logs for the Python agent, see [Configure Python lo
If `true`, enables log decoration and the collection of log events and logging metrics if these sub-feature configurations are also enabled. If `false`, no logging instrumentation features are enabled.
</Collapser>

<Collapser
<Collapser
id="application_logging.forwarding.enabled"
title="application_logging.forwarding.enabled"
>
Expand Down Expand Up @@ -3950,6 +3950,175 @@ For some tips on configuring logs for the Python agent, see [Configure Python lo
</Callout>
</Collapser>

<Collapser
id="application_logging.forwarding.context_data.enabled"
title="application_logging.forwarding.context_data.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_CONTEXT_DATA_ENABLED`
</td>
</tr>
</tbody>
</table>


If `true`, the agent will capture available context data (extras, dictionary message attributes, attributes provided by logging frameworks) and add its contents as attributes on the logs forwarded to New Relic. You can control this behavior through the settings under the `application_logging.forwarding.context_data` stanza.

</Collapser>

<Collapser
id="application_logging.forwarding.context_data.include"
title="application_logging.forwarding.context_data.include"
>
<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_CONTEXT_DATA_INCLUDE`
</td>
</tr>
</tbody>
</table>

If attributes are enabled for `context_data`, all attribute keys found in this list will be sent to us in transaction traces. For more information, see the [agent attribute rules](/docs/apm/other-features/attributes/agent-attributes).

<Callout variant="important">
When adding context attributes, the agent prefixes the keys with `context.` for attributes from the logging framework context, and `message.` for attributes from a dictionary message context.

These prefixes are <b>NOT</b> included when matching against include/exclude filtering rules.
</Callout>

</Collapser>

<Collapser
id="application_logging.forwarding.context_data.exclude"
title="application_logging.forwarding.context_data.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_CONTEXT_DATA_EXCLUDE`
</td>
</tr>
</tbody>
</table>

All attribute keys found in this list will not be sent in context_data. For more information, see the [agent attribute rules](/docs/apm/other-features/attributes/agent-attributes).

<Callout variant="important">
When adding context attributes, the agent prefixes the keys with `context.` for attributes from the logging framework context, and `message.` for attributes from a dictionary message context.

These prefixes are <b>NOT</b> included when matching against include/exclude filtering rules.
</Callout>

</Collapser>

<Collapser
id="event_harvest_config.harvest_limits.log_event_data"
title="event_harvest_config.harvest_limits.log_event_data"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ This records a [log event](/docs/logs/logs-context/configure-logs-context-python
<td>
`message`

_string_
_string_, _dictionary_
</td>

<td>
Required. The `message` defines the log message and must be a string.
Required. The `message` that defines the log message. For dictionary values, the key `message` will be extracted if available, and any other items will be considered context data attributes under the prefix `message.`.

To report these attributes, [enable context data forwarding](/docs/agents/python-agent/configuration/python-agent-configuration#application_logging.forwarding.context_data.enabled) and optionally configure [include](/docs/agents/python-agent/configuration/python-agent-configuration#application_logging.forwarding.context_data.include) and [exclude](/docs/agents/python-agent/configuration/python-agent-configuration#application_logging.forwarding.context_data.exclude) rules.
</td>
</tr>

Expand Down Expand Up @@ -78,6 +80,20 @@ This records a [log event](/docs/logs/logs-context/configure-logs-context-python
</td>
</tr>

<tr>
<td>
`attributes`

_dictionary_
</td>

<td>
Optional. Items included in this dictionary will be considered context data attributes under the prefix `context.`.

To report these attributes, [enable context data forwarding](/docs/agents/python-agent/configuration/python-agent-configuration#application_logging.forwarding.context_data.enabled) and optionally configure [include](/docs/agents/python-agent/configuration/python-agent-configuration#application_logging.forwarding.context_data.include) and [exclude](/docs/agents/python-agent/configuration/python-agent-configuration#application_logging.forwarding.context_data.exclude) rules.
</td>
</tr>

<tr>
<td>
`application`
Expand Down Expand Up @@ -131,3 +147,13 @@ def fetch():
newrelic.agent.record_log_event('Fetching data.')
# do some type of work in this transaction...
```

### Record log event with context data attributes [#context-data-example]

Here's an example of recording a log event using message attributes and context attributes:

```py
def fetch(product_id):
newrelic.agent.record_log_event({"message": "Fetching data", "product_id": product_id}, attributes={"thread_id": threading.get_ident()})
# do some type of work in this transaction...
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
subject: Python agent
releaseDate: '2024-01-11'
version: 9.5.0
downloadLink: 'https://pypi.python.org/pypi/newrelic'
features: ['Add context data attributes to logs','Add support for dictionary type log messages','Obfuscate license keys and user API keys in logs','Add attribute support to `record_log_event` API']
bugs: []
security: []
---

## Notes

This release of the Python agent adds context data attributes to logs, support for dictionary type log messages, adds attribute support to `record_log_event` API, and obfuscates logged license keys and user API keys.

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 context data attributes to logs**

* Context data available from logging frameworks can now be recorded as attributes on logs. These attributes are prefixed with `context.`, which is not considered when filtering attributes from logs.
* Context data may include extras, dictionary message attributes, and attributes provided by logging frameworks.
* To report these attributes, [enable context data forwarding](/docs/agents/python-agent/configuration/python-agent-configuration#application_logging.forwarding.context_data.enabled) and optionally configure [include](/docs/agents/python-agent/configuration/python-agent-configuration#application_logging.forwarding.context_data.include) and [exclude](/docs/agents/python-agent/configuration/python-agent-configuration#application_logging.forwarding.context_data.exclude) rules to filter the allowed attributes.

* **Add support for dictionary type log messages**

* Dictionary type log messages are now supported for logging frameworks which support dictionary type log messages (including the builtin `logging` module and `structlog`).
* The key `message` will be extracted if available and treated as the log message, and any other items will be considered context data attributes and prefixed with `message.`. These attributes are subject to the same filtering rules as other context data.

* **Add attribute support to `record_log_event` API**

* The `record_log_event` API now allows passing context data in using the optional `attributes` keyword argument, and allows the message argument to be a dictionary as described above.

* **Obfuscate license keys and user API keys in logs**

* The agent now obfuscates all instances of license keys or user API keys in agent logs and audit logs.

## 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 e6a0803

Please sign in to comment.