Next.js Discord

Discord Forum

Migrating 14.0.4 to 14.2.0 getting /metrics 404

Unanswered
Mud-daubers posted this in #help-forum
Open in Discord
Mud-daubersOP
I just attempted upgrading my existing app router based app from 14.0.4 to 14.2.0 and all seems to be working, except I'm getting constant server log message of /metrics 404 in <20-200 ms>

Anyone know how to get rid of this?

62 Replies

Mud-daubersOP
To clarify, this shows up in the next.js bash terminal, not the VSC debug console, as launched from a launch.json of

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Next.js: debug server-side",
      "type": "node-terminal",
      "request": "launch",
      "command": "npm run dev --turbo"
    }
  ]
}
I added a metrics/route.ts just to get rid of 404's, but still getting 200s constantly
Debugger attached.

> dashboard3@0.1.0 dev
> next dev

Debugger attached.
Debugger attached.
  ▲ Next.js 14.2.0
  - Local:        http://localhost:3000
  - Environments: .env.development, .env

 ✓ Starting...
Debugger attached.
Waiting for the debugger to disconnect...
 ✓ Ready in 7.2s
 ○ Compiling /metrics ...
 ✓ Compiled /metrics in 1697ms (54 modules)
 GET /metrics 200 in 1106ms
 GET /metrics 200 in 1931ms
 GET /metrics 200 in 19ms
 GET /metrics 200 in 15ms
 GET /metrics 200 in 11ms
 GET /metrics 200 in 9ms
 GET /metrics 200 in 34ms

as example
Mud-daubersOP
will try that. Also just rolling back to 14.0.4 to make sure it's not one of the other packages upgraded at the same time
and does it happen with different browser?
Mud-daubersOP
it's happening without ever loading it in a browser, just immediately on launching the dev server it starts populating the launch terminal
PORT=4000 npm run dev
@Ray `PORT=4000 npm run dev`
just to make sure, not other program trying to access it
Mud-daubersOP
will do. I rolled back to 14.0.4 only (leaving all the other package upgrades done at same time) and I'm not getting the metrics hit, so think it's coming from the 14.2 upgrade. I'm trying now with the console log and different port
Mud-daubersOP
how odd. changing the port to 4000 it's no longer giving that. Changing it back just to make sure i'm not insane (also this revealed how bad I've been about hardcoding localhost:3000 everywhere :D)
Mud-daubersOP
just a couple of fetch's that were making api calls
Yup though, switching back to 3000 it comes back
This is the console.log
✓ Compiled /metrics in 4s (54 modules)
NextRequest [Request] {
  [Symbol(realm)]: {
    settingsObject: { baseUrl: undefined, origin: [Getter], policyContainer: [Object] }
  },
  [Symbol(state)]: {
    method: 'GET',
    localURLsOnly: false,
    unsafeRequest: false,
    body: null,
    client: { baseUrl: undefined, origin: [Getter], 
guh, keeps clipping it. sec.
reservedClient: null,
    replacesClientId: '',
    window: 'client',
    keepalive: false,
    serviceWorkers: 'all',
    initiator: '',
    destination: '',
    priority: null,
    origin: 'client',
    policyContainer: 'client',
    referrer: 'client',
    referrerPolicy: '',
    mode: 'cors',
    useCORSPreflightFlag: false,
    credentials: 'same-origin',
    useCredentials: false,
    cache: 'default',
    redirect: 'follow',
    integrity: '',
    cryptoGraphicsNonceMetadata: '',
    parserMetadata: '',
    reloadNavigation: false,
    historyNavigation: false,
    userActivation: false,
    taintedOrigin: false,
    redirectCount: 0,
    responseTainting: 'basic',
    preventNoCacheCacheControlHeaderModification: false,
    done: false,
    timingAllowFailed: false,
    headersList: _HeadersList {
      cookies: null,
      [Symbol(headers map)]: [Map],
      [Symbol(headers map sorted)]: [Array]
    },
 urlList: [ URL {} ],
    url: URL {
      href: 'http://localhost:3000/metrics',
      origin: 'http://localhost:3000',
      protocol: 'http:',
      username: '',
      password: '',
      host: 'localhost:3000',
      hostname: 'localhost',
      port: '3000',
      pathname: '/metrics',
      search: '',
      searchParams: URLSearchParams {},
      hash: ''
    }
  },
  [Symbol(signal)]: AbortSignal { aborted: false },
  [Symbol(abortController)]: AbortController { signal: AbortSignal { aborted: false } },
  [Symbol(headers)]: _HeadersList {
    cookies: null,
    [Symbol(headers map)]: Map(9) {
      'accept' => [Object],
      'accept-encoding' => [Object],
      'connection' => [Object],
      'host' => [Object],
      'user-agent' => [Object],
      'x-forwarded-for' => [Object],
      'x-forwarded-host' => [Object],
      'x-forwarded-port' => [Object],
      'x-forwarded-proto' => [Object]
    },
    [Symbol(headers map sorted)]: [
      [Array], [Array],
      [Array], [Array],
      [Array], [Array],
      [Array], [Array],
      [Array]
    ]
  },
  [Symbol(internal request)]: {
    cookies: RequestCookies { _parsed: Map(0) {}, _headers: [_HeadersList] },
    geo: {},
    ip: undefined,
    nextUrl: NextURL { [Symbol(NextURLInternal)]: [Object] },
    url: 'http://localhost:3000/metrics'
  }
}
 GET /metrics 200 in 4229ms
Anyways, I'll switch ports to 4000 I suppose as that sorts it, but I'm curious what that actually is
or vscode
Mud-daubersOP
can try, though this doesn't feel like it's anything external, it comes and goes between 14.0.4 and 14.2 with that package upgrade the only change
do you see it with npm run build && npm run start?
Mud-daubersOP
Rebooted everything, ran it purely through ssh commandline to make sure it wasn't something with VSC and it appears there when I'm using port 3000. With PORT=4000 npm run dev it doesn't do it.
let me try with build/start
Mud-daubersOP
I haven't actually tried to run build and start in months honestly. Been in prototype development mode
/** @type {import('next').NextConfig} */
const nextConfig = {
  // causes all pages to render twice, which is good for shaking out problems, but sucks for debugging
  reactStrictMode: false, // Recommended for the `pages` directory, default in `app`.
  swcMinify: true,
  compiler: {
    // Enables the styled-components SWC transform
    styledComponents: true,
  },
  experimental: {
    optimizePackageImports: ['package-name'],
  },
};

module.exports = nextConfig;
I think it only happen in dev mode
Mud-daubersOP
wouldn't shock me if it's dev only. Weird though
running with start now
yeah and not sure why it only happen on port 3000 :lolsob:
Mud-daubersOP
there isn't any sort of opt-out collecting developer metrics sort of thing in next.js is there?
yeah, npm run start there's no metrics hit
super weird
@Mud-daubers yeah, npm run start there's no metrics hit
do you still have console.log in the route.ts?
Mud-daubersOP
yeah
ok
Mud-daubersOP
never getting hit
and doesn't hit when I do PORT=4000
is it possible to share the repo? so I can try it on my machine?
Mud-daubersOP
Can't sadly. I can share the package.json, but not the codebase
have you tried starting the server without turbo?
Mud-daubersOP
yeah, with and without happens on 3000
that's strange
Mud-daubersOP
too big to paste without nitro, if you would prefer it just in markup text, I can cut it into chunks and paste here
its ok
I just tried that
no issue
Mud-daubersOP
npm run dev is same as next dev right? for some reason next cli isn't working on my current dev vm
Mud-daubersOP
Going to try this other direction, roll my entire package.json back and only upgrade 14.2, double check it didn't come from one of the other upgrades
Mud-daubersOP
well that's interesting. If I roll back to 14.0.4 but leave the route.ts with /metrics/route.ts unstashed, that endpoint is getting hit still. But if I stash the /metrics endpoint so it doesn't exist, I get no 404 or any other console messages about /metrics
So it's like older version still tries constantly to hit /metrics but doesn't log the failure, where new version logs a 404. Wildly odd. I'll have to try and spin it up later in a clean docker development image to make sure it's not just something odd in my local dev environment