Skip to content

Commit

Permalink
feat(name-state): add getStatusName method
Browse files Browse the repository at this point in the history
Co-authored-by: Bryan Clement <bclement@newrelic.com>
Co-authored-by: Michael Goin <mgoin@newrelic.com>
  • Loading branch information
3 people committed Apr 24, 2019
1 parent b68cdb3 commit e447ac4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,9 @@ function _partialNameFromUri(requestUrl, status) {
// potentially apply the URL backstop now. Only do so if no user rules matched.
if (!partialName) {
// avoid polluting root path when 404
if (status === 404) {
partialName = this.nameState.getNameNotFound()
const statusName = this.nameState.getStatusName(status)
if (statusName) {
partialName = statusName
} else {
var normalized = this.agent.urlNormalizer.normalize(scrubbedUrl)
ignore = ignore || normalized.ignore
Expand Down
15 changes: 15 additions & 0 deletions lib/transaction/name-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ var LEGACY_NAMING = {
Restify: true
}

const STATUS_CODE_NAMES = {
404: '(not found)',
501: '(not implemented)',
405: '(method not allowed)'
}

/**
* Manages transaction names using a stack of paths.
Expand All @@ -41,6 +46,16 @@ NameState.prototype.setName = function setName(prefix, verb, delimiter, path) {
logger.trace('setName called on name state, path stack now %j', this.pathStack)
}

NameState.prototype.getStatusName = function getStatusName(statusCode) {
const name = STATUS_CODE_NAMES[statusCode]
if (name) {
if (LEGACY_NAMING.hasOwnProperty(this.prefix)) {
return _getName(this, name)
}
return NAMES.WEB.FRAMEWORK_PREFIX + '/' + _getName(this, name)
}
}

NameState.prototype.markPath = function markPath() {
this.markedPath = this.pathStack.slice()
}
Expand Down

0 comments on commit e447ac4

Please sign in to comment.