Skip to content

Commit

Permalink
Update Stackdriver exporter example
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 committed Jan 28, 2020
1 parent 7949e3f commit 283ad47
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions examples/stackdriver-trace/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { BasicTracer, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { BasicTracerRegistry, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { CanonicalCode } = require('@opentelemetry/types');
const { StackdriverTraceExporter } = require('@opentelemetry/exporter-stackdriver-trace');

// Initialize an exporter
const exporter = new StackdriverTraceExporter({
serviceName: 'basic-service',
logger: new opentelemetry.ConsoleLogger(),
projectId: '<PROJECT_ID>'
});

const tracer = new BasicTracer();
const registry = new BasicTracerRegistry();

// Configure span processor to send spans to the provided exporter
tracer.addSpanProcessor(new SimpleSpanProcessor(exporter));
registry.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the BasicTracer bindings
opentelemetry.initGlobalTracer(tracer);
// Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings
opentelemetry.initGlobalTracerRegistry(registry);
const tracer = opentelemetry.getTracer('stackdriver-basic')

// Create a span. A span must be closed.
const root = opentelemetry.getTracer().startSpan('main');
const related = opentelemetry.getTracer().startSpan('related', {
links: [{ spanContext: root.context() }],
const root = tracer.startSpan('main');
const related = tracer.startSpan('related', {
links: [{ spanContext: root.context() }]
});

for (let i = 0; i < 10; i += 1) {
Expand All @@ -42,8 +42,8 @@ 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,
const span = tracer.startSpan('doWork', {
parent: parent
});

// simulate some random work.
Expand Down

0 comments on commit 283ad47

Please sign in to comment.