diff --git a/lib/integrations/index.ts b/lib/integrations/index.ts index 023e0847..940bdf2a 100644 --- a/lib/integrations/index.ts +++ b/lib/integrations/index.ts @@ -6,7 +6,6 @@ import mustacheIntegration from "./mustache"; import ejsIntegration from "./ejs"; import httpIntegration from "./http"; import expressIntegration from "./express"; -import nuxtIntegration from "./nuxt"; import httpsIntegration from "./https"; import ioredisIntegration from "./ioredis"; import prismaIntegration from "./prisma"; @@ -24,7 +23,6 @@ export const KNOWN_PACKAGES: string[] = [ ejsIntegration.getPackageName(), httpIntegration.getPackageName(), expressIntegration.getPackageName(), - nuxtIntegration.getPackageName(), httpsIntegration.getPackageName(), ioredisIntegration.getPackageName(), prismaIntegration.getPackageName(), @@ -43,7 +41,6 @@ export function getIntegrationForPackage(pkg: string): RequireIntegration { case ejsIntegration.getPackageName(): return ejsIntegration; case httpIntegration.getPackageName(): return httpIntegration; case expressIntegration.getPackageName(): return expressIntegration; - case nuxtIntegration.getPackageName(): return nuxtIntegration; case httpsIntegration.getPackageName(): return httpsIntegration; case ioredisIntegration.getPackageName(): return ioredisIntegration; case prismaIntegration.getPackageName(): return prismaIntegration; diff --git a/lib/integrations/nuxt.ts b/lib/integrations/nuxt.ts deleted file mode 100644 index 1a2d45c1..00000000 --- a/lib/integrations/nuxt.ts +++ /dev/null @@ -1,98 +0,0 @@ -import * as path from "path"; -import { ExportBag, RequireIntegration } from "../types/integrations"; -import { Scout } from "../scout"; -import { LogFn, LogLevel, ScoutContextName, ScoutSpanOperation } from "../types"; -import * as Constants from "../constants"; - -// Hook into the express and mongodb module -export class NuxtIntegration extends RequireIntegration { - protected readonly packageName: string = "nuxt"; - - protected shim(nuxtExport: any): any { - nuxtExport = this.shimNuxtCtor(nuxtExport); - - return nuxtExport; - } - - /** - * Shim for nuxt's `Nuxt` constructor - * - * @param {any} nuxtExport - nuxt's export - */ - private shimNuxtCtor(nuxtExport: any): any { - const OriginalCtor = nuxtExport.Nuxt; - const integration = this; - - // Create a constructor identical to the original Nuxt constructor - const Nuxt = function Nuxt() { - const originalArgs = arguments; - integration.logFn("[scout/integrations/nuxt] Creating Nuxt object...", LogLevel.Debug); - - // Create the instance - const instance = new OriginalCtor(...originalArgs); - - // We need to shim nuxt.render such that when it is called - const originalRender = instance.render; - instance.render = function render(req, res, next) { - // If no scout instance is available then run the function normally - if (!integration.scout) { return originalRender.apply(this, arguments); } - - // If we have context set up (we are in an async context and can obtain the current request) - if (integration.scout.getCurrentRequest()) { - integration.logFn( - "[scout/integrations/nuxt] ScoutRequest present while serving [${req.url}]", - LogLevel.Debug, - ); - return originalRender.apply(this, arguments); - } - - // At this point, if a scout instance and there is no current scout request - // that means any activity nuxt triggers (ex. HTTP requests with 'net') - // are going to happen *without* a containg request/controller span this - // happens because requests to Nuxt do *not* flow throw the normal - // middleware flow of express/other integrations - - const url = req.url || ""; - const method = req.method || ""; - const controllerName = `Controller/${method.toUpperCase()} ${url}`; - - // Start a transaction that finished when res.end is called - return integration.scout.transaction(controllerName, finishTransaction => { - // Ensure the integration and instrument functions are stil present by the time we run - if (!integration.scout || !integration.scout.instrument) { - integration.logFn( - "[scout/integrations/nuxt] Integration broken or missing instrument function", - LogLevel.Warn, - ); - finishTransaction(); - return originalRender.apply(this, [req, res, next]); - } - - // Perform the instrumentation - return integration.scout.instrument(controllerName, () => { - // No need to finish the span explicitly since transaction finish will close interior spans - const originalResEnd = res.end; - res.end = function() { - finishTransaction(); - return originalResEnd.apply(this, arguments); - }; - - return originalRender.apply(this, [req, res, next]); - }); - }); - }; - - return instance; - }; - - // NOTE: we have to shim nuxt this way because the objects in it do *not* have setters - const rebuiltNuxtExport = {Nuxt}; - Object.keys(nuxtExport) - .filter(k => k !== "Nuxt") - .forEach(k => rebuiltNuxtExport[k] = nuxtExport[k]); - - return rebuiltNuxtExport; - } -} - -export default new NuxtIntegration(); diff --git a/package.json b/package.json index 5cabea15..75438360 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "test-integration-mustache": "tape 'dist/test/integrations/mustache.e2e.js'", "test-integration-ejs": "tape 'dist/test/integrations/ejs.e2e.js'", "test-integration-express": "tape 'dist/test/integrations/express.e2e.js'", - "test-integration-nuxt": "tape 'dist/test/integrations/nuxt.e2e.js'", "test-integration-ioredis": "tape 'dist/test/integrations/ioredis.e2e.js'", "test-integration-nest": "tape 'dist/test/integrations/nest.e2e.js'", "test-integration-prisma": "tape 'dist/test/integrations/prisma.e2e.js'", @@ -77,7 +76,6 @@ "mustache-express": "^1.3.2", "mysql": "^2.18.1", "mysql2": "^3.11.5", - "nuxt": "^2.18.1", "pg": "^8.13.1", "@prisma/client": "^5.22.0", "prisma": "^5.22.0", diff --git a/test/integrations/nuxt.e2e.ts b/test/integrations/nuxt.e2e.ts deleted file mode 100644 index 221e5837..00000000 --- a/test/integrations/nuxt.e2e.ts +++ /dev/null @@ -1,40 +0,0 @@ -import * as test from "tape"; -import * as request from "supertest"; -import { Express, Application } from "express"; - -import { - ScoutEvent, - buildScoutConfiguration, -} from "../../lib/types"; - -import { setupRequireIntegrations } from "../../lib"; - -import { - Scout, - ScoutRequest, - ScoutSpan, - ScoutEventRequestSentData, -} from "../../lib/scout"; - -// The hook for http has to be triggered this way in a typescript context -// since a partial import from scout itself (lib/index) will not run the setupRequireIntegrations() code -// *NOTE* this must be here since express is used from TestUtil -setupRequireIntegrations(["express", "nuxt"]); - -import * as TestUtil from "../util"; -import * as Constants from "../../lib/constants"; -import { getIntegrationSymbol } from "../../lib/types/integrations"; -import ExpressIntegration from "../../lib/integrations/express"; -import { scoutMiddleware, ApplicationWithScout } from "../../lib/express"; - -import { ScoutContextName, ScoutSpanOperation, ExpressFn } from "../../lib/types"; - -import { FILE_PATHS } from "../fixtures"; - -test("the shim works", t => { - t.assert(getIntegrationSymbol() in require("nuxt"), "nuxt export has the integration symbol"); - t.end(); -}); - -// https://github.com/scoutapp/scout_apm_node/issues/200 -// TODO: find a way to test nuxt as a part of this without building the entire nuxt project?