Skip to content

Fix Next.js 14.2.x incompatibility #1141

@luismiramirez

Description

@luismiramirez

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed and unconfirmed bugs reported by us and customers.supportProblems or questions reported by customers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions