npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@opentelemetry/shim-opencensus

v0.51.1

Published

OpenCensus to OpenTelemetry shim

Downloads

135

Readme

OpenCensus shim

NPM Published Version Apache License

OpenCensus shim allows existing OpenCensus instrumentation to report to OpenTelemetry. This allows you to incrementally migrate your existing OpenCensus instrumentation to OpenTelemetry. More details are available in the OpenCensus Compatibility Specification.

Installation

npm install --save @opentelemetry/shim-opencensus

Tracing usage

Installing the shim's require-in-the-middle hook

This is the recommended way to use the shim for tracing.

This package provides a require-in-the-middle hook which replaces OpenCensus's CoreTracer class with a shim implementation that writes to the OpenTelemetry API. This will cause all usage of OpenCensus's tracing methods (in OpenCensus instrumentation or your own custom instrumentation) to be reported to OpenTelemetry.

There are two options for installing the hook:

  1. Using Node's --require flag to load the register module:

    node --require @opentelemetry/shim-opencensus/register ./app.js
  2. Programmatically:

    // Early in your application startup
    require('@opentelemetry/shim-opencensus').installShim();

    Note that this has to be run before any OpenCensus tracers have been created.

Replace OpenCensus tracer with the ShimTracer in your code

Alternatively, you can replace any usage of OpenCensus tracers in your code with the ShimTracer directly.

Before:

const tracing = require('@opencensus/nodejs');
const tracer = tracing.start({samplingRate: 1}).tracer;

// ...

tracer.startRootSpan({name: 'main'}, rootSpan => {
  rootSpan.end();
});

After:

const { trace } = require('@opentelemetry/api');
const { ShimTracer } = require('@opentelemetry/shim-opencensus');
const tracer = new ShimTracer(trace.getTracer('my-module'));  

// ...

tracer.startRootSpan({name: 'main'}, rootSpan => {
  rootSpan.end();
});

Metrics usage

OpenCensus metrics can be collected and sent to an OpenTelemetry exporter by providing the OpenCensusMetricProducer to your MetricReader. For example, to export OpenCensus metrics through the OpenTelemetry Prometheus exporter:

meterProvider.addMetricReader(
  new PrometheusExporter({
    metricProducers: [
      new OpenCensusMetricProducer({
        openCensusMetricProducerManager:
          oc.Metrics.getMetricProducerManager(),
      }),
    ],
  })
);

Example

See examples/opencensus-shim for a short example.

License

Apache 2.0 - See LICENSE for more information.

Useful links