elastic / elastic/apm-agent-nodejs

Feature Request: Support NuxtJS

Open
#1,933 2 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

Description

NuxtJS is an up and coming "all-in-one" javascript framework that allows developers to build web pages and applications using the Vue.js frontend application and either [statically generate a site](https://nuxtjs.org/docs/2.x/concepts/static-site-generation) and host the generated files, or use Node.js as [a server side renderer](https://vuejs.org/v2/guide/ssr.html).

There's no obvious role for the Node.js Agent in a statically rendered NuxtJS application. Also, if users are using Node.js to serve out the statically rendered site themselves via Express, Hapi, etc. they should be able to instrument this simple web server with the agent already.

However, for a server side rendered site/application that's served out by Node.js there is a role for the agent.

In unclear what support for NuxtJS should look like -- if you're a NuxtJS user and have thoughts we'd love to hear from you.

## NuxtJS Early Bootstrap

NuxtJS provides a `nuxt` command line application for

1. Starting both a development and production server
2. Generating a static site
3. Building your source code

```
// File: package.json

"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",

/* ... */
},
```

This CLI application bootstraps the NuxtJS application [before the agent's require-in-the-middle](https://www.npmjs.com/package/require-in-the-middle) module can rewrite/monkey-patch a few critical core modules. The soonest a user can inject their own javascript is the `nuxt.config.js` file and by the time `nuxt` loads this file the CLI application has already required in the `http`/`https` module.

In other words, using the stock happy path tools it does not seem possible to start the agent before the `nuxt` application starts.

NuxtJS also uses [the `connect` framework](https://www.npmjs.com/package/connect) to load its server middleware. Supporting NuxtJS might mean instrumenting this module (the same way we instrument express, hapi, etc)

## NuxtJS as Express Middleware

Alternatively -- there's some science out there [for running NuxtJS applications under express](https://dev.to/taishi/do-you-know-how-to-use-nuxt-js-with-firebase-cloud-functions-2kni). This [is only hinted at](https://nuxtjs.org/faq/auth-routes#using-express-and-sessions) in the docs, but if this is a mainstream practice "supporting NuxtJS" might be as simple as documenting its use via express.

## NuxtJS Webpack Build

Finally -- the `nuxt` tool appears to use webpack to compile a running server. This compiled file lives at

.nuxt/dist/server/server.js

It may be possible to hook into the compiler an ensure that agent starting code is added at the top of the file.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.