newrelic-python-agent icon indicating copy to clipboard operation
newrelic-python-agent copied to clipboard

NewRelic agent: Failed to extract source code context from callable

Open altonotch opened this issue 3 years ago • 3 comments

Description I added newrelic apm to a tornado based application. The agent is outputting a lot of error messages: newrelic.api.time_trace ERROR - Failed to extract source code context from callable <address.to.request.handler.here>. Report this issue to newrelic support.

Is this something in our code?

Expected Behavior No error messages and expected to see transactions in the APM.

Steps to Reproduce

  1. install newrelic==7.10.0.175
  2. wrap python main.py execution in newrelic-admin run-python path/to/code

Your Environment Python 3.9.2 NewRelic 7.10.0.175 Tornado 6.1.0

altonotch avatar Apr 10 '22 14:04 altonotch

Hello! This is an issue in a new feature we've just added in this version. If you're seeing that log message, your application should be safely recovering from the issue and there shouldn't be any crashes related to it. (If there are, definitely let us know.)

Could you tell us a bit about the callable this error message is referencing? We'd like to figure out what's not functioning as expected and get that data reporting. Specifically in the logs where you've redacted it to say: <address.to.request.handler.here>

Is that piece of code a function, a functools.partial, a callable object, a classmethod, etc?

If the log messages are bothering you and you'd like to temporarily disable the new feature you can use this setting to temporarily disable it.

TimPansino avatar Apr 11 '22 18:04 TimPansino

What we have is a class, a request handler, that is decorated with a function that returns a configured handler, with changed type.

From the error message, it looks like the part that causes the failure in the agent is the decorator.

Basically this part, see example code, specifically this:

app = Application([
    (r'/user/(.*)', ProfileHandler, dict(database=database)),
    ])

Let's say you have:

@configure_handler(configs=some_configs_obj)
class SomeHandler(RequestHandler):
    ...

and configure_handler is something like this:

def configure_handler(config: GenericHandlerConfig) \
        -> Callable[[GenericHandlerClassType], GenericHandlerClassType]:
    def inner_configure(cls: GenericHandlerClassType) -> GenericHandlerClassType:
        return type("GenericHandler_configured", (cls,), dict(_is_debug=config.is_debug))
    return inner_configure

And the error in the agent is for "GenericHandler_configured".

Hope this helps.

altonotch avatar Apr 12 '22 07:04 altonotch

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 13 '22 00:06 stale[bot]

We have a fix coming for this!

hmstepanek avatar Nov 14 '22 23:11 hmstepanek