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 23, 2020
1 parent cb677c0 commit d4db47b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions examples/stackdriver-trace/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
'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', {
const root = tracer.startSpan('main');
const related = tracer.startSpan('related', {
links: [{ spanContext: root.context() }]
});

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

Expand Down

0 comments on commit d4db47b

Please sign in to comment.