Giter Site home page Giter Site logo

Support of Next js ^14 about apm-agent-nodejs HOT 2 OPEN

vbuhaiov avatar vbuhaiov commented on June 1, 2024 4
Support of Next js ^14

from apm-agent-nodejs.

Comments (2)

trentm avatar trentm commented on June 1, 2024

@vbuhaiov Thanks for opening the issue.

Our hope is to support tracing of recent Next.js versions via OpenTelemetry support that Next.js has added to its core.
However, this isn't a well trodden path yet, so there may likely be limitations/bugs.

The current Next.js instrumentation in the Elastic Node.js APM agent (experimental, and limited to next <13.3.0) has proven to be brittle. Changes in the minor version of Next.js releases tended to break the instrumentation. We feel the addition of @opentelemetry/api usage in the next core package is a better architectural path.

We haven't yet had a chance to try to work through it, but this is how I see it working:

  • Enable the elastic-apm-node's OpenTelemetry tracing bridge via ELASTIC_APM_OPENTELEMETRY_BRIDGE_ENABLED=true. This tells the Elastic Node.js APM agent to register an OpenTelemetry "TracerProvider" so that usage of the @opentelemetry/api in the Node.js app will be picked up by the APM agent and translated to Elastic APM tracing data.

Really that should be the only required step.

Unfortunately we don't have a current timeline for looking into this.

Some notes/thoughts on troubleshooting this:

  • I don't know if bundling, that may be common in Next.js apps, might cause surprises.
  • As long as Next is using @opentelemetry/api@^1.0.0 it should be fine. However, OTel is generally setup to be silent if not registered, so if there is a hiccup, it can be a little hard to diagnose.

from apm-agent-nodejs.

ale180192 avatar ale180192 commented on June 1, 2024

Do you have any estimations regarding support of nextjs 14 ?

Is your feature request related to a problem? Please describe. Not able to use APM with the latest next js versions ^14. No package was found during node ./server.js

Describe the solution you'd like Increase a supported version to the ^14

Describe alternatives you've considered No alternatives, it is not supported and the build does not work

Additional context ./package.json "dependencies": { "elastic-apm-node": "^4.4.0", "next": "14.1.0" },

Dockerfile FROM node:18-alpine AS base

I'm using almost the same version and it's working (I also see the unsupported version but it seems it's not affecting)

{
  "name": "xxx",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": " NODE_OPTIONS=--require=elastic-apm-node/start-next.js dotenv -e ./../.env.local -- next dev",
    "dev:build": "dotenv -e ./../.env.local -- next build",
    "build": "next build",
    "start": "NODE_OPTIONS=--require=elastic-apm-node/start-next.js next start -H 0.0.0.0",
    "lint": "NODE_OPTIONS=--require=elastic-apm-node/start-next.js next lint",
    "migrate:dev": "dotenv -e ./../.env.local -- npx prisma migrate dev",
    "migrate:deploy": "dotenv -e -- npx prisma migrate deploy",
    "migrate:format": "dotenv -e ./../.env.local -- npx prisma format",
    "migrate:generate": "dotenv -e ./../.env.local -- npx prisma generate",
    "migrate:reset": "dotenv -e ./../.env.local -- npx prisma migrate reset",
    "db:seed": "dotenv -e ./../.env.local -- npx prisma db seed"
  },
  "prisma": {
    "seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
  },
  "dependencies": {
    "@prisma/client": "^5.9.1",
    "console-log-level": "^1.4.1",
    "dotenv-cli": "^7.3.0",
    "elastic-apm-node": "^4.4.1",
    "next": "14.1.0",
    "openai": "^4.28.0",
    "react": "^18",
    "react-dom": "^18"
  },
  "devDependencies": {
    "@types/node": "^20.11.17",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "@typescript-eslint/parser": "^7.0.2",
    "autoprefixer": "^10.0.1",
    "eslint": "^8",
    "eslint-config-next": "14.1.0",
    "postcss": "^8",
    "prettier-eslint": "^16.3.0",
    "prisma": "^5.9.1",
    "tailwindcss": "^3.3.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.3.3"
  }
}

this is my elastic-apm-node.js file

module.exports = {
  serverUrl: process.env.ELASTIC_APM_SERVER_URL,
  secretToken: process.env.ELASTIC_APM_SECRET_TOKEN,
  active: true,
  logLevel: "error",
  logger: false,
  verifyServerCert: false,
  usePathAsTransactionName: true,
  opentelemetryBridgeEnabled: false,
};

and this is my apm-server definition

cat > apm_server.yaml <<EOF
apiVersion: apm.k8s.elastic.co/v1
kind: ApmServer
metadata:
  name: pergamino-apm-server
  namespace: $NAMESPACE
spec:
  version: 8.12.1
  count: 1
  elasticsearchRef:
    name: $PREFIX_NAME
  kibanaRef:
    name: $PREFIX_NAME
  http:
    tls:
      selfSignedCertificate:
        disabled: true
        subjectAltNames:
        - dns: pergamino-apm-server-apm-http.default.svc.cluster.local
EOF

I hope this configuration helps someone.

from apm-agent-nodejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.