newrelic
Version:
New Relic agent
39 lines (34 loc) • 1.01 kB
JavaScript
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
const UNKNOWN = 'Unknown'
const {
params: { DatastoreParameters }
} = require('../../shim/specs')
function grabLastUrlSegment(url = '/') {
// cast URL as string, and an empty
// string for null, undefined, NaN etc.
url = '' + (url || '/')
const lastSlashIndex = url.lastIndexOf('/')
return url.substring(lastSlashIndex + 1)
}
/**
* Retrieves the db segment params from endpoint and command parameters
*
* @param {object} endpoint instance of ddb endpoint
* @param {object} params parameters passed to a ddb command
* @returns {object}
*/
function setDynamoParameters(endpoint, params) {
return new DatastoreParameters({
host: endpoint && (endpoint.host || endpoint.hostname),
port_path_or_id: (endpoint && endpoint.port) || 443,
collection: (params && params.TableName) || UNKNOWN
})
}
module.exports = {
grabLastUrlSegment,
setDynamoParameters
}