Skip to content

Commit

Permalink
Update Stackdriver exporter example (#731)
Browse files Browse the repository at this point in the history
* Update Stackdriver exporter example

* fix: example lints
  • Loading branch information
mayurkale22 authored Jan 28, 2020
1 parent 7949e3f commit 4e3c44d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
6 changes: 3 additions & 3 deletions examples/postgres/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
"@opentelemetry/plugin-pg-pool": "^0.3.3",
"@opentelemetry/tracing": "^0.3.3",
"@opentelemetry/types": "^0.3.3",
"express": "^4.17.1"
"express": "^4.17.1",
"pg": "^7.12.1"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme",
"devDependencies": {
"cross-env": "^6.0.0",
"pg": "^7.12.1"
"cross-env": "^6.0.0"
}
}
22 changes: 10 additions & 12 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,9 +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', {
parent,
});
const span = tracer.startSpan('doWork', { parent });

// simulate some random work.
const work = Math.floor(Math.random() * 40000000);
Expand Down

0 comments on commit 4e3c44d

Please sign in to comment.