bradb123
bradb123

Reputation: 21

OpenTelemetry Next.js - <root span not yet received> for Service field and empty Name field for traces in Grafana

I've implemented tracing on my Next.js app using OpenTelemetry (my implementation is below). The app sends the traces to my Grafana Agent which then forwards them onto Tempo.

However, when looking at the traces in Grafana using the Tempo trace table, the majority of the traces have 'root span not yet received' for the Service field and an empty Name field (see link below). But when you click the Trace ID to show the full trace, the correct Service and Name field is present.

Does anyone know why this is happening and if it is possible to resolve?

Grafana trace table

const { NodeSDK } = require('@opentelemetry/sdk-node');
const { PeriodicExportingMetricReader, ConsoleMetricExporter } = require('@opentelemetry/sdk-metrics');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-grpc');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');

const sdk = new NodeSDK({
 traceExporter: new OTLPTraceExporter(),
  metricReader: new PeriodicExportingMetricReader({
    exporter: new OTLPMetricExporter(),
  }),
  instrumentations: [
    getNodeAutoInstrumentations({
      '@opentelemetry/instrumentation-fs': {
        enabled: false,
      },
      '@opentelemetry/instrumentation-http': {
          // This gives your request spans a more meaningful name than `HTTP GET`
          requestHook: (span, request) => {
            span.updateName( `${request.method} ${request.url || request.path}` );
            // The below is not working
            //span.setAttribute('http.route', request.path);
          },
       },
    }),
  ]
});

sdk.start();

Upvotes: 0

Views: 1475

Answers (1)

Everton Arakaki
Everton Arakaki

Reputation: 11

If you run your application locally, is this behavior the same?

If not, this indicates your system is not the first one on the chain of OTEL to generate the trace. The collector will not show the service name because it's waiting for the upstream system to send's the trace information.

To fix, you could identify the upstream service (ingress nginx, message system, cloud api gateway) and make then forward the traces to tempo.

If your upstream service is already forwarding the traces to tempo and you still see <root span not yet received>, check if any otel processor rule is dropping the root trace.

Upvotes: 0

Related Questions