Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named Tracers / Tracer Registry #582

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d75f53e
feat: spike of named tracer registry
dyladan Dec 2, 2019
ead9f16
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 2, 2019
50927cd
chore: mysql/mongo tracer registry support
dyladan Dec 2, 2019
c686117
fix: lint
dyladan Dec 2, 2019
7dba62c
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 2, 2019
14fa061
chore: add getTracer back
dyladan Dec 2, 2019
b1e887c
chore: change default tracer name to empty string
dyladan Dec 2, 2019
5ca0209
fix: lint
dyladan Dec 2, 2019
217d3b3
Merge branch 'master' into tracer-registry
dyladan Dec 2, 2019
61f4618
chore: update examples for registry
dyladan Dec 2, 2019
33dd773
Merge branch 'tracer-registry' of github.com:dynatrace-oss-contrib/op…
dyladan Dec 2, 2019
6f81608
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 10, 2019
0687f1c
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 17, 2019
cc4eba9
chore(tracer-registry): make name required
dyladan Dec 17, 2019
9d95597
chore: lint
dyladan Dec 17, 2019
3237f99
chore: update examples for required tracer name
dyladan Dec 17, 2019
643e286
chore: remove unused tracer delegate
dyladan Dec 17, 2019
508ff33
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 18, 2019
41c1168
chore: remove references to basic tracer
dyladan Dec 23, 2019
6a94efe
chore: remove references to NodeTracer
dyladan Dec 23, 2019
4693d22
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 26, 2019
13f96fd
chore: update xhr for tracer registry
dyladan Dec 26, 2019
38ffef8
chore: update tracer names to match package names
dyladan Dec 26, 2019
9915a2c
chore: add version script to all packages
dyladan Dec 26, 2019
69ff01f
chore: update plugins to use version script
dyladan Dec 26, 2019
40c4301
chore: add jsdoc to noop tracer registry
dyladan Dec 27, 2019
1eea9d2
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Dec 27, 2019
660f41f
chore: update ioredis for tracer registry
dyladan Dec 27, 2019
8e6399e
chore: update pg pool for tracer registry
dyladan Dec 27, 2019
bd0be2c
fix: lint
dyladan Dec 30, 2019
30a1b36
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Jan 3, 2020
7c39151
chore: fix tests
dyladan Jan 3, 2020
e814df6
chore: lint
dyladan Jan 3, 2020
0ec5b82
Merge remote-tracking branch 'upstream/master' into tracer-registry
dyladan Jan 6, 2020
cd47354
chore: lint
dyladan Jan 6, 2020
bfa8bfa
Merge branch 'master' into tracer-registry
mayurkale22 Jan 9, 2020
5740098
Merge branch 'master' into tracer-registry
mayurkale22 Jan 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this intentional ?


# OS generated files
.DS_Store
Expand Down
8 changes: 4 additions & 4 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');

Expand All @@ -17,13 +17,13 @@ if (EXPORTER.toLowerCase().startsWith('z')) {
exporter = new JaegerExporter(options);
}

const tracer = new BasicTracer();
const registry = new BasicTracerRegistry();
dyladan marked this conversation as resolved.
Show resolved Hide resolved

// 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);
opentelemetry.initGlobalTracerRegistry(registry);

// Create a span. A span must be closed.
const span = opentelemetry.getTracer().startSpan('main');
Expand Down
8 changes: 4 additions & 4 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: {
            enabled: true,
Expand All @@ -32,10 +32,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);
opentelemetry.initGlobalTracerRegistry(registry);
}

exports.setupTracerAndExporters = setupTracerAndExporters;
8 changes: 4 additions & 4 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 @@ -31,10 +31,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);
opentelemetry.initGlobalTracerRegistry(registry);
}

exports.setupTracerAndExporters = setupTracerAndExporters;
8 changes: 4 additions & 4 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 @@ -33,10 +33,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);
opentelemetry.initGlobalTracerRegistry(registry);
}

exports.setupTracerAndExporters = setupTracerAndExporters;
8 changes: 4 additions & 4 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 @@ -23,10 +23,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);
opentelemetry.initGlobalTracerRegistry(registry);
}

exports.setupTracerAndExporters = setupTracerAndExporters;
8 changes: 4 additions & 4 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 @@ -23,10 +23,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);
opentelemetry.initGlobalTracerRegistry(registry);
}

exports.setupTracerAndExporters = setupTracerAndExporters;
10 changes: 5 additions & 5 deletions examples/mysql/setup.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'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');

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

tracer.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter({
registry.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter({
serviceName: service,
})));
tracer.addSpanProcessor(new SimpleSpanProcessor(new JaegerExporter({
registry.addSpanProcessor(new SimpleSpanProcessor(new JaegerExporter({
serviceName: service,
// The default flush interval is 5 seconds.
flushInterval: 2000
})));

// Initialize the OpenTelemetry APIs to use the BasicTracer bindings
opentelemetry.initGlobalTracer(tracer);
opentelemetry.initGlobalTracerRegistry(registry);
}

exports.setupTracerAndExporters = setupTracerAndExporters;
8 changes: 4 additions & 4 deletions examples/redis/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 @@ -23,10 +23,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);
opentelemetry.initGlobalTracerRegistry(registry);
}

exports.setupTracerAndExporters = setupTracerAndExporters;
37 changes: 19 additions & 18 deletions examples/tracer-web/index.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,59 @@
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
import { WebTracer } from '@opentelemetry/web';
import { WebTracerRegistry } from '@opentelemetry/web';
import { DocumentLoad } from '@opentelemetry/plugin-document-load';
import { ZoneScopeManager } from '@opentelemetry/scope-zone';

const webTracer = new WebTracer({
const registry = new WebTracerRegistry({
plugins: [
new DocumentLoad()
]
});
webTracer.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
registry.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));

const webTracerWithZone = new WebTracer({
const registryWithZone = new WebTracerRegistry({
scopeManager: new ZoneScopeManager(),
plugins: [
new DocumentLoad()
]
});
webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
registryWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
const tracerWithZone = registryWithZone.getTracer();

console.log('Current span is window', webTracerWithZone.getCurrentSpan() === window);
console.log('Current span is window', tracerWithZone.getCurrentSpan() === window);

// example of keeping track of scope between async operations
const prepareClickEvent = () => {
const url1 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/master/package.json';
const url2 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/master/packages/opentelemetry-web/package.json';

const element = document.getElementById('button1');
let mainSpan = webTracerWithZone.startSpan('main-span');
webTracerWithZone.bind(element, mainSpan);
let mainSpan = tracerWithZone.startSpan('main-span');
tracerWithZone.bind(element, mainSpan);

const onClick = () => {
const span1 = webTracerWithZone.startSpan(`files-series-info-1`, {
parent: webTracerWithZone.getCurrentSpan()
const span1 = tracerWithZone.startSpan(`files-series-info-1`, {
parent: tracerWithZone.getCurrentSpan()
});

const span2 = webTracerWithZone.startSpan(`files-series-info-2`, {
parent: webTracerWithZone.getCurrentSpan()
const span2 = tracerWithZone.startSpan(`files-series-info-2`, {
parent: tracerWithZone.getCurrentSpan()
});

webTracerWithZone.withSpan(span1, () => {
tracerWithZone.withSpan(span1, () => {
getData(url1).then((data) => {
console.log('current span is span1', webTracerWithZone.getCurrentSpan() === span1);
console.log('current span is span1', tracerWithZone.getCurrentSpan() === span1);
console.log('info from package.json', data.description, data.version);
webTracerWithZone.getCurrentSpan().addEvent('fetching-span1-completed');
tracerWithZone.getCurrentSpan().addEvent('fetching-span1-completed');
span1.end();
});
});

webTracerWithZone.withSpan(span2, () => {
tracerWithZone.withSpan(span2, () => {
getData(url2).then((data) => {
setTimeout(() => {
console.log('current span is span2', webTracerWithZone.getCurrentSpan() === span2);
console.log('current span is span2', tracerWithZone.getCurrentSpan() === span2);
console.log('info from package.json', data.description, data.version);
webTracerWithZone.getCurrentSpan().addEvent('fetching-span2-completed');
tracerWithZone.getCurrentSpan().addEvent('fetching-span2-completed');
span2.end();
}, 100);
});
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export * from './trace/globaltracer-utils';
export * from './trace/instrumentation/BasePlugin';
export * from './trace/NoopSpan';
export * from './trace/NoopTracer';
mayurkale22 marked this conversation as resolved.
Show resolved Hide resolved
export * from './trace/NoopTracerRegistry';
export * from './trace/NoRecordingSpan';
export * from './trace/sampler/ProbabilitySampler';
export * from './trace/spancontext-utils';
Expand Down
2 changes: 2 additions & 0 deletions packages/opentelemetry-core/src/trace/NoopTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ export class NoopTracer implements Tracer {
return NOOP_HTTP_TEXT_FORMAT;
}
}

export const noopTracer = new NoopTracer();
24 changes: 24 additions & 0 deletions packages/opentelemetry-core/src/trace/NoopTracerRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*!
* Copyright 2019, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as types from '@opentelemetry/types';
import { noopTracer } from './NoopTracer';

export class NoopTracerRegistry implements types.TracerRegistry {
dyladan marked this conversation as resolved.
Show resolved Hide resolved
getTracer(_name?: string, _version?: string): types.Tracer {
return noopTracer;
}
}
Loading