How to send traces from Node.js OTEL SDK to Tempo?

In fact it’s not possible to define headers directly at the first level of the object, however via the metadata property:

const metadata = new grpc.Metadata();
metadata.add(
  "authorization",
  `Basic ${Buffer.from(
    `${process.env.TEMPO_USER}:${process.env.TEMPO_PASS}`
  ).toString("base64")}`
);

provider.addSpanProcessor(
  new BatchSpanProcessor(
    new OTLPTraceExporter({
      url: `tempo-eu-west-0.grafana.net:443`,
      metadata: metadata,
    })
  )
);
1 Like

For anyone else struggling with this, here’s the combination of configuration that worked for me:

  • I used the region-based tempo URL like tempo-us-central1.grafana.net:443.
  • I used the numeric user ID, like 123456 from https://<ORG_NAME>.grafana.net/datasources/edit/grafanacloud-traces labeled “User” under the “Basic Auth Details” section as the basic auth username.
  • I used an API key created at https://grafana.com/orgs/<ORG_NAME>/api-keys with MetricsPublisher role as the basic auth password.
    // The "OTEL_EXPORTER_OTLP_HEADERS" key needs to be exact 
    process.env.OTEL_EXPORTER_OTLP_HEADERS = `Authorization=Basic ${Buffer.from(
      process.env.GRAFANA_TEMPO_BASIC_AUTH_USERNAME +
      ':' +
      process.env.GRAFANA_TEMPO_BASIC_AUTH_PASSWORD,
    ).toString('base64')}`;

    return new opentelemetry.NodeSDK({
      traceExporter: new OTLPTraceExporter({
        url: process.env.GRAFANA_TRACE_ENDPOINT,
      }),
      instrumentations,
    });
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';

Also, I needed to use the @opentelemetry/exporter-trace-otlp-grpc package instead of the @opentelemetry/exporter-trace-otlp-proto package.

1 Like