title | parent | toc | tags | languages | categories | thumbnail | description | date | mrm | author | xredirect | slug | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Tracing A Node.js with OCI Application Performance Monitoring and Zipkin |
|
false |
|
|
|
assets/ociemailimage-10.jpg |
Using Zipkin as an open-source tracking tool with OCI Application Performance Monitoring. |
2022-02-25 19:42 |
WWMK220224P00058 |
|
tracing-node-js-micro-service-oci |
OCI Application Performance Monitoring (APM) provides a comprehensive set of features to monitor applications and diagnose performance issues.
APM integrates with open-source tracing system tools (aka, open-source tracers) such as Jaeger and Zipkin allowing you to upload trace data from your application. It also supports context propagation between Application Performance Monitoring agents and open-source tracers.
In this tutorial, we'll cover how to set up APM on your system, configure your Node.js for tracing, and run some sample queries using Trace Explorer.
-
Go to APM > Administration
-
Select the Create APM Domain button and provide the information requested in popup window.
{% imgx assets/ociapmzipkinimage-92.jpg %}
{% imgx assets/ociapmzipkinimage-93.jpg %}
{% imgx assets/ociapmzipkinimage-94.jpg %}
In the APM domain details you created, get the Data Upload Endpoint URL and the auto_generated_public_datakey
values, we’ll need them in the next step.
{% imgx assets/ociapmzipkinimage-95.jpg %}
Before we get started, make sure to:
- Configure Zipkin for your app - Follow the steps in the Zipkin JS repo to configure Zipkin for your app.
- Set up OCI APM - Follow the step in this document to configure tracers for OCI.
For the rest of this tutorial, we'll work with sample code in the Zipkin repo.
First, clone the repo and then edit the sample code as noted below.
{% imgx assets/ociapmzipkinimage-96.jpg %}
/* eslint-env browser */
const {
BatchRecorder,
jsonEncoder: {JSON_V2}
} = require('zipkin');
const {HttpLogger} = require('zipkin-transport-http');
Replace the last line with:
const CLSContext = require('zipkin-context-cls');
const debug = 'undefined' !== typeof window
? window.location.search.indexOf('debug') !== -1
: process.env.DEBUG;
// Send spans to Zipkin asynchronously over HTTP
const zipkinBaseUrl = 'http://localhost:9411';
// data upload endpoint example is something like https://aaaa...aaapi.apm-agt.eu-frankfurt-1.oci.oraclecloud.com/20200101/observations/public-span?dataFormat=zipkin&dataFormatVersion=2&dataKey=QM...3D
-
Adjust
BaseURL
- Of course, theBaseURL
will not be alocalhost
, so replaceconst zipkinBaseUrl = '<http://localhost:9411>;'
with:const httpLogger = new HttpLogger({ endpoint: '<domain data upload endpoint in step 2>/20200101/observations/public-span?dataFormat=zipkin&dataFormatVersion=2&dataKey=<public data key in step 2>', jsonEncoder: JSON_V2 })
-
Remove the logger and add a tracer -
-
Remove this:
const httpLogger = new HttpLogger({ endpoint: `${zipkinBaseUrl}/api/v2/spans`, jsonEncoder: JSON_V2 });
-
And add this:
// Setup the tracer const tracer = new Tracer({ ctxImpl: new CLSContext('zipkin'), // implicit in-process context recorder: new BatchRecorder({ logger: httpLogger }), // batched http recorder localServiceName: 'mytest', // name of this application supportsJoin: false //Span join disable setting });
-
A this point, the rest should look like this:
function recorder(serviceName) {
return debug ? debugRecorder(serviceName) : new BatchRecorder({logger: httpLogger});
}
function debugRecorder(serviceName) {
// This is a hack that lets you see the data sent to Zipkin!
const logger = {
logSpan: (span) => {
const json = JSON_V2.encode(span);
console.log(`${serviceName} reporting: ${json}`);
httpLogger.logSpan(span);
}
};
const batchRecorder = new BatchRecorder({logger});
// This is a hack that lets you see which annotations become which spans
return ({
record: (rec) => {
const {spanId, traceId} = rec.traceId;
console.log(`${serviceName} recording: ${traceId}/${spanId} ${rec.annotation.toString()}`);
batchRecorder.record(rec);
}
});
}
module.exports.recorder = recorder;
{% imgx assets/ociapmzipkinimage-97.jpg %}
Go to APM Trace Explorer and run a query:
{% imgx assets/ociapmzipkinimage-98.jpg %}
Traces can be observed in the list!
{% imgx assets/ociapmzipkinimage-91.jpg %}
That’s all! Quick and easy!
If you’re curious about the goings-on of Oracle Developers in their natural habitat, come join us in our public Slack channel!
And don't forget our free tier, where you can try out what we just discussed.
To explore more information about development with Oracle products: