newrelic/node-newrelic — pull request #188 by mdlavin (2014-12-11 03:10:56+00:00)
Title: Allow changing the transaction name in a custom web transaction

While using the custom transaction API call, I noticed that I wasn't allowed to rename a transaction after creating it, like I was for transactions that are created by the agent itself. In my usecase I have a bunch of incoming work that I know needs to be processed. I want to start work the transaction immediately so I can track the time it takes to prepare for the work and the time it takes to decide what needs to be done. In my situation, I want to give the transaction a better name after some preparation has been done and I know more information.

When I dug into the code for custom transactions, I saw that it was calling transaction.setName() as soon as the transaction was created. The documentation for setName() says:

```
/**
* Sets the name of this transaction, figuring out along the way whether the
* transaction should be ignored. Should run as late in the transaction's
* lifetime as possible.
*
```

To respect the documentation of setName(), and to enable changing the name in the middle of a custom transaction, my changes move the setName() call to the endTransaction() code instead. I've added a testcase that fails without my changes.