opentelemetry-js/experimental/examples/opencensus-shim
OpenTelemetry Bot 2d3760898c
chore: prepare next release (#5921)
2025-09-10 09:12:38 +00:00
..
images docs: update OpenCensus shim example for metrics (#4078) 2023-09-19 11:07:26 +02:00
README.md chore(lint): refactor Markdown linting to use markdownlint-cli2 (#4713) 2024-05-21 14:44:23 +02:00
client.js docs(opencensus-shim) add an example showing how to use the opencensus shim (#3778) 2023-06-14 16:39:12 +02:00
package.json chore: prepare next release (#5921) 2025-09-10 09:12:38 +00:00
server.js docs: update OpenCensus shim example for metrics (#4078) 2023-09-19 11:07:26 +02:00
setup.js docs: update from deprecated SEMRESATTRS_SERVICE_NAME to ATTR_SERVICE_NAME (#5604) 2025-04-10 07:35:26 +00:00
utils.js docs(opencensus-shim) add an example showing how to use the opencensus shim (#3778) 2023-06-14 16:39:12 +02:00

README.md

Overview

The OpenCensus shim allows existing OpenCensus instrumentation to interoperate with OpenTelemetry instrumentation by using the OpenTelemetry SDK as an implementation for OpenCensus.

This is a simple example that demonstrates how existing OpenCensus instrumentation can be integrated with OpenTelemetry.

The example has:

  • Root Spans (on client), instrumented with OpenCensus's HTTP instrumentation
  • Child Span from a remote parent (on server), instrumented with OpenCensus's HTTP instrumentation
  • Another Child Span created in the server representing some work being done, instrumented manually with OpenTelemetry.
  • Server metrics coming from OpenCensus's HTTP instrumentation, available through the OpenTelemetry's Prometheus exporter.

Installation

# from this directory
$ npm install

Run the Application

Jaeger

Setup Jaeger Tracing All in One agent. If you have docker installed:

docker run \
  --rm \
  --name jaeger \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 16686:16686 \
  -p 4317:4317 \
  jaegertracing/all-in-one:latest

Run the sample server

# from this directory
$ node -r @opentelemetry/shim-opencensus/register ./server.js

The -r @opentelemetry/shim-opencensus/register flag to Node tells it to load the OpenCensus shim's register module to install the OpenCensus shim. The shim bridges all calls to OpenCensus's tracers to OpenTelemetry.

Run the sample client

# from this directory
node -r @opentelemetry/shim-opencensus/register ./client.js

Again, we use the -r @opentelemetry/shim-opencensus/register flag to install the OpenCensus shim.

Check the trace

Go to Jaeger with your browser http://localhost:16686/ and click on the "Service" dropdown. Choose opencensus-shim-example-server and hit "Find Traces". Click on one of the available traces and you should see 3 spans:

  • An outer span from the client. This came from the OpenCensus HTTP instrumentation.
    • A child from the server. This came from the OpenCensus HTTP instrumentation.
      • A child for the sleep operation. This was manually instrumented with OpenTelemetry. Notice this span is correctly recorded as a child of the OpenCensus instrumentation.

Jaeger UI showing a trace

Check the Prometheus metrics

Load the Prometheus metrics endpoint of the server at http://localhost:9464/metrics in your browser. You should see the opencensus_io_http_server_* related metrics in the output.

Screenshot showing Prometheus raw metrics

LICENSE

Apache License 2.0