Skip to content

Commit

Permalink
Named Tracers / Tracer Registry (#582)
Browse files Browse the repository at this point in the history
* feat: spike of named tracer registry

* chore: mysql/mongo tracer registry support

* fix: lint

* chore: add getTracer back

* chore: change default tracer name to empty string

* fix: lint

* chore: update examples for registry

* chore(tracer-registry): make name required

* chore: lint

* chore: update examples for required tracer name

* chore: remove unused tracer delegate

* chore: remove references to basic tracer

* chore: remove references to NodeTracer

* chore: update xhr for tracer registry

* chore: update tracer names to match package names

* chore: add version script to all packages

* chore: update plugins to use version script

* chore: add jsdoc to noop tracer registry

* chore: update ioredis for tracer registry

* chore: update pg pool for tracer registry

* fix: lint

* chore: fix tests

* chore: lint

* chore: lint

Co-authored-by: Mayur Kale <[email protected]>
  • Loading branch information
dyladan and mayurkale22 committed Jan 9, 2020
1 parent 059595a commit 18c6aa4
Show file tree
Hide file tree
Showing 107 changed files with 975 additions and 936 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ docs

#lerna
.changelog
package.json.lerna_backup

# OS generated files
.DS_Store
Expand Down
18 changes: 9 additions & 9 deletions benchmark/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

const benchmark = require('./benchmark');
const opentelemetry = require('@opentelemetry/core');
const { BasicTracer, BatchSpanProcessor, InMemorySpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { NodeTracer } = require('@opentelemetry/node');
const { BasicTracerRegistry, BatchSpanProcessor, InMemorySpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { NodeTracerRegistry } = require('@opentelemetry/node');

const exporter = new InMemorySpanExporter();
const logger = new opentelemetry.NoopLogger();

const setups = [
{
name: 'BasicTracer',
tracer: new BasicTracer({ logger })
name: 'BasicTracerRegistry',
registry: new BasicTracerRegistry({ logger })
},
{
name: 'NodeTracer',
tracer: new NodeTracer({ logger })
name: 'NodeTracerRegistry',
registry: new NodeTracerRegistry({ logger })
}
];

for (const setup of setups) {
console.log(`Beginning ${setup.name} Benchmark...`);
const tracer = setup.tracer;
const tracer = setup.registry.getTracer("benchmark");
const suite = benchmark()
.add('#startSpan', function () {
const span = tracer.startSpan('op');
Expand Down Expand Up @@ -55,7 +55,7 @@ for (const setup of setups) {
.add('#startSpan with SimpleSpanProcessor', function () {
const simpleSpanProcessor = new SimpleSpanProcessor(exporter);

tracer.addSpanProcessor(simpleSpanProcessor);
registry.addSpanProcessor(simpleSpanProcessor);
const span = tracer.startSpan('op');
span.end();

Expand All @@ -64,7 +64,7 @@ for (const setup of setups) {
.add('#startSpan with BatchSpanProcessor', function () {
const batchSpanProcessor = new BatchSpanProcessor(exporter);

tracer.addSpanProcessor(batchSpanProcessor);
registry.addSpanProcessor(batchSpanProcessor);
const span = tracer.startSpan('op');
span.end();
batchSpanProcessor.shutdown();
Expand Down
15 changes: 8 additions & 7 deletions examples/basic-tracer-node/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const opentelemetry = require('@opentelemetry/core');
const { BasicTracer, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { BasicTracerRegistry, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const { CollectorExporter } = require('@opentelemetry/exporter-collector');
Expand All @@ -20,16 +20,17 @@ if (EXPORTER.toLowerCase().startsWith('z')) {
exporter = new CollectorExporter(options);
}

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('example-basic-tracer-node')

// Create a span. A span must be closed.
const span = opentelemetry.getTracer().startSpan('main');
const span = tracer.startSpan('main');
for (let i = 0; i < 10; i++) {
doWork(span);
}
Expand All @@ -42,7 +43,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
19 changes: 10 additions & 9 deletions examples/basic-tracer-node/multi_exporter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const opentelemetry = require('@opentelemetry/core');
const { BasicTracer, BatchSpanProcessor, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { BasicTracerRegistry, BatchSpanProcessor, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const { CollectorExporter } = require('@opentelemetry/exporter-collector');

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

const zipkinExporter = new ZipkinExporter({serviceName: 'basic-service'});
const jaegerExporter = new JaegerExporter({
Expand All @@ -14,21 +14,22 @@ const collectorExporter = new CollectorExporter({serviceName: 'basic-service'});

// It is recommended to use this BatchSpanProcessor for better performance
// and optimization, especially in production.
tracer.addSpanProcessor(new BatchSpanProcessor(zipkinExporter, {
registry.addSpanProcessor(new BatchSpanProcessor(zipkinExporter, {
bufferSize: 10 // This is added for example, default size is 100.
}));

// It is recommended to use SimpleSpanProcessor in case of Jaeger exporter as
// it's internal client already handles the spans with batching logic.
tracer.addSpanProcessor(new SimpleSpanProcessor(jaegerExporter));
registry.addSpanProcessor(new SimpleSpanProcessor(jaegerExporter));

tracer.addSpanProcessor(new SimpleSpanProcessor(collectorExporter));
registry.addSpanProcessor(new SimpleSpanProcessor(collectorExporter));

// 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('default');

// Create a span. A span must be closed.
const span = opentelemetry.getTracer().startSpan('main');
const span = tracer.startSpan('main');
for (let i = 0; i < 10; i++) {
doWork(span);
}
Expand All @@ -43,7 +44,7 @@ collectorExporter.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
2 changes: 1 addition & 1 deletion examples/dns/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const config = require('./setup');
config.setupTracerAndExporters('dns-client-service');

const dns = require('dns').promises;
const tracer = opentelemetry.getTracer();
const tracer = opentelemetry.getTracer('example-dns');

/** A function which makes a dns lookup and handles response. */
function makeLookup() {
Expand Down
10 changes: 5 additions & 5 deletions examples/dns/setup.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracer } = require('@opentelemetry/node');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const EXPORTER = process.env.EXPORTER || '';

function setupTracerAndExporters(service) {
const tracer = new NodeTracer({
const registry = new NodeTracerRegistry({
      plugins{
          dns{
            enabledtrue,
Expand All @@ -30,10 +30,10 @@ function setupTracerAndExporters(service) {
});
}

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);
}

exports.setupTracerAndExporters = setupTracerAndExporters;
2 changes: 1 addition & 1 deletion examples/grpc/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const grpc = require('grpc');
const messages = require('./helloworld_pb');
const services = require('./helloworld_grpc_pb');
const PORT = 50051;
const tracer = opentelemetry.getTracer();
const tracer = opentelemetry.getTracer('example-grpc-client');

/** A function which makes requests and handles response. */
function main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const config = require('./setup');
config.setupTracerAndExporters('grpc-server-service');

const grpc = require('grpc');
const tracer = opentelemetry.getTracer();
const tracer = opentelemetry.getTracer('example-grpc-server');

const messages = require('./helloworld_pb');
const services = require('./helloworld_grpc_pb');
Expand Down
10 changes: 5 additions & 5 deletions examples/grpc/setup.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracer } = require('@opentelemetry/node');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const EXPORTER = process.env.EXPORTER || '';

function setupTracerAndExporters(service) {
const tracer = new NodeTracer({
const registry = new NodeTracerRegistry({
plugins: {
grpc: {
enabled: true,
Expand All @@ -29,10 +29,10 @@ function setupTracerAndExporters(service) {
});
}

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);
}

exports.setupTracerAndExporters = setupTracerAndExporters;
2 changes: 1 addition & 1 deletion examples/grpc_dynamic_codegen/capitalize_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const path = require('path');
const grpc = require('grpc');
const protoLoader = require('@grpc/proto-loader');

const tracer = opentelemetry.getTracer();
const tracer = opentelemetry.getTracer('example-grpc-capitalize-client');

const PROTO_PATH = path.join(__dirname, 'protos/defs.proto');
const PROTO_OPTIONS = { keepCase: true, enums: String, defaults: true, oneofs: true };
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc_dynamic_codegen/capitalize_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const PROTO_OPTIONS = { keepCase: true, enums: String, defaults: true, oneofs: t
const definition = protoLoader.loadSync(PROTO_PATH, PROTO_OPTIONS);
const rpcProto = grpc.loadPackageDefinition(definition).rpc;

const tracer = opentelemetry.getTracer();
const tracer = opentelemetry.getTracer('example-grpc-capitalize-server');

/** Implements the Capitalize RPC method. */
function capitalize(call, callback) {
Expand Down
10 changes: 5 additions & 5 deletions examples/grpc_dynamic_codegen/setup.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracer } = require('@opentelemetry/node');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const EXPORTER = process.env.EXPORTER || '';

function setupTracerAndExporters(service) {
const tracer = new NodeTracer({
const registry = new NodeTracerRegistry({
plugins: {
grpc: {
enabled: true,
Expand All @@ -31,10 +31,10 @@ function setupTracerAndExporters(service) {

// It is recommended to use this `BatchSpanProcessor` for better performance
// and optimization, especially in production.
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);
}

exports.setupTracerAndExporters = setupTracerAndExporters;
2 changes: 1 addition & 1 deletion examples/http/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const config = require('./setup');
config.setupTracerAndExporters('http-client-service');

const http = require('http');
const tracer = opentelemetry.getTracer();
const tracer = opentelemetry.getTracer('example-http-client');

/** A function which makes requests and handles response. */
function makeRequest() {
Expand Down
2 changes: 1 addition & 1 deletion examples/http/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const config = require('./setup');
config.setupTracerAndExporters('http-server-service');

const http = require('http');
const tracer = opentelemetry.getTracer();
const tracer = opentelemetry.getTracer('example-http-server');

/** Starts a HTTP server that receives requests on sample server port. */
function startServer (port) {
Expand Down
10 changes: 5 additions & 5 deletions examples/http/setup.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracer } = require('@opentelemetry/node');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const EXPORTER = process.env.EXPORTER || '';

function setupTracerAndExporters(service) {
const tracer = new NodeTracer();
const registry = new NodeTracerRegistry();

let exporter;
if (EXPORTER.toLowerCase().startsWith('z')) {
Expand All @@ -21,10 +21,10 @@ function setupTracerAndExporters(service) {
});
}

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);
}

exports.setupTracerAndExporters = setupTracerAndExporters;
4 changes: 2 additions & 2 deletions examples/https/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const config = require('./setup');
config.setupTracerAndExporters('https-client-service');

const https = require('https');
const tracer = opentelemetry.getTracer();
const tracer = opentelemetry.getTracer('example-https-client');

/** A function which makes requests and handles response. */
function makeRequest() {
Expand All @@ -31,7 +31,7 @@ function makeRequest() {
});
});
});

// The process must live for at least the interval past any traces that
// must be exported, or some risk being lost if they are recorded after the
// last export.
Expand Down
2 changes: 1 addition & 1 deletion examples/https/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const config = require('./setup');
config.setupTracerAndExporters('https-server-service');

const https = require('https');
const tracer = opentelemetry.getTracer();
const tracer = opentelemetry.getTracer('example-https-server');

/** Starts a HTTPs server that receives requests on sample server port. */
function startServer (port) {
Expand Down
10 changes: 5 additions & 5 deletions examples/https/setup.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracer } = require('@opentelemetry/node');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const EXPORTER = process.env.EXPORTER || '';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
function setupTracerAndExporters(service) {
let exporter;
const tracer = new NodeTracer();
const registry = new NodeTracerRegistry();

if (EXPORTER.toLowerCase().startsWith('z')) {
exporter = new ZipkinExporter({
Expand All @@ -21,10 +21,10 @@ function setupTracerAndExporters(service) {
});
}

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);
}

exports.setupTracerAndExporters = setupTracerAndExporters;
Loading

0 comments on commit 18c6aa4

Please sign in to comment.