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

Structlog hook fails to append to processors #1039

Closed rchui closed 10 months ago

rchui commented 10 months ago

Description The newrelic structlog hook fails to append the new relic event consumer to the structlog processors:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
     return _run_code(code, main_globals, None,
   File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
     exec(code, run_globals)
   File "/app/broker/__main__.py", line 295, in <module>
     logs.configure(sumologic_url=configs.secrets.SUMOLOGIC_BACKEND_URL, process_id=process_id)
   File "/app/common/logs.py", line 89, in configure
     logger.info("Configuring handler", handler="StreamHandler")
   File "/usr/local/lib/python3.10/site-packages/structlog/_native.py", line 134, in meth
     return self._proxy_to_logger(name, event, **kw)
   File "/usr/local/lib/python3.10/site-packages/structlog/_base.py", line 216, in _proxy_to_logger
     args, kw = self._process_event(method_name, event, event_kw)
   File "/usr/local/lib/python3.10/site-packages/newrelic/hooks/logger_structlog.py", line 107, in wrap__process_event
     processors.append(new_relic_event_consumer)
 AttributeError: 'tuple' object has no attribute 'append'

Expected Behavior I expect it to be able to append itself to the processors without failure

Troubleshooting or NR Diag results

root@633af40f90f1:/backend# python --version
Python 3.10.13
newrelic==9.5.0
structlog==24.1.0

Steps to Reproduce I don't have a reproducible example, but I'm almost 100% sure it is because newrelic assumes that the processor set passed through when configuring structlog is a list. However the function signature in configure_once is Iterable[Processor]. Because I've initialized logging with a tuple newrelic attempts to append to it and fails.

Newrelic sdk should not be making this assumption given the function signature of the structlog configuration.

TimPansino commented 10 months ago

Confirmed, will be fixed in the next release.