Skip to content

Commit

Permalink
fix: Fix for empty route in fastify (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitsuthar authored Dec 17, 2024
1 parent 8345e26 commit b939b97
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/instrumentation-security/hooks/fastify/nr-fastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const { ATTHERATE, DOUBLE_DOLLAR } = require('../../core/constants');
const lodash = require('lodash');
const routeManager = require('../../core/route-manager');
const semver = require('semver')
const url = require('url');
const API = require("../../../nr-security-api");
const logger = API.getLogger();

Expand Down Expand Up @@ -119,12 +118,10 @@ function setupExports(original, wrappedExport) {
*/
function extractParams(shim, req) {
try {
const reqURL = req.url || req.raw.url;
const parsedURI = url.parse(reqURL).pathname;
const transaction = shim.tracer.getTransaction();
if (transaction) {
let request = requestManager.getRequestFromId(transaction.id);
if (req.params && segment && request) {
if (req.params && request) {
Object.keys(req.params).forEach(function (key) {
if (req.params[key]) {
if (!request.parameterMap[key]) {
Expand All @@ -144,9 +141,9 @@ function extractParams(shim, req) {
}
});
}
let method = request.method.toUpperCase();
if (parsedURI && request && requestManager.requestMap[method + ATTHERATE + parsedURI]) {
request.uri = parsedURI;
const txInfo = lodash.get(req, Object.getOwnPropertySymbols(req).find(symbol => symbol.toString() === 'Symbol(fastify.context)'));
if (request && txInfo && txInfo.config && txInfo.config.url) {
request.uri = txInfo.config.url;
requestManager.setRequest(transaction.id, request);
}
}
Expand Down

0 comments on commit b939b97

Please sign in to comment.