-
Notifications
You must be signed in to change notification settings - Fork 155
Node.js: Update examples #579
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,10 +33,9 @@ To use Instana as your exporter, first ensure that you have an [Instana agent ru | |
Now let's use the Instana exporter: | ||
|
||
```js | ||
var tracing = require('@opencensus/nodejs'); | ||
var instana = require('@opencensus/exporter-instana'); | ||
|
||
var exporter = new instana.InstanaTraceExporter(); | ||
const tracing = require('@opencensus/nodejs'); | ||
const { InstanaTraceExporter }= require('@opencensus/exporter-instana'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems spurious, perhaps just keep the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally think the destructuring import is fine as that is a fairly common pattern in JS and then it saves you referencing it via the namespace below (i.e. you don't need to say |
||
|
||
const exporter = new InstanaTraceExporter(); | ||
tracing.registerExporter(exporter).start(); | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ logo: /img/partners/jaeger_logo.svg | |
- [Introduction](#introduction) | ||
- [Installing the exporter](#installing-the-exporter) | ||
- [Creating the exporter](#creating-the-exporter) | ||
- [Viewing your traces](#viewing-your-traces) | ||
- [Project link](#project-link) | ||
|
||
## Introduction | ||
Jaeger, inspired by Dapper and OpenZipkin, is a distributed tracing system released as open source by Uber Technologies. | ||
|
@@ -40,21 +42,26 @@ npm install @opencensus/exporter-jaeger | |
Now let's use the Jaeger exporter: | ||
|
||
```js | ||
var core = require('@opencensus/core'); | ||
var tracing = require('@opencensus/nodejs'); | ||
var jaeger = require('@opencensus/exporter-jaeger'); | ||
const { logger } = require('@opencensus/core'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps let's make this style consistent: in some place we have
while here
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const { JaegerTraceExporter } = require('@opencensus/exporter-jaeger'); | ||
const tracing = require('@opencensus/nodejs'); | ||
|
||
var jaegerOptions = { | ||
// Add service name and jaeger options | ||
const jaegerOptions = { | ||
serviceName: 'opencensus-exporter-jaeger', | ||
host: 'localhost', | ||
port: 6832, | ||
tags: [{key: 'opencensus-exporter-jeager', value: '0.0.1'}], | ||
tags: [{key: 'opencensus-exporter-jeager', value: '0.0.9'}], | ||
bufferTimeout: 10, // time in milliseconds | ||
logger: core.logger.logger('debug'), | ||
maxPacketSize: 1000 | ||
logger: logger.logger('debug') | ||
}; | ||
|
||
var exporter = new jaeger.JaegerTraceExporter(jaegerOptions); | ||
|
||
const exporter = new JaegerTraceExporter(jaegerOptions); | ||
tracing.registerExporter(exporter).start(); | ||
``` | ||
|
||
## Viewing your traces | ||
Please visit the Jaeger UI endpoint [http://localhost:16686](http://localhost:16686) | ||
|
||
## Project link | ||
You can find out more about the Jaeger project at [https://www.jaegertracing.io/](https://www.jaegertracing.io/) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ logo: /img/prometheus-logo.png | |
- [Introduction](#introduction) | ||
- [Installing the exporter](#installing-the-exporter) | ||
- [Creating the exporter](#creating-the-exporter) | ||
- [Running Prometheus](#running-prometheus) | ||
- [Viewing your metrics](#viewing-your-metrics) | ||
- [Project link](#project-link) | ||
|
||
## Introduction | ||
Prometheus is a monitoring system that collects metrics, by scraping | ||
|
@@ -31,26 +34,56 @@ npm install @opencensus/exporter-prometheus | |
``` | ||
|
||
## Creating the exporter | ||
To create the exporter, we'll need to: | ||
|
||
* Import and use the Prometheus exporter package | ||
* Define a namespace that will uniquely identify our metrics when viewed on Prometheus | ||
* Expose a port on which we shall run a `/metrics` endpoint | ||
* With the defined port, we'll need a Promethus configuration file so that Prometheus can scrape from this endpoint | ||
|
||
Now let's use the Prometheus exporter: | ||
|
||
```js | ||
const { Stats } = require('@opencensus/core'); | ||
const { globalStats } = require('@opencensus/core'); | ||
const { PrometheusStatsExporter } = require('@opencensus/exporter-prometheus'); | ||
|
||
// Add your port and startServer to the Prometheus options | ||
const exporter = new PrometheusStatsExporter({ | ||
port: 9464, | ||
startServer: false | ||
startServer: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What changed here from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So earlier, it was like two step approach
This can be possible by passing |
||
}); | ||
|
||
// Our Stats manager | ||
const stats = new Stats(); | ||
|
||
// Pass the created exporter to Stats | ||
stats.registerExporter(exporter); | ||
globalStats.registerExporter(exporter); | ||
``` | ||
|
||
// Run the server | ||
exporter.startServer(function callback() { | ||
// Callback | ||
}); | ||
and then for our corresponding `prometheus.yaml` file: | ||
|
||
```yaml | ||
global: | ||
scrape_interval: 10s | ||
|
||
external_labels: | ||
monitor: 'demo' | ||
|
||
scrape_configs: | ||
- job_name: 'demo' | ||
|
||
scrape_interval: 10s | ||
|
||
static_configs: | ||
- targets: ['localhost:8888'] | ||
``` | ||
## Running Prometheus | ||
And then run Prometheus with your configuration | ||
```shell | ||
prometheus --config.file=prometheus.yaml | ||
``` | ||
|
||
## Viewing your metrics | ||
Please visit [http://localhost:9090](http://localhost:9090) | ||
|
||
## Project link | ||
You can find out more about the Prometheus project at [https://prometheus.io/](https://prometheus.io/) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ logo: /img/zipkin-logo.jpg | |
- [Introduction](#introduction) | ||
- [Installing the exporter](#installing-the-exporter) | ||
- [Creating the exporter](#creating-the-exporter) | ||
- [Viewing your traces](#viewing-your-traces) | ||
- [Project link](#project-link) | ||
|
||
## Introduction | ||
Zipkin is a distributed tracing system. It helps gather timing data needed to troubleshoot latency problems in microservice architectures. | ||
|
@@ -18,8 +20,8 @@ It manages both the collection and lookup of this data. Zipkin’s design is bas | |
|
||
OpenCensus Node.js has support for this exporter available, distributed through NPM package [@opencensus/exporter-zipkin](https://www.npmjs.com/package/@opencensus/exporter-zipkin) | ||
|
||
{{% notice tip %}} | ||
For assistance setting up Zipkin, [Click here](/codelabs/zipkin) for a guided codelab. | ||
{{% notice note %}} | ||
This guide makes use of Zipkin for visualizing your data. For assistance setting up Zipkin, [Click here](/codelabs/zipkin) for a guided codelab. | ||
{{% /notice %}} | ||
|
||
## Installing the exporter | ||
|
@@ -34,16 +36,22 @@ npm install @opencensus/exporter-zipkin | |
Now let's use the Zipkin exporter: | ||
|
||
```js | ||
var tracing = require('@opencensus/nodejs'); | ||
var zipkin = require('@opencensus/exporter-zipkin'); | ||
const tracing = require('@opencensus/nodejs'); | ||
const { ZipkinTraceExporter } = require('@opencensus/exporter-zipkin'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixing |
||
|
||
// Add your zipkin url (ex http://localhost:9411/api/v2/spans) | ||
// and application name to the Zipkin options | ||
var options = { | ||
const zipkinOptions = { | ||
url: 'your-zipkin-url', | ||
serviceName: 'your-application-name' | ||
}; | ||
|
||
var exporter = new zipkin.ZipkinTraceExporter(options); | ||
const exporter = new ZipkinTraceExporter(zipkinOptions); | ||
tracing.registerExporter(exporter).start(); | ||
``` | ||
|
||
## Viewing your traces | ||
Please visit the Zipkin UI endpoint [http://localhost:9411](http://localhost:9411) | ||
|
||
## Project link | ||
You can find out more about the Zipkin project at [https://zipkin.io/](https://zipkin.io/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we changing this to
globalStats
? What's up withstats
? Other languages use the same or is anotherstats
used somewhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Earlier we used to create Stats instance (
new Stats()
) and used in the application. With new release, we have changed it to a global singleton Stats instance (globalStats
). This behavioral change is introduced to match other language implementation. (The nameglobalStats
is specific to Node library).