diff --git a/api.js b/api.js index c992cbe6f5..3c9f04be92 100644 --- a/api.js +++ b/api.js @@ -477,7 +477,7 @@ API.prototype.createWebTransaction = function createWebTransaction(url, callback tx.id ) tx.partialName = NAMES.CUSTOM + NAMES.ACTION_DELIMITER + url - tx.setName(url, 0) + tx.url = url tx.webSegment = tracer.addSegment(url, recordWeb) return callback.apply(this, arguments) @@ -553,6 +553,7 @@ API.prototype.endTransaction = function endTransaction() { if (tx.webSegment) { tx.webSegment.markAsWeb(tx.url) tx.webSegment.end() + tx.setName(tx.url, 0) } tx.end() } else { diff --git a/test/unit/api/custom-instrumentation.test.js b/test/unit/api/custom-instrumentation.test.js index c7b91d543d..a760482fa4 100644 --- a/test/unit/api/custom-instrumentation.test.js +++ b/test/unit/api/custom-instrumentation.test.js @@ -299,6 +299,20 @@ describe('The custom instrumentation API', function () { var value = txHandler() expect(value).to.be.equal('a thing') }) + + it('should allow changing the transaction name', function (done) { + var txHandler = api.createWebTransaction('/custom/transaction', function (outerTx) { + var tx = agent.tracer.getTransaction() + + api.setTransactionName('new_name') + api.endTransaction() + + expect(tx.name).to.be.equal('WebTransaction/Custom/new_name') + done() + }) + + txHandler() + }) }) describe('when creating an background transaction', function () {