Skip to content

Commit

Permalink
feat: update example with Jaeger exporter (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 authored and bg451 committed Sep 18, 2019
1 parent 45be4b5 commit 03cbd00
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions examples/node-basic/index.js
@@ -1,10 +1,18 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { BasicTracer } = require('@opentelemetry/basic-tracer');
const { BasicTracer, SimpleSpanProcessor } = require('@opentelemetry/basic-tracer');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');

const options = {
serviceName: 'my-service'
}
const exporter = new JaegerExporter(options);

const tracer = new BasicTracer();
tracer.addSpanProcessor(new SimpleSpanProcessor(exporter));
// Initialize the OpenTelemetry APIs to use the BasicTracer bindings
opentelemetry.initGlobalTracer(new BasicTracer());
opentelemetry.initGlobalTracer(tracer);

// Create a span. A span must be closed.
const span = opentelemetry.getTracer().startSpan('main');
Expand All @@ -14,14 +22,18 @@ for (let i = 0; i < 10; i++) {
// Be sure to end the span.
span.end();

// flush and close the connection.
exporter.shutdown();

function doWork (parent) {
// Start another span. In this example, the main method already started a
// span, so that'll be the parent span, and this will be a child span.
const span = opentelemetry.getTracer().startSpan('doWork', {
parent: parent
});

for (let i = 0; i <= 40000000; i++) {} // short delay
// simulate some random work.
for (let i = 0; i <= Math.floor(Math.random() * 40000000); i++) {}

// Set attributes to the span.
span.setAttribute('key', 'value');
Expand Down

0 comments on commit 03cbd00

Please sign in to comment.