Opentelemetry-js: ReferenceError: BatchSpanProcessor is not defined

Created on 13 Nov 2019  路  6Comments  路  Source: open-telemetry/opentelemetry-js

Please answer these questions before submitting a bug report.

What version of OpenTelemetry are you using?

latest

What version of Node are you using?

latest

What did you do?

If possible, provide a recipe for reproducing the error.

const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');

const opentelemetry = require('@opentelemetry/core');
const { NodeTracer } = require('@opentelemetry/node');

// Create and initialize NodeTracer
const tracer = new NodeTracer();


const exporter = new JaegerExporter({ serviceName: 'hello-world' });
tracer.addSpanProcessor(new BatchSpanProcessor(exporter));

// Initialize the tracer
opentelemetry.initGlobalTracer(tracer);

What did you expect to see?

tracing

What did you see instead?

ReferenceError: BatchSpanProcessor is not defined

Additional context

Would be nice to have an example with both automated instrumentation + export (jaeger or zipkin) ... is the above ordering correct?

bug

Most helpful comment

I think there is a sample using jeager/zipkin and autoinstrumentation in folder examples/http.

In your sample there is nothing like const { BatchSpanProcessor } = require('@opentelemetry/tracing');.

All 6 comments

I think there is a sample using jeager/zipkin and autoinstrumentation in folder examples/http.

In your sample there is nothing like const { BatchSpanProcessor } = require('@opentelemetry/tracing');.

Thanks @Flarna, taking from the example you . mentioned I was able to achieve instrumentation and export to jaeger with the following config.

const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const opentelemetry = require('@opentelemetry/core');
const { NodeTracer } = require('@opentelemetry/node');
const { BatchSpanProcessor } = require('@opentelemetry/tracing');

// Create and initialize NodeTracer
const tracer = new NodeTracer({
  plugins: {
    http: {
      enabled: true,
      // You may use a package name or absolute path to the file.
      path: '@opentelemetry/plugin-http',
      // http plugin options
    },
  },
});

const exporter = new JaegerExporter({ serviceName: 'hello-world' });
tracer.addSpanProcessor(new BatchSpanProcessor(exporter));

// Initialize the tracer
opentelemetry.initGlobalTracer(tracer);

However there is an issue when we do not have the http plugin installed, my understanding is that it would fetch the required plugin automatically but it errors out with: PluginLoader#load: applying patch to [email protected] using @opentelemetry/plugin-http module PluginLoader#load: could not load plugin @opentelemetry/plugin-http of module http. Error: Cannot find module '@opentelemetry/plugin-http' I will create a separate issue.

The simpler way is: const tracer = new NodeTracer(); <= just initialize NodeTracer. No need to pass plugins config unless you want to override default values (like path, ignoreUrls, ignoreMethods etc.).

Thanks @mayurkale22 but this is actually the message i get when initializing the tracer without any plugins config (or with the plugin config, but the plugin not explicitly installed)

That's to say both

const tracer = new NodeTracer();

And

const tracer = new NodeTracer({
  plugins: {
    http: {
      enabled: true,
      // You may use a package name or absolute path to the file.
      path: '@opentelemetry/plugin-http',
      // http plugin options
    },
  },
});

(without @opentelemetry/plugin-http in node_modules)

yield :

PluginLoader#load: trying loading [email protected]
PluginLoader#load: applying patch to [email protected] using @opentelemetry/plugin-http module
PluginLoader#load: could not load plugin @opentelemetry/plugin-http of module http. Error: Cannot find module '@opentelemetry/plugin-http'

Should I open a separate issue?

Should I open a separate issue?

That would be ideal and we can close this one.

The temporary workaround is that you can install the package(npm install @opentelemetry/plugin-http) manually in order to work the HTTP instrumentation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MadRabbit picture MadRabbit  路  6Comments

rbruggem picture rbruggem  路  5Comments

naseemkullah picture naseemkullah  路  4Comments

naseemkullah picture naseemkullah  路  5Comments

backkem picture backkem  路  6Comments