From 283ad47c1d0b6c766fe2c244cad89a9911488b29 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Wed, 22 Jan 2020 20:49:23 -0800 Subject: [PATCH] Update Stackdriver exporter example --- examples/stackdriver-trace/index.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/stackdriver-trace/index.js b/examples/stackdriver-trace/index.js index 277ddba431..f89f71b7a9 100644 --- a/examples/stackdriver-trace/index.js +++ b/examples/stackdriver-trace/index.js @@ -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: '' }); -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) { @@ -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.