Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Node.js: Update examples #579

Merged
merged 2 commits into from
Feb 15, 2019

Conversation

mayurkale22
Copy link
Member

This PR contains the following changes.

  1. Node.js 0.0.9 version has introduced butch of changes for Stats (Metrics) examples including TagKey, TagValue and TagMap.
  2. Change var -> const.
  3. Fixes quickstart/node.js: use open source exporters for tutorials #355 -> use the open source exporter (Prometheus) for quickstart tutorials.

[myTagKey],
'my view'
);
globalStats..registerView(view);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right globalStats.., double dots "..". Were you able to run this code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I ran the example and it works as expected.

// And register it
stats.registerExporter(exporter);
globalStats.registerExporter(exporter);
Copy link
Member

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 with stats? Other languages use the same or is another stats used somewhere?

Copy link
Member Author

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 name globalStats is specific to Node library).


// Let's create an instance of our just created exporter
var exporter = new MyConsoleTraceExporter();
const exporter = new MyConsoleTraceExporter();
// And start tracing with it
tracing.registerExporter(exporter).start();

// Now, lets create a simple HTTP 2 server
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/HTTP 2/HTTP/2/g

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


var exporter = new instana.InstanaTraceExporter();
const tracing = require('@opencensus/nodejs');
const { InstanaTraceExporter }= require('@opencensus/exporter-instana');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems spurious, perhaps just keep the const change and then as it was before i.e.

const instana

Choose a reason for hiding this comment

The 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 instana.InstanaTraceExporter(); you can just say const exporter = new InstanaTraceExporter();)

var core = require('@opencensus/core');
var tracing = require('@opencensus/nodejs');
var jaeger = require('@opencensus/exporter-jaeger');
const { logger } = require('@opencensus/core');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps let's make this style consistent: in some place we have const { objectName } = require(<import>) and in others const objectName = require(<import>) for example

const tracing = require('@opencensus/nodejs');

while here

const { logger } = require('@opencensus/core');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { objectName } = require(<import>) i.e. destructuring import is preferred wherever it is feasible.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What changed here from startServer: false to startServer: true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So earlier, it was like two step approach

  1. Don't start the Prometheus exporter server i.e. startServer: false
  2. Explicitly call startServer method to start the Prometheus exporter server i.e.
exporter.startServer(function callback() {
  // Callback
});

This can be possible by passing startServer: true option.

});
and then for our corresponding `prometheus.yaml` file:

```shell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff including this!

var tracing = require('@opencensus/nodejs');
var zipkin = require('@opencensus/exporter-zipkin');
const tracing = require('@opencensus/nodejs');
const { ZipkinTraceExporter } = require('@opencensus/exporter-zipkin');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing const tracing and const { ZipkinTraceExporter }


// Create and Register the view
const view = globalStats.createView(
'my/view',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: what would you thin about adding comments for the name and description values e.g.

const view = globalStats.createView(
    /* name */ 'my/view',
   measure,
   AggregationType.LAST_VALUE,
   [myTagKey], 
   /* description */ 'my view'
);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


var exporter = new instana.InstanaTraceExporter();
const tracing = require('@opencensus/nodejs');
const { InstanaTraceExporter }= require('@opencensus/exporter-instana');

Choose a reason for hiding this comment

The 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 instana.InstanaTraceExporter(); you can just say const exporter = new InstanaTraceExporter();)

});
and then for our corresponding `prometheus.yaml` file:

```shell

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be yaml instead of shell?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@odeke-em
Copy link
Member

Thanks for working on this and for tagging me @mayurkale22! I'll humbly defer to @draffensperger since he has new Node.js expertise and is familiar with the new syntax than I am.

@mayurkale22
Copy link
Member Author

Is this good to merge?

Copy link
Member

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @mayurkale22 for the work and @draffensperger for the reviews!

@mayurkale22 mayurkale22 merged commit 1690b8d into census-instrumentation:master Feb 15, 2019
@mayurkale22 mayurkale22 deleted the node_0.0.9 branch February 15, 2019 21:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants