Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Feature Idea: Twisted App with new relic (?)

twisted
feature-request
version-python-2-50-0-39
feature-idea

#1

Hi,
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 ?

Thanks!


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.


#2

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:


#3

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


#4

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:


#5

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


#6

Thank you @daniel_goldberg! My pleasure!


#7

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


#8

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


#9

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?


#10

@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.


#11

@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.


#12

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


#13

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


#14

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:


#15

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.


#16

@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):
    #...stuff....
        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())

        try:
            # 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)
                    nr_agent.set_transaction_name(transaction_name)
                    nr_agent.set_background_task()

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

                self.run_actual_things()

        finally:
            if nr_agent is not None:
                nr_agent.end_of_transaction()

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.


7/22/2016 Post of the Week—Twisted, Synthetics, Java and Django!
#17

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