Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow changing the transaction name in a custom web transaction #188

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions test/unit/api/custom-instrumentation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down