Skip to content

Commit

Permalink
chore: add basic tracer example (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 authored Sep 18, 2019
1 parent 7fff538 commit 45be4b5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions examples/node-basic/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { BasicTracer } = require('@opentelemetry/basic-tracer');

// Initialize the OpenTelemetry APIs to use the BasicTracer bindings
opentelemetry.initGlobalTracer(new BasicTracer());

// Create a span. A span must be closed.
const span = opentelemetry.getTracer().startSpan('main');
for (let i = 0; i < 10; i++) {
doWork(span);
}
// Be sure to end the span.
span.end();

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

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

// Annotate our span to capture metadata about our operation
span.addEvent('invoking doWork').end();
}

0 comments on commit 45be4b5

Please sign in to comment.