Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix for empty route in fastify #268

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading