Skip to content
Advertisement

@opentelemetry/sdk-node vs @opentelemetry/sdk-tracing-node

I am trying to play with open telemetry in a Node application. I find it a bit confusing that some examples ask me to install the @opentelemetry/sdk-node (like this official guide), while some others ask me to install @opentelemetry/sdk-tracing-node (like this one, also offical guide).

The examples that require @opentelemetry/sdk-node have code like this:

const sdk = new opentelemetry.NodeSDK({
  traceExporter: new opentelemetry.tracing.ConsoleSpanExporter(),
  instrumentations: [
    // instrumentations...
  ]
});

sdk.start()

The ones using @opentelemetry/sdk-tracing-node are like this:

registerInstrumentations({
  instrumentations: [
    // instrumentations...
  ]
});

const provider = new NodeTracerProvider();
const exporter = new ConsoleSpanExporter();
const processor = new BatchSpanProcessor(exporter);
provider.addSpanProcessor(processor);

provider.register();

They are somewhat similar, and I guess they achieve the same thing in the end. The questions are:

  • what’s the difference between these two approaches?
  • is one of them better, maybe more recommended nowadays?

Advertisement

Answer

sdk-node also brings the metrics and logs SDK while sdk-tracing-node only brings tracing SDK.

If you only care about tracing for now and want to avoid pulling useless dependencies, you can use sdk-tracing-node.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement