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
- Sign in to the Oracle Cloud Infrastructure console, open the navigation menu, and click Observability and Management. Under Application Performance Monitoring, click Administration:
- Click Create APM Domain and enter the domain details:
- Click on the domain you just created and make a note (copy/paste) of the domain values Data Upload Endpoint and private Datakey:
Step 2: Configure Span Reporting
- Instal Zipkin on your node.js server
npm install zipkin --save npm install zipkin-context-cls npm install zipkin-transport-http
- 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
- Initialize the Zipkin module:
Step 3: View Data in Trace Explorer
We are now ready to view and analyze trace data in APM Trace Explorer.
- From the OCI main menu, navigate to Trace Explorer:
- Select your compartment and domain and view all trace data, under the Traces tab:
- 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
Configuring Node.js Zipkin Client for Reporting to APM
F53912-01
April 2022
Copyright © 2022, Oracle and/or its affiliates.
This tutorial helps you configure the code of the Node.js application that uses Zipkin client (Tracer) for distributed tracing that is required to connect it to Oracle APM.
This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited.
If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, then the following notice is applicable:
U.S. GOVERNMENT END USERS: Oracle programs (including any operating system, integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such programs) and Oracle computer documentation or other Oracle data delivered to or accessed by U.S. Government end users are "commercial computer software" or "commercial computer software documentation" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, the use, reproduction, duplication, release, display, disclosure, modification, preparation of derivative works, and/or adaptation of i) Oracle programs (including any operating system, integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such programs), ii) Oracle computer documentation and/or iii) other Oracle data, is subject to the rights and limitations specified in the license contained in the applicable contract. The terms governing the U.S. Government's use of Oracle cloud services are defined by the applicable contract for such services. No other rights are granted to the U.S. Government.
This software or hardware is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently dangerous applications, including applications that may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software or hardware in dangerous applications.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Intel and Intel Inside are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Epyc, and the AMD logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered trademark of The Open Group.
This software or hardware and documentation may provide access to or information about content, products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services unless otherwise set forth in an applicable agreement between you and Oracle. Oracle Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services, except as set forth in an applicable agreement between you and Oracle.