appsignal-nodejs icon indicating copy to clipboard operation
appsignal-nodejs copied to clipboard

Fix Next.js 14.2.x incompatibility

Open luismiramirez opened this issue 1 year ago • 2 comments

Next.js 14.2.x applications don't report spans to the agent.

When configured following the docs, the agent starts, and host metrics work. However, Next.js spans aren't reported, and the AppSignal OpenTelemetry tracer isn't able to identify the current span nor create new ones.

Next.js built-in instrumentation works as the emitted spans can be seen when adding a ConsoleSpanExporter()

instrumentation.ts file to output spans in console and to run AppSignal at the same time.

export async function register() {
  if (process.env.NEXT_RUNTIME === "nodejs") {
    try {
      const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
      const { BatchSpanProcessor } = require("@opentelemetry/sdk-trace-base");
      const { ConsoleSpanExporter } = require("@opentelemetry/sdk-trace-base");

      const provider = new NodeTracerProvider();

      // Just for testing, let's output to console
      provider.addSpanProcessor(new BatchSpanProcessor(new ConsoleSpanExporter()));

      provider.register();
      console.log("Tracer provider registered");

      require("./appsignal.cjs");
    } catch (error) {
      console.error("Failed to initialize OpenTelemetry:", error);
    }
  }
}

Next.js 13.x, 14.1.x, and 15 work.

Internal link

luismiramirez avatar Oct 22 '24 14:10 luismiramirez

https://app.intercom.com/a/inbox/yzor8gyw/inbox/admin/4356044/conversation/16410700367592?view=List (Private link)

shairyar avatar Oct 23 '24 05:10 shairyar

  • This issue has not had any activity in 14 days. Please provide a status update if it is still relevant. Closed it if it is no longer relevant. Or move it to another column if it's blocked or requires another look at it. - (More info)

This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

backlog-helper[bot] avatar Nov 06 '24 09:11 backlog-helper[bot]