[SE]node.jsの0.11.14でurlの挙動ちょっと変わった件

詳細は「TypeError occurred with Heroku App - Node.js Agent - New Relic Explorers Hub」に書いてあるのですが。


Heroku上のnode.jsアプリでnewrelic使ってるのだけれど、ちょっとした内容を更新してHerokuにdeployしたらエラーが出るようになりましたよと。

2014-10-03T15:05:22.033348+00:00 app[web.1]: /app/node_modules/newrelic/node_modules/continuation-local-storage/context.js:78
2014-10-03T15:05:22.033357+00:00 app[web.1]:             ^
2014-10-03T15:05:22.033359+00:00 app[web.1]: TypeError: Object.keys called on non-object
2014-10-03T15:05:22.033361+00:00 app[web.1]:   at Function.keys (native)
2014-10-03T15:05:22.033362+00:00 app[web.1]:   at Object.parseParameters (/app/node_modules/newrelic/lib/util/urltils.js:77:14)
2014-10-03T15:05:22.033364+00:00 app[web.1]:   at TraceSegment.markAsWeb (/app/node_modules/newrelic/lib/transaction/trace/segment.js:91:32)
2014-10-03T15:05:22.033366+00:00 app[web.1]:   at ServerResponse.instrumentedFinish (/app/node_modules/newrelic/lib/instrumentation/core/http.js:96:15)
2014-10-03T15:05:22.033367+00:00 app[web.1]:   at ServerResponse.g (events.js:199:16)
2014-10-03T15:05:22.033369+00:00 app[web.1]:   at ServerResponse.<anonymous> (/app/node_modules/newrelic/node_modules/continuation-local-storage/context.js:74:17)
2014-10-03T15:05:22.033370+00:00 app[web.1]:   at ServerResponse.emit (events.js:129:20)
2014-10-03T15:05:22.033372+00:00 app[web.1]:   at ServerResponse.emitted [as emit] (/app/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/emitter-listener/listener.js:122:21)
2014-10-03T15:05:22.033374+00:00 app[web.1]:   at finish (_http_outgoing.js:517:10)
2014-10-03T15:05:22.033375+00:00 app[web.1]:   at /app/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31
2014-10-03T15:05:22.033377+00:00 app[web.1]:   at process._tickCallback (node.js:372:11)
2014-10-03T15:05:22.033378+00:00 app[web.1]:


で、スタックトレースにはnewrelicのコードがあったのでnewrelicのフォーラムに投稿してみたら「URLの扱い変わるような更新したんじゃない?」って言われて、「そんな更新してないけどなー」って調べてみたらnode標準の「url」のところがなにやら変わってるご様子。


newrelic内に「if (parsed.search !== '')」で分岐するところがあるのだけれど、このparsed.searchが今まで''を返していたところでnullを返すようになっていた。


上記parsedは「url.parse(【パス】, true)」となっていて、その部分を端的に示すと、

console.dir(require("url").parse("/", true));

というコードの結果が0.11.13だと

{ protocol: null,
  slashes: null,
  auth: null,
  host: null,
  port: null,
  hostname: null,
  hash: null,
  search: '',     <-----
  query: {},     <-----
  pathname: '/',
  path: '/',
  href: '/' }

だけれど、0.11.14だと

{ protocol: null,
  slashes: null,
  auth: null,
  host: null,
  port: null,
  hostname: null,
  hash: null,
  search: null,     <----- if (parsed.search !== '') in urltils.js
  query: null,     <-----
  pathname: '/',
  path: '/',
  href: '/' }

という感じ。


package.jsonでは「0.11.x」のようにマイナーバージョンのところは自動で最新のを使うようにしていたのだけれど、このあたりも明示して固定しないといかんかなー。