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

Support of Next js ^14 #3855

Open
vbuhaiov opened this issue Jan 31, 2024 · 2 comments
Open

Support of Next js ^14 #3855

vbuhaiov opened this issue Jan 31, 2024 · 2 comments
Labels
agent-nodejs Make available for APM Agents project planning. community

Comments

@vbuhaiov
Copy link

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

@github-actions github-actions bot added agent-nodejs Make available for APM Agents project planning. community triage labels Jan 31, 2024
@trentm
Copy link
Member

trentm commented Feb 2, 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.

@trentm trentm removed the triage label Feb 2, 2024
@ale180192
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning. community
Projects
None yet
Development

No branches or pull requests

3 participants