How to use @opencensus/core - 10 common examples

To help you get started, we’ve selected a few @opencensus/core 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 keymetrics / pm2-io-apm / src / census / plugins / __tests__ / redis.spec.ts View on Github external
// For these tests, mongo must be runing. Add OPENCENSUS_REDIS_TESTS to run
  // these tests.
  const OPENCENSUS_REDIS_TESTS =
      process.env.OPENCENSUS_REDIS_TESTS as string
  const OPENCENSUS_REDIS_HOST =
      process.env.OPENCENSUS_REDIS_HOST as string
  let shouldTest = true
  if (!OPENCENSUS_REDIS_TESTS) {
    console.log('Skipping test-redis. Run REDIS to test')
    shouldTest = false
  }

  const URL = `redis://${OPENCENSUS_REDIS_HOST || 'localhost'}:6379`
  const VERSION = '2.8.0'

  const tracer = new CoreTracer()
  const rootSpanVerifier = new RootSpanVerifier()
  let client: redis.RedisClient

  before((done) => {
    tracer.start({ samplingRate: 1, logger: logger.logger(4) })
    tracer.registerSpanEventListener(rootSpanVerifier)
    plugin.enable(redis, tracer, VERSION, {}, '')
    client = redis.createClient({
      url: URL
    })
    client.on('error', (err: Error) => {
      console.log(
        'Skipping test-redis. Could not connect. Run Redis to test', err)
      shouldTest = false
      done()
    })
github keymetrics / pm2-io-apm / src / census / plugins / __tests__ / ioredis.spec.ts View on Github external
// For these tests, mongo must be runing. Add OPENCENSUS_REDIS_TESTS to run
  // these tests.
  const OPENCENSUS_REDIS_TESTS =
      process.env.OPENCENSUS_REDIS_TESTS as string
  const OPENCENSUS_REDIS_HOST =
      process.env.OPENCENSUS_REDIS_HOST as string
  let shouldTest = true
  if (!OPENCENSUS_REDIS_TESTS) {
    console.log('Skipping test-redis. Run REDIS to test')
    shouldTest = false
  }

  const URL = `redis://${OPENCENSUS_REDIS_HOST || 'localhost'}:6379`
  const VERSION = '4.6.2'

  const tracer = new CoreTracer()
  const rootSpanVerifier = new RootSpanVerifier()
  let client: ioredis.Redis

  before((done) => {
    tracer.start({ samplingRate: 1, logger: logger.logger(4) })
    tracer.registerSpanEventListener(rootSpanVerifier)
    plugin.enable(ioredis, tracer, VERSION, {}, '')
    client = new ioredis(URL)
    client.on('error', (err: Error) => {
      console.log(
        'Skipping test-redis. Could not connect. Run Redis to test', err)
      shouldTest = false
      done()
    })
    client.on('ready', done)
  })
github VilledeMontreal / workit / packages / workit-camunda / sample / tasks / helloWorldTaskV2.ts View on Github external
public async execute(message: IMessage): Promise {
      const { properties } = message;

      console.log(`Executing task: ${properties.activityId} with the class HelloWorldTaskV2`);
      console.log(`${properties.bpmnProcessId}::${properties.processInstanceId} Servus!`);
      console.log(`version: ${properties.workflowDefinitionVersion}`);
      
      const response = await axios.get('https://jsonplaceholder.typicode.com/todos/1');
      const tracer = tracerService.getTracer();
      const span = tracer.startChildSpan({ name: 'customSpan', kind: SpanKind.CLIENT });
      
      console.log();
      console.log('data:');
      console.log(response.data);
      // put your business logic here
      span.end();
      return Promise.resolve(message);
  }
}
github census-instrumentation / opencensus-node / examples / stats / web_client_monitoring / app.js View on Github external
app.use(bodyParser.json());

// The project id must be provided for running in a local environment
const project = process.env.GOOGLE_CLOUD_PROJECT;
assert(typeof project !== 'undefined' && project,
  "Please set environment variable GOOGLE_CLOUD_PROJECT to the project id.");
console.log(`Sending metrics data to project: ${project}`);

// OpenCensus setup
// [START web_client_monitoring_ocsetup]
const exporter = new StackdriverStatsExporter({projectId: project});
globalStats.registerExporter(exporter);
const mLatencyMs = globalStats.createMeasureDouble("webmetrics/latency",
                       MeasureUnit.MS,
                       "Latency related to page loading");
const mClickCount = globalStats.createMeasureInt64("webmetrics/click_count",
                       MeasureUnit.UNIT,
                       "Number of clicks");
const buckets = [0, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80,
                100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000,
                5000, 10000, 20000, 50000, 100000];

const tagPhase = { name: "phase" };
const tagClient = { name: "client" };

const latencyView = globalStats.createView(
  "webmetrics/latency",
  mLatencyMs,
  AggregationType.DISTRIBUTION,
  [tagPhase, tagClient],
  "Distribution of latencies",
  buckets
github census-instrumentation / opencensus-node / examples / stats / exporter / prometheus.js View on Github external
tags.set(methodKey, { value: 'REPL' });
    tags.set(statusKey, { value: 'OK' });

    globalStats.record([{
      measure: mLineLengths,
      value: processedLine.length
    }], tags);

    globalStats.record([{
      measure: mLatencyMs,
      value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
    }], tags);
  } catch (err) {
    console.log(err);

    const errTags = new TagMap();
    errTags.set(methodKey, { value: 'repl' });
    errTags.set(statusKey, { value: 'ERROR' });
    globalStats.record([{
      measure: mLatencyMs,
      value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
    }], errTags);
  }

  // Restarts the start time for the REPL
  startNanoseconds = endNanoseconds;
});
github census-instrumentation / opencensus-node / examples / stats / exporter / stackdriver.js View on Github external
tags.set(methodKey, { value: 'REPL' });
    tags.set(statusKey, { value: 'OK' });

    globalStats.record([{
      measure: mLineLengths,
      value: processedLine.length
    }], tags);

    globalStats.record([{
      measure: mLatencyMs,
      value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
    }], tags);
  } catch (err) {
    console.log(err);

    const errTags = new TagMap();
    errTags.set(methodKey, { value: 'repl' });
    errTags.set(statusKey, { value: 'ERROR' });
    globalStats.record([{
      measure: mLatencyMs,
      value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
    }], errTags);
  }

  // Restarts the start time for the REPL
  startNanoseconds = endNanoseconds;
});
github census-instrumentation / opencensus-node / examples / stats / exporter / prometheus.js View on Github external
lineReader.on('line', function (line) {
  // Read
  try {
    const processedLine = processLine(line); // Evaluate
    console.log(processedLine); // Print

    // Registers the end of our REPL
    [_, endNanoseconds] = process.hrtime();

    const tags = new TagMap();
    tags.set(methodKey, { value: 'REPL' });
    tags.set(statusKey, { value: 'OK' });

    globalStats.record([{
      measure: mLineLengths,
      value: processedLine.length
    }], tags);

    globalStats.record([{
      measure: mLatencyMs,
      value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
    }], tags);
  } catch (err) {
    console.log(err);

    const errTags = new TagMap();
github census-instrumentation / opencensus-node / examples / stats / web_client_monitoring / app.js View on Github external
value: 1
    }], tags);

    tags.set(tagPhase, { value: valueTLSNegotiation });
    globalStats.record([{
      measure: mLatencyMs,
      value: 1
    }], tags);

    tags.set(tagPhase, { value: valueLoad });
    globalStats.record([{
      measure: mLatencyMs,
      value: 1
    }], tags);

    const tags1 = new TagMap();
    tags1.set(tagClient, { value: valueWeb });
    globalStats.record([{
      measure: mClickCount,
      value: 1
    }], tags1);
    res.status(200).send("Received").end();
    console.log('Competed recording metrics');
  } catch (err) {
    console.log(`Could not save stats: ${err}`);
    res.status(500).send("Error saving stats").end();
  }
  // [END web_client_monitoring_record]
});
github census-instrumentation / opencensus-node / examples / stats / exporter / stackdriver.js View on Github external
lineReader.on('line', function (line) {
  // Read
  try {
    const processedLine = processLine(line); // Evaluate
    console.log(processedLine); // Print

    // Registers the end of our REPL
    [_, endNanoseconds] = process.hrtime();

    const tags = new TagMap();
    tags.set(methodKey, { value: 'REPL' });
    tags.set(statusKey, { value: 'OK' });

    globalStats.record([{
      measure: mLineLengths,
      value: processedLine.length
    }], tags);

    globalStats.record([{
      measure: mLatencyMs,
      value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
    }], tags);
  } catch (err) {
    console.log(err);

    const errTags = new TagMap();
github census-instrumentation / opencensus-node / examples / stats / web_client_monitoring / app.js View on Github external
const app = express();
app.use(express.static("web_client"));
app.use(bodyParser.json());

// The project id must be provided for running in a local environment
const project = process.env.GOOGLE_CLOUD_PROJECT;
assert(typeof project !== 'undefined' && project,
  "Please set environment variable GOOGLE_CLOUD_PROJECT to the project id.");
console.log(`Sending metrics data to project: ${project}`);

// OpenCensus setup
// [START web_client_monitoring_ocsetup]
const exporter = new StackdriverStatsExporter({projectId: project});
globalStats.registerExporter(exporter);
const mLatencyMs = globalStats.createMeasureDouble("webmetrics/latency",
                       MeasureUnit.MS,
                       "Latency related to page loading");
const mClickCount = globalStats.createMeasureInt64("webmetrics/click_count",
                       MeasureUnit.UNIT,
                       "Number of clicks");
const buckets = [0, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80,
                100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000,
                5000, 10000, 20000, 50000, 100000];

const tagPhase = { name: "phase" };
const tagClient = { name: "client" };

const latencyView = globalStats.createView(
  "webmetrics/latency",
  mLatencyMs,
  AggregationType.DISTRIBUTION,