How to use the @opencensus/nodejs.tracer 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-ecosystem / opencensus-experiments / interoptest / src / nodejsservice / src / testservice / service-hopper.js View on Github external
return new Promise((resolve, reject) => {
    const id = request.getId();
    const name = request.getName();
    const hops = request.getServiceHopsList();

    // Adds reqId attribute
    const span = tracing.tracer.currentRootSpan;
    if (span) {
      span.addAttribute('reqId', id);
    }

    // Creates a test response
    const response = new interop.TestResponse();
    response.setId(id);
    if (hops.length === 0) {
      resolve(setSuccessStatus(response));
    } else {
      // Extracts data from first service hop.
      const firstHop = hops[0];
      const host = firstHop.getService().getHost() || constants.DEFAULT_HOST;
      const port = firstHop.getService().getPort();
      const restHops = hops.slice(1);
      const transport = firstHop
github thesandlord / Istio101 / code / code-opencensus-full / index.js View on Github external
return new Promise(async (res,rej)=>{
    const fibSpan = tracing.tracer.startChildSpan('Fibonacci Calculation')
    fibSpan.parentSpanId = span.id
    const num = fibonacci(Math.floor(Math.random() * 30));
    fibSpan.end()

    // Random sleep! Because everyone needs their sleep!
    const sleepSpan = tracing.tracer.startChildSpan('Sleep')
    sleepSpan.parentSpanId = span.id
    await sleep()
    sleepSpan.end()
    
    res({
        isOdd: Boolean(num%2),
        num
    })
    
  })
}
github thesandlord / Istio101 / code / code-opencensus-full / index.js View on Github external
app.get('/', async(req, res) => {

  const begin = Date.now()

  // Calculate a Fibbonacci Number and check if it is Odd or Even
  const childSpan = tracing.tracer.startChildSpan('Fibonacci Odd Or Even')
  const isOddOrEven = await oddOrEven(childSpan)
  childSpan.end()

  let up
  try {
    up = await request({url: upstream_uri})
  } catch (error) {
        up = error
  }
  const timeSpent = (Date.now() - begin) / 1000 + "secs (opencensus full)"

  res.end(`${service_name} - ${timeSpent} - num: ${isOddOrEven.num} - isOdd: ${isOddOrEven.isOdd}\n${upstream_uri} -> ${up}`)
})
github census-instrumentation / opencensus-node / packages / opencensus-exporter-zpages / src / zpages-frontend / page-handlers / traceconfigz.page-handler.ts View on Github external
private static extractSamplingProbability(): number {
    const samplingProbability = tracing.tracer.sampler.description;
    if (samplingProbability === 'always') {
      return 1;
    } else if (samplingProbability === 'never') {
      return 0;
    }
    const probability = samplingProbability.match(/\((.*)\)/);
    return probability ? Number(probability[1]) : 1 / 10000;
  }
}
github census-instrumentation / opencensus-node / packages / opencensus-exporter-zpages / src / zpages-frontend / page-handlers / traceconfigz.page-handler.ts View on Github external
private saveChanges(query: Partial): void {
    /** restore the config to default */
    if (query.change === 'restore_default') {
      tracing.tracer.sampler = SamplerBuilder.getSampler(
        this.defaultConfig!.samplingRate
      );
      return;
    }

    /** change the sampling probability value */
    if (query.samplingprobability) {
      tracing.tracer.sampler = SamplerBuilder.getSampler(
        query.samplingprobability
      );
    }
  }

@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