Feature Idea: Twisted App with new relic (?)

Is it possible to add new relic to a twisted.app ?
I’ve seen that there is a experimental version of something there… am I wrong ?


New Relic edit

  • I want this, too
  • I have more info to share (reply below)
  • I have a solution for this

0 voters

We take feature ideas seriously and our product managers review every one when plotting their roadmaps. However, there is no guarantee this feature will be implemented. This post ensures the idea is put on the table and discussed though. So please vote and share your extra details with our team.

Hi @daniel_goldberg - a similar question came up on Stack Overflow. We do also note in our Python Agent docs that the support for Twisted is there but experimental. So you are correct that we have something brewing there. :slight_smile:

1 Like

Hi Lisa, thanks for your answer. I did that question too! :wink:
Do you know when we could try that ? :smiley:

Hi @daniel_goldberg - I’ve looked into this a bit further and it turns out that the experimental Twisted support is having enough issues that we’re not comfortable granting access to it at this time. So while it is brewing we do not have something right now for this. :frowning:

No problem. Thanks anyway.
Let me congratulate for the awesome support given to us!


Thank you @daniel_goldberg! My pleasure!

Is Twisted still not supported by New Relic Python agent (Ver

@vinay_r Yes, the Python agent does not currently support Twisted. I’ll create a feature request on your behalf for Twisted support.

Given the age, difficulty, and small market for this feature request; I’ll presume it is an unlikely addition to the product line?

Assuming that, does New Relic or others have any advice for regarding approaches and risks of alternate approaches when linking python twisted applications up to New Relic?

@bhyde I wouldn’t say “unlikely”—our product managers are always interested in how to make our Python Agent even more awesome for our users! I will put in a feature request for you so they can see that you’re interested!

As for your second question, I’ll ask the support team here at New Relic and see if anyone has any advice/best-practices/gotchas for linking a Python/Twisted app with New Relic.

@bhyde While we do very much like Twisted and think it is a great technology, we currently are unable to instrument applications built with it due to its asynchronous nature and unfortunately do not have viable workarounds for that at this time. Even if performance data was to report, the timings would likely be incorrect and not very useful.

If anyone else on the forum has had luck with getting some usable Twisted data to report, feel free to include your process here, but from the New Relic side of things, we do not have a way to do so.

1 Like

Nope. I didn’t sign up for any trials. I suspect you all did on my behalf when I registered for a workshop you all ran on day last week in Newton. - ben

Any update on this? Is there a plan for when Twisted support will be available?

No new updates to share just yet, @eric_stein_de. I will file a feature request for you though—that way my product managers will like to see another voice for Twisted support. Thanks for letting me know. :blush:

I have been watchinig this thread and I would like to chime in.

We don’t need full twisted support. What we need is a way to create transactions manually and to finish them manually. If I was able to create a transaction object, name it and then some time later call .finish() or whatever on it, I could immediately start using NewRelic to instrument my Twisted application. As it stands however, I have spent hours crawling the Python Agent’s implementation and cannot figure out a way to simply start a transaction, and end it, synchronously and manually.

If NewRelic could simply offer a simple transaction creation and commit API then this would be a lot easier. It seems that the existing stuff is too tied up in threads and automatic book-keeping. We just need something far simpler.

1 Like

@dustin.lacewell - it is in fact possible. I am doing it for my background batch jobs.

Here is a snippet of my code that I did. Granted, this is not async code and it is not twisted code. If you want to make transactions for web requests in an asynchronous python thing, you would have to patch the code in the python NR agent that influences how the instrumentation parts detect the current transaction. I’m not going to go into that here. It is likely fraught with issues, and I don’t really recommend it.

In this snippet, nr_agent is the python NR agent, and current_app is the flask “current_app”. I am setting up the flask application context to allow me to use flask extensions in my background jobs. This may not be the best thing in the world but it should clue you in as to how to create a transaction by hand.

class NullContextManager(object):

    def __enter__(self):
        current_app.logger.debug('newrelic agent was not available (entering fake transaction)')
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        current_app.logger.debug('newrelic agent was not available (exiting fake transaction)')
        return self

class Whatever(object):
    def blah(self):
        transaction = None

        if nr_agent is not None:
            transaction = nr_agent.current_transaction()
            if transaction is None:
                current_app.logger.debug('Starting a newrelic transaction')

                import newrelic.api.transaction
                transaction = newrelic.api.transaction.Transaction(nr_agent.application())

            # we surely don't have a transaction; fake it for the context manager.
            if nr_agent is None:
                transaction = NullContextManager()

            with transaction:
                if nr_agent is not None:
                    transaction_name = self.background_job_name()
                    current_app.logger.debug("transaction name for new relic is %s" % transaction_name)

                    if nr_agent.current_transaction() is None:
                            'We tried to create a new New Relic transaction, failed. Errors will not be captured.')
                        current_app.logger.debug('Started a new NR transaction for job.')


            if nr_agent is not None:

The above code assumes that you have already imported newrelic.agent previously in your interpreter and used .initialize on it with a config file, and called the register_application function as well. You should do this before you import anything else.

1 Like

Given the answers here and the time passed, any chance this will get a push forward?