Skip to content

Commit 87499b8

Browse files
committed
fix: honour 'usePathAsTransactionName' config var in Next.js instrumentation
Fixes: #3072
1 parent 5655ccc commit 87499b8

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

CHANGELOG.asciidoc

+20
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ Notes:
3232
=== Node.js Agent version 3.x
3333
3434
35+
==== Unreleased
36+
37+
[float]
38+
===== Breaking changes
39+
40+
[float]
41+
===== Features
42+
43+
[float]
44+
===== Bug fixes
45+
46+
* Fix Next.js instrumentation to honour the <<use-path-as-transaction-name>>
47+
config setting. When set to true the APM transaction name for a request to a
48+
Next.js Dynamic Route will use the request path, e.g. `GET /about-us`, rather
49+
than the dynamic route name, e.g. `GET /[...page]`. ({issues}3072[#3072])
50+
51+
[float]
52+
===== Chores
53+
54+
3555
[[release-notes-3.41.0]]
3656
==== 3.41.0 2022/12/12
3757

examples/nextjs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"elastic-apm-node": "elastic/apm-agent-nodejs#main",
12+
"elastic-apm-node": "^3.40.1",
1313
"next": "12.3.1",
1414
"react": "18.2.0",
1515
"react-dom": "18.2.0"

lib/instrumentation/modules/next/dist/server/dev/next-dev-server.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ module.exports = function (mod, agent, { version, enabled }) {
143143
// specific route wrapper hasn't already done so.
144144
if (trans && !trans[kSetTransNameFn]) {
145145
trans[kSetTransNameFn] = (req, pathname) => {
146-
trans.setDefaultName(`${req.method} ${pathname}`)
146+
if (agent._conf.usePathAsTransactionName) {
147+
trans.setDefaultName(`${req.method} ${req.url}`)
148+
} else {
149+
trans.setDefaultName(`${req.method} ${pathname}`)
150+
}
147151
// Ensure only the first `findPageComponents` result sets the trans
148152
// name, otherwise a loaded `/_error` for page error handling could
149153
// incorrectly override.

lib/instrumentation/modules/next/dist/server/next-server.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ module.exports = function (mod, agent, { version, enabled }) {
140140
// specific route wrapper hasn't already done so.
141141
if (trans && !trans[kSetTransNameFn]) {
142142
trans[kSetTransNameFn] = (req, pathname) => {
143-
trans.setDefaultName(`${req.method} ${pathname}`)
143+
if (agent._conf.usePathAsTransactionName) {
144+
trans.setDefaultName(`${req.method} ${req.url}`)
145+
} else {
146+
trans.setDefaultName(`${req.method} ${pathname}`)
147+
}
144148
// Ensure only the first `findPageComponents` result sets the trans
145149
// name, otherwise a loaded `/_error` for page error handling could
146150
// incorrectly override.

0 commit comments

Comments
 (0)