How to use the @opencensus/nodejs.registerExporter function in @opencensus/nodejs

To help you get started, we’ve selected a few @opencensus/nodejs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github census-instrumentation / opencensus-node / examples / grpc / capitalize_client.js View on Github external
// for more details.
  // Expects ADCs to be provided through the environment as ${GOOGLE_APPLICATION_CREDENTIALS}
  // A Stackdriver workspace is required and provided through the environment as ${GOOGLE_PROJECT_ID}
  const projectId = process.env.GOOGLE_PROJECT_ID;

  // GOOGLE_APPLICATION_CREDENTIALS are expected by a dependency of this code
  // Not this code itself. Checking for existence here but not retaining (as not needed)
  if (!projectId || !process.env.GOOGLE_APPLICATION_CREDENTIALS) {
    throw Error('Unable to proceed without a Project ID');
  }

  // Creates Stackdriver exporter
  const exporter = new StackdriverTraceExporter({ projectId: projectId });

  // Starts Stackdriver exporter
  tracing.registerExporter(exporter).start();

  // Starts tracing and set sampling rate
  const tracer = tracing.start({
    samplingRate: 1 // For demo purposes, always sample
  }).tracer;

  // Defines basedir and version
  const basedir = path.dirname(require.resolve('grpc'));
  const version = require(path.join(basedir, 'package.json')).version;

  // Enables GRPC plugin: Method that enables the instrumentation patch.
  plugin.enable(grpc, tracer, version, /** plugin options */{}, basedir);

  return tracer;
}
github census-instrumentation / opencensus-node / examples / grpc / capitalize_server.js View on Github external
// See https://developers.google.com/identity/protocols/application-default-credentials
  // for more details.
  // Expects ADCs to be provided through the environment as ${GOOGLE_APPLICATION_CREDENTIALS}
  // A Stackdriver workspace is required and provided through the environment as ${GOOGLE_PROJECT_ID}
  const projectId = process.env.GOOGLE_PROJECT_ID;

  // GOOGLE_APPLICATION_CREDENTIALS are expected by a dependency of this code
  // Not this code itself. Checking for existence here but not retaining (as not needed)
  if (!projectId || !process.env.GOOGLE_APPLICATION_CREDENTIALS) {
    throw Error('Unable to proceed without a Project ID');
  }
  // Creates Stackdriver exporter
  const exporter = new StackdriverTraceExporter({ projectId: projectId });

  // Starts Stackdriver exporter
  tracing.registerExporter(exporter).start();

  // Starts tracing and set sampling rate
  const tracer = tracing.start({
    samplingRate: 1 // For demo purposes, always sample
  }).tracer;

  // Defines basedir and version
  const basedir = path.dirname(require.resolve('grpc'));
  const version = require(path.join(basedir, 'package.json')).version;

  // Enables GRPC plugin: Method that enables the instrumentation patch.
  plugin.enable(grpc, tracer, version, /** plugin options */{}, basedir);

  return tracer;
}

@opencensus/nodejs

OpenCensus is a toolkit for collecting application performance and behavior data.

Apache-2.0
Latest version published 4 years ago

Package Health Score

47 / 100
Full package analysis