Before you Begin

The support for OpenTracing, an API and vendor-neutral instrumentation framework, allows application developers to instrument their application code and analyze the trace data in Oracle Cloud Infrastructure (OCI) Application Performance Monitoring (APM). This is an example of instrumentation of a Node.js application using a Zipkin tracer.

Background

Distributed tracing is a method used to profile and monitor applications. This method is especially used to monitor applications built using a microservices architecture. OpenTracing is an open-source project that provides vendor-neutral APIs and instrumentation for distributed tracing. It allows developers to add instrumentation to their application code using APIs.

Application Performance Monitoring consumes telemetry data collected by OpenTracing and provides information on requests, through various microservices or functions. Therefore, APM allows real end user monitoring and complete analysis of the impact of services on the overall end-user digital experience..

Our Scenario

In this example, we are running one or more Node.js servers and we want to track and collect all transactions. The recorded data allows you to see each operation timing as well as how much time was spent in each service. This is the data that we will upload to APM for visualization and further analysis

Step 1: Create an APM Domain

  1. Sign in to the Oracle Cloud Infrastructure console, open the navigation menu, and click Observability and Management. Under Application Performance Monitoring, click Administration:
    OCI Main Menu
    Description of the illustration apm.png
  2. Click Create APM Domain and enter the domain details:
    Create Menu
    Description of the illustration create.png
  3. Click on the domain you just created and make a note (copy/paste) of the domain values Data Upload Endpoint and private Datakey:
    Domain Details
    Description of the illustration domain_details.png

Step 2: Configure Span Reporting

  1. Instal Zipkin on your node.js server
    npm install zipkin --save
    npm install zipkin-context-cls
    npm install zipkin-transport-http
    
  2. The following settings should be adjusted in order to set up Zipkin Tracer to report to APM.
    const {
      Tracer,
      BatchRecorder,
      jsonEncoder: {JSON_V2}
    } = require('zipkin');
     
    const CLSContext = require('zipkin-context-cls');
    const {HttpLogger} = require('zipkin-transport-http');
     
    // Setup the tracer
    const tracer = new Tracer({
      ctxImpl: new CLSContext('zipkin'), // implicit in-process context
      recorder: new BatchRecorder({
        logger: new HttpLogger({
          endpoint: '<Collector endpoint>', //Span collection endpoint URL setting
          jsonEncoder: JSON_V2 //Span format and encoding setting
        })
      }), // batched http recorder
      localServiceName: '<service-name>', // name of this application/service
      supportsJoin: false //Span join disable setting
    });
                            

    Here is a breakdown of the code to configure the Node.js Zipkin client:

    • Initialize the Zipkin module:
      const {
        Tracer,
        BatchRecorder,
        jsonEncoder: {JSON_V2}
      } = require('zipkin');
                                      
    • In order to collect your transaction, you need to create and configure the tracer object, which will report spans to the Oracle APM Collector instead of Zipkin backend in JSON-encoded Zipkin v2 format.

      Make sure to include the Data Upload Endpoint you obatained when creating the APM Domain as the Collector Endoint.

      const tracer = new Tracer({
        ctxImpl: new CLSContext('zipkin'), // implicit in-process context
        recorder: new BatchRecorder({
          logger: new HttpLogger({
            endpoint: '<Collector endpoint>', //Span collection endpoint URL setting
            jsonEncoder: JSON_V2 //Span format and encoding setting
          })
                                      
    • Give your service a name and disable Span Joining for the Tracer that is reporting to APM, as OpenTracing specification does not allow Span ID sharing between different spans within the same trace.
      localServiceName: '<service-name>', // name of this application/service
        supportsJoin: false //Span join disable setting

Step 3: View Data in Trace Explorer

We are now ready to view and analyze trace data in APM Trace Explorer.

  1. From the OCI main menu, navigate to Trace Explorer:
    OCI Main Menu
    Description of the illustration trace.png
  2. Select your compartment and domain and view all trace data, under the Traces tab:

    Trace Explorer
    Description of the illustration traceexplorer.png
  3. Use the following query to filter your data to only see data from the service you created.
    SHOW SPANS * WHERE (Kind='SERVER') AND (('ServicenName='<service-name>'))

    APM's Trace Explorer features a multitude of ways to visualize data, which you can explore by going to LINK

Next Steps

An APM Browser Agent records user interaction with websites and sends browser spans and real user monitoring metrics to Application Performance Monitoring. These metrics can provide further insight into the real experience of your end users and identifies performance problems as your users navigate to your site from different web browsers and devices. For more information on how to deploy an APM Browser Agent, see Configure APM Browser Agent.

Learn More