From d75f53e6e55adea69bbe139c0626cfeeff69fca6 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 2 Dec 2019 12:13:14 -0500 Subject: [PATCH 01/24] feat: spike of named tracer registry --- .gitignore | 1 + packages/opentelemetry-core/src/index.ts | 1 + .../src/trace/NoopTracer.ts | 2 + .../src/trace/NoopTracerRegistry.ts | 24 ++++ .../src/trace/globaltracer-utils.ts | 14 +-- .../src/trace/instrumentation/BasePlugin.ts | 8 +- .../test/trace/BasePlugin.test.ts | 11 +- .../test/trace/globaltracer-utils.test.ts | 26 +++-- .../test/transform.test.ts | 6 +- .../{NodeTracer.ts => NodeTracerRegistry.ts} | 4 +- packages/opentelemetry-node/src/config.ts | 4 +- packages/opentelemetry-node/src/index.ts | 4 +- .../src/instrumentation/PluginLoader.ts | 6 +- .../test/NodeTracer.test.ts | 110 +++++++++--------- .../test/instrumentation/PluginLoader.test.ts | 35 +++--- packages/opentelemetry-plugin-dns/src/dns.ts | 2 +- .../test/functionals/dns-disable.test.ts | 9 +- .../test/functionals/dns-enable.test.ts | 8 +- .../test/functionals/utils.test.ts | 10 +- .../test/integrations/dns-lookup.test.ts | 10 +- .../integrations/dnspromise-lookup.test.ts | 10 +- .../src/documentLoad.ts | 2 +- .../test/documentLoad.test.ts | 37 +++--- .../opentelemetry-plugin-grpc/src/grpc.ts | 2 +- .../test/grpc.test.ts | 57 +++++---- .../opentelemetry-plugin-http/src/http.ts | 2 +- .../test/functionals/http-disable.test.ts | 22 ++-- .../test/functionals/http-enable.test.ts | 24 ++-- .../test/functionals/http-package.test.ts | 8 +- .../test/functionals/utils.test.ts | 8 +- .../test/integrations/http-enable.test.ts | 8 +- .../test/functionals/https-disable.test.ts | 22 ++-- .../test/functionals/https-enable.test.ts | 24 ++-- .../test/functionals/https-package.test.ts | 8 +- .../test/integrations/https-enable.test.ts | 8 +- .../package.json | 4 +- .../src/mongodb.ts | 2 +- .../test/mongodb.test.ts | 34 +++--- .../tsconfig.json | 3 +- .../opentelemetry-plugin-pg/src/pg.ts | 2 +- .../opentelemetry-plugin-pg/test/pg.test.ts | 9 +- .../opentelemetry-plugin-redis/src/redis.ts | 2 +- .../test/redis.test.ts | 9 +- .../test/Shim.test.ts | 6 +- .../src/BasicTracerRegistry.ts | 64 ++++++++++ packages/opentelemetry-tracing/src/Span.ts | 6 +- .../src/{BasicTracer.ts => Tracer.ts} | 26 ++--- packages/opentelemetry-tracing/src/index.ts | 3 +- packages/opentelemetry-tracing/src/types.ts | 4 +- packages/opentelemetry-tracing/src/utility.ts | 6 +- ...er.test.ts => BasicTracerRegistry.test.ts} | 110 +++++++++--------- .../test/MultiSpanProcessor.test.ts | 4 +- .../opentelemetry-tracing/test/Span.test.ts | 6 +- .../test/export/BatchSpanProcessor.test.ts | 10 +- .../test/export/ConsoleSpanExporter.test.ts | 10 +- .../test/export/InMemorySpanExporter.test.ts | 26 +++-- .../test/export/SimpleSpanProcessor.test.ts | 8 +- packages/opentelemetry-types/src/index.ts | 1 + .../src/trace/instrumentation/Plugin.ts | 6 +- .../src/trace/tracer_registry.ts | 31 +++++ .../{WebTracer.ts => WebTracerRegistry.ts} | 6 +- packages/opentelemetry-web/src/index.ts | 2 +- .../opentelemetry-web/test/WebTracer.test.ts | 27 ++--- 63 files changed, 542 insertions(+), 422 deletions(-) create mode 100644 packages/opentelemetry-core/src/trace/NoopTracerRegistry.ts rename packages/opentelemetry-node/src/{NodeTracer.ts => NodeTracerRegistry.ts} (92%) create mode 100644 packages/opentelemetry-tracing/src/BasicTracerRegistry.ts rename packages/opentelemetry-tracing/src/{BasicTracer.ts => Tracer.ts} (86%) rename packages/opentelemetry-tracing/test/{BasicTracer.test.ts => BasicTracerRegistry.test.ts} (82%) create mode 100644 packages/opentelemetry-types/src/trace/tracer_registry.ts rename packages/opentelemetry-web/src/{WebTracer.ts => WebTracerRegistry.ts} (88%) diff --git a/.gitignore b/.gitignore index f9d0089925..9900542847 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,7 @@ docs #lerna .changelog +package.json.lerna_backup # OS generated files .DS_Store diff --git a/packages/opentelemetry-core/src/index.ts b/packages/opentelemetry-core/src/index.ts index 581d9ab055..a1b3c00487 100644 --- a/packages/opentelemetry-core/src/index.ts +++ b/packages/opentelemetry-core/src/index.ts @@ -26,6 +26,7 @@ export * from './trace/globaltracer-utils'; export * from './trace/instrumentation/BasePlugin'; export * from './trace/NoopSpan'; export * from './trace/NoopTracer'; +export * from './trace/NoopTracerRegistry'; export * from './trace/NoRecordingSpan'; export * from './trace/sampler/ProbabilitySampler'; export * from './trace/spancontext-utils'; diff --git a/packages/opentelemetry-core/src/trace/NoopTracer.ts b/packages/opentelemetry-core/src/trace/NoopTracer.ts index ea36a96ecf..bd569977fa 100644 --- a/packages/opentelemetry-core/src/trace/NoopTracer.ts +++ b/packages/opentelemetry-core/src/trace/NoopTracer.ts @@ -59,3 +59,5 @@ export class NoopTracer implements Tracer { return NOOP_HTTP_TEXT_FORMAT; } } + +export const noopTracer = new NoopTracer(); diff --git a/packages/opentelemetry-core/src/trace/NoopTracerRegistry.ts b/packages/opentelemetry-core/src/trace/NoopTracerRegistry.ts new file mode 100644 index 0000000000..3283627921 --- /dev/null +++ b/packages/opentelemetry-core/src/trace/NoopTracerRegistry.ts @@ -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 { + getTracer(_name?: string, _version?: string): types.Tracer { + return noopTracer; + } +} diff --git a/packages/opentelemetry-core/src/trace/globaltracer-utils.ts b/packages/opentelemetry-core/src/trace/globaltracer-utils.ts index 9f16402e4d..360aad57a7 100644 --- a/packages/opentelemetry-core/src/trace/globaltracer-utils.ts +++ b/packages/opentelemetry-core/src/trace/globaltracer-utils.ts @@ -15,21 +15,21 @@ */ import * as types from '@opentelemetry/types'; -import { TracerDelegate } from './TracerDelegate'; +import { NoopTracerRegistry } from './NoopTracerRegistry'; -let globalTracerDelegate = new TracerDelegate(); +let globalTracerRegistry: types.TracerRegistry = new NoopTracerRegistry(); /** * Set the current global tracer. Returns the initialized global tracer */ -export function initGlobalTracer(tracer: types.Tracer): types.Tracer { - return (globalTracerDelegate = new TracerDelegate(tracer)); +export function initGlobalTracerRegistry(tracerRegistry: types.TracerRegistry): types.TracerRegistry { + return (globalTracerRegistry = tracerRegistry); } /** * Returns the global tracer */ -export function getTracer(): types.Tracer { - // Return the global tracer delegate - return globalTracerDelegate; +export function getTracerRegistry(): types.TracerRegistry { + // Return the global tracer registry + return globalTracerRegistry; } diff --git a/packages/opentelemetry-core/src/trace/instrumentation/BasePlugin.ts b/packages/opentelemetry-core/src/trace/instrumentation/BasePlugin.ts index 5a58aa6962..658f622edd 100644 --- a/packages/opentelemetry-core/src/trace/instrumentation/BasePlugin.ts +++ b/packages/opentelemetry-core/src/trace/instrumentation/BasePlugin.ts @@ -21,6 +21,7 @@ import { PluginConfig, PluginInternalFiles, PluginInternalFilesVersion, + TracerRegistry, } from '@opentelemetry/types'; import * as semver from 'semver'; import * as path from 'path'; @@ -39,14 +40,17 @@ export abstract class BasePlugin implements Plugin { protected readonly _internalFilesList?: PluginInternalFiles; // required for internalFilesExports protected _config!: PluginConfig; + + constructor(protected readonly _tracerName: string, protected readonly _tracerVersion?: string) { } + enable( moduleExports: T, - tracer: Tracer, + tracerRegistry: TracerRegistry, logger: Logger, config?: PluginConfig ): T { this._moduleExports = moduleExports; - this._tracer = tracer; + this._tracer = tracerRegistry.getTracer(this._tracerName, this._tracerVersion); this._logger = logger; this._internalFilesExports = this._loadInternalFilesExports(); if (config) this._config = config; diff --git a/packages/opentelemetry-core/test/trace/BasePlugin.test.ts b/packages/opentelemetry-core/test/trace/BasePlugin.test.ts index 6a67fdcc5a..b0b728d8c7 100644 --- a/packages/opentelemetry-core/test/trace/BasePlugin.test.ts +++ b/packages/opentelemetry-core/test/trace/BasePlugin.test.ts @@ -14,12 +14,13 @@ * limitations under the License. */ -import { BasePlugin, NoopTracer, NoopLogger } from '../../src'; import * as assert from 'assert'; import * as path from 'path'; +import { BasePlugin, NoopLogger } from '../../src'; +import { NoopTracerRegistry } from '../../src/trace/NoopTracerRegistry'; import * as types from './fixtures/test-package/foo/bar/internal'; -const tracer = new NoopTracer(); +const registry = new NoopTracerRegistry(); const logger = new NoopLogger(); describe('BasePlugin', () => { @@ -28,7 +29,7 @@ describe('BasePlugin', () => { const testPackage = require('./fixtures/test-package'); const plugin = new TestPlugin(); assert.doesNotThrow(() => { - plugin.enable(testPackage, tracer, logger); + plugin.enable(testPackage, registry, logger); }); // @TODO: https://github.com/open-telemetry/opentelemetry-js/issues/285 @@ -61,6 +62,10 @@ class TestPlugin extends BasePlugin<{ [key: string]: Function }> { readonly version = '0.1.0'; readonly _basedir = basedir; + constructor() { + super("test-package.opentelemetry") + } + protected readonly _internalFilesList = { '0.1.0': { internal: 'foo/bar/internal.js', diff --git a/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts b/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts index 9d15b0d12f..4a0b50aa2e 100644 --- a/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts +++ b/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts @@ -17,11 +17,12 @@ import * as assert from 'assert'; import * as types from '@opentelemetry/types'; import { - getTracer, - initGlobalTracer, + getTracerRegistry, + initGlobalTracerRegistry, } from '../../src/trace/globaltracer-utils'; import { NoopTracer, NoopSpan } from '../../src'; import { TraceFlags } from '@opentelemetry/types'; +import { NoopTracerRegistry } from '../../src/trace/NoopTracerRegistry'; describe('globaltracer-utils', () => { const functions = [ @@ -32,13 +33,13 @@ describe('globaltracer-utils', () => { 'getHttpTextFormat', ]; - it('should expose a tracer via getTracer', () => { - const tracer = getTracer(); + it('should expose a tracer registry via getTracerRegistry', () => { + const tracer = getTracerRegistry(); assert.ok(tracer); assert.strictEqual(typeof tracer, 'object'); }); - describe('GlobalTracer', () => { + describe('GlobalTracerRegistry', () => { const spanContext = { traceId: 'd4cda95b652f4a1592b449d5929fda1b', spanId: '6e0c63257de34c92', @@ -47,12 +48,12 @@ describe('globaltracer-utils', () => { const dummySpan = new NoopSpan(spanContext); afterEach(() => { - initGlobalTracer(new NoopTracer()); + initGlobalTracerRegistry(new NoopTracerRegistry()); }); it('should not crash', () => { functions.forEach(fn => { - const tracer = getTracer(); + const tracer = getTracerRegistry(); try { ((tracer as unknown) as { [fn: string]: Function })[fn](); // Try to run the function assert.ok(true, fn); @@ -64,8 +65,9 @@ describe('globaltracer-utils', () => { }); }); - it('should use the global tracer', () => { - const tracer = initGlobalTracer(new TestTracer()); + it('should use the global tracer registry', () => { + initGlobalTracerRegistry(new TestTracerRegistry()); + const tracer = getTracerRegistry().getTracer("name"); const span = tracer.startSpan('test'); assert.deepStrictEqual(span, dummySpan); }); @@ -78,5 +80,11 @@ describe('globaltracer-utils', () => { return dummySpan; } } + + class TestTracerRegistry extends NoopTracerRegistry { + getTracer() { + return new TestTracer(); + } + } }); }); diff --git a/packages/opentelemetry-exporter-zipkin/test/transform.test.ts b/packages/opentelemetry-exporter-zipkin/test/transform.test.ts index a7c0399d7e..5a0bb439e9 100644 --- a/packages/opentelemetry-exporter-zipkin/test/transform.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/transform.test.ts @@ -16,7 +16,7 @@ import * as assert from 'assert'; import * as types from '@opentelemetry/types'; -import { Span, BasicTracer } from '@opentelemetry/tracing'; +import { Span, BasicTracerRegistry } from '@opentelemetry/tracing'; import { NoopLogger, hrTimeToMicroseconds, @@ -32,9 +32,9 @@ import { import * as zipkinTypes from '../src/types'; const logger = new NoopLogger(); -const tracer = new BasicTracer({ +const tracer = new BasicTracerRegistry({ logger, -}); +}).getTracer(); const parentId = '5c1c63257de34c67'; const spanContext: types.SpanContext = { traceId: 'd4cda95b652f4a1592b449d5929fda1b', diff --git a/packages/opentelemetry-node/src/NodeTracer.ts b/packages/opentelemetry-node/src/NodeTracerRegistry.ts similarity index 92% rename from packages/opentelemetry-node/src/NodeTracer.ts rename to packages/opentelemetry-node/src/NodeTracerRegistry.ts index 86591fd0ac..d2aac35236 100644 --- a/packages/opentelemetry-node/src/NodeTracer.ts +++ b/packages/opentelemetry-node/src/NodeTracerRegistry.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { BasicTracer } from '@opentelemetry/tracing'; +import { BasicTracerRegistry } from '@opentelemetry/tracing'; import { AsyncHooksScopeManager } from '@opentelemetry/scope-async-hooks'; import { PluginLoader } from './instrumentation/PluginLoader'; import { NodeTracerConfig, DEFAULT_INSTRUMENTATION_PLUGINS } from './config'; @@ -22,7 +22,7 @@ import { NodeTracerConfig, DEFAULT_INSTRUMENTATION_PLUGINS } from './config'; /** * This class represents a node tracer with `async_hooks` module. */ -export class NodeTracer extends BasicTracer { +export class NodeTracerRegistry extends BasicTracerRegistry { private readonly _pluginLoader: PluginLoader; /** diff --git a/packages/opentelemetry-node/src/config.ts b/packages/opentelemetry-node/src/config.ts index 7d0eb09175..e16a72687c 100644 --- a/packages/opentelemetry-node/src/config.ts +++ b/packages/opentelemetry-node/src/config.ts @@ -15,12 +15,12 @@ */ import { Plugins } from './instrumentation/PluginLoader'; -import { BasicTracerConfig } from '@opentelemetry/tracing'; +import { TracerConfig } from '@opentelemetry/tracing'; /** * NodeTracerConfig provides an interface for configuring a Node Tracer. */ -export interface NodeTracerConfig extends BasicTracerConfig { +export interface NodeTracerConfig extends TracerConfig { /** Plugins options. */ plugins?: Plugins; } diff --git a/packages/opentelemetry-node/src/index.ts b/packages/opentelemetry-node/src/index.ts index 6517aafec9..7c291d3284 100644 --- a/packages/opentelemetry-node/src/index.ts +++ b/packages/opentelemetry-node/src/index.ts @@ -1,4 +1,4 @@ -/*! + /*! * Copyright 2019, OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,4 +14,4 @@ * limitations under the License. */ -export * from './NodeTracer'; +export * from './NodeTracerRegistry'; diff --git a/packages/opentelemetry-node/src/instrumentation/PluginLoader.ts b/packages/opentelemetry-node/src/instrumentation/PluginLoader.ts index 3eb8881e6f..5030c9a923 100644 --- a/packages/opentelemetry-node/src/instrumentation/PluginLoader.ts +++ b/packages/opentelemetry-node/src/instrumentation/PluginLoader.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Logger, Plugin, Tracer, PluginConfig } from '@opentelemetry/types'; +import { Logger, Plugin, PluginConfig, TracerRegistry } from '@opentelemetry/types'; import * as hook from 'require-in-the-middle'; import * as utils from './utils'; @@ -55,7 +55,7 @@ export class PluginLoader { private _hookState = HookState.UNINITIALIZED; /** Constructs a new PluginLoader instance. */ - constructor(readonly tracer: Tracer, readonly logger: Logger) {} + constructor(readonly registry: TracerRegistry, readonly logger: Logger) {} /** * Loads a list of plugins. Each plugin module should implement the core @@ -115,7 +115,7 @@ export class PluginLoader { this._plugins.push(plugin); // Enable each supported plugin. - return plugin.enable(exports, this.tracer, this.logger, config); + return plugin.enable(exports, this.registry, this.logger, config); } catch (e) { this.logger.error( `PluginLoader#load: could not load plugin ${modulePath} of module ${name}. Error: ${e.message}` diff --git a/packages/opentelemetry-node/test/NodeTracer.test.ts b/packages/opentelemetry-node/test/NodeTracer.test.ts index 0cffd80c0d..5b558b1853 100644 --- a/packages/opentelemetry-node/test/NodeTracer.test.ts +++ b/packages/opentelemetry-node/test/NodeTracer.test.ts @@ -23,7 +23,7 @@ import { NoopLogger, NoRecordingSpan, } from '@opentelemetry/core'; -import { NodeTracer } from '../src/NodeTracer'; +import { NodeTracerRegistry } from '../src/NodeTracerRegistry'; import { TraceFlags } from '@opentelemetry/types'; import { Span } from '@opentelemetry/tracing'; import * as path from 'path'; @@ -39,8 +39,8 @@ const INSTALLED_PLUGINS_PATH = path.join( 'node_modules' ); -describe('NodeTracer', () => { - let tracer: NodeTracer; +describe('NodeTracerRegistry', () => { + let registry: NodeTracerRegistry; before(() => { module.paths.push(INSTALLED_PLUGINS_PATH); }); @@ -48,45 +48,45 @@ describe('NodeTracer', () => { afterEach(() => { // clear require cache Object.keys(require.cache).forEach(key => delete require.cache[key]); - tracer.stop(); + registry.stop(); }); describe('constructor', () => { it('should construct an instance with required only options', () => { - tracer = new NodeTracer(); - assert.ok(tracer instanceof NodeTracer); + registry = new NodeTracerRegistry(); + assert.ok(registry instanceof NodeTracerRegistry); }); it('should construct an instance with binary format', () => { - tracer = new NodeTracer({ + registry = new NodeTracerRegistry({ binaryFormat: new BinaryTraceContext(), }); - assert.ok(tracer instanceof NodeTracer); + assert.ok(registry instanceof NodeTracerRegistry); }); it('should construct an instance with http text format', () => { - tracer = new NodeTracer({ + registry = new NodeTracerRegistry({ httpTextFormat: new HttpTraceContext(), }); - assert.ok(tracer instanceof NodeTracer); + assert.ok(registry instanceof NodeTracerRegistry); }); it('should construct an instance with logger', () => { - tracer = new NodeTracer({ + registry = new NodeTracerRegistry({ logger: new NoopLogger(), }); - assert.ok(tracer instanceof NodeTracer); + assert.ok(registry instanceof NodeTracerRegistry); }); it('should construct an instance with sampler', () => { - tracer = new NodeTracer({ + registry = new NodeTracerRegistry({ sampler: ALWAYS_SAMPLER, }); - assert.ok(tracer instanceof NodeTracer); + assert.ok(registry instanceof NodeTracerRegistry); }); it('should load user configured plugins', () => { - tracer = new NodeTracer({ + registry = new NodeTracerRegistry({ logger: new NoopLogger(), plugins: { 'simple-module': { @@ -102,7 +102,7 @@ describe('NodeTracer', () => { }, }, }); - const pluginLoader = tracer['_pluginLoader']; + const pluginLoader = registry['_pluginLoader']; assert.strictEqual(pluginLoader['_plugins'].length, 0); require('simple-module'); assert.strictEqual(pluginLoader['_plugins'].length, 1); @@ -111,39 +111,39 @@ describe('NodeTracer', () => { }); it('should construct an instance with default attributes', () => { - tracer = new NodeTracer({ + registry = new NodeTracerRegistry({ defaultAttributes: { region: 'eu-west', asg: 'my-asg', }, }); - assert.ok(tracer instanceof NodeTracer); + assert.ok(registry instanceof NodeTracerRegistry); }); }); describe('.startSpan()', () => { it('should start a span with name only', () => { - tracer = new NodeTracer({ + registry = new NodeTracerRegistry({ logger: new NoopLogger(), }); - const span = tracer.startSpan('my-span'); + const span = registry.getTracer().startSpan('my-span'); assert.ok(span); }); it('should start a span with name and options', () => { - tracer = new NodeTracer({ + registry = new NodeTracerRegistry({ logger: new NoopLogger(), }); - const span = tracer.startSpan('my-span', {}); + const span = registry.getTracer().startSpan('my-span', {}); assert.ok(span); }); it('should return a default span with no sampling', () => { - tracer = new NodeTracer({ + registry = new NodeTracerRegistry({ sampler: NEVER_SAMPLER, logger: new NoopLogger(), }); - const span = tracer.startSpan('my-span'); + const span = registry.getTracer().startSpan('my-span'); assert.ok(span instanceof NoRecordingSpan); assert.strictEqual(span.context().traceFlags, TraceFlags.UNSAMPLED); assert.strictEqual(span.isRecording(), false); @@ -156,11 +156,11 @@ describe('NodeTracer', () => { const defaultAttributes = { foo: 'bar', }; - tracer = new NodeTracer({ + registry = new NodeTracerRegistry({ defaultAttributes, }); - const span = tracer.startSpan('my-span') as Span; + const span = registry.getTracer().startSpan('my-span') as Span; assert.ok(span instanceof Span); assert.deepStrictEqual(span.attributes, defaultAttributes); }); @@ -168,31 +168,31 @@ describe('NodeTracer', () => { describe('.getCurrentSpan()', () => { it('should return null with AsyncHooksScopeManager when no span started', () => { - tracer = new NodeTracer({}); - assert.deepStrictEqual(tracer.getCurrentSpan(), null); + registry = new NodeTracerRegistry({}); + assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), null); }); }); describe('.withSpan()', () => { it('should run scope with AsyncHooksScopeManager scope manager', done => { - tracer = new NodeTracer({}); - const span = tracer.startSpan('my-span'); - tracer.withSpan(span, () => { - assert.deepStrictEqual(tracer.getCurrentSpan(), span); + registry = new NodeTracerRegistry({}); + const span = registry.getTracer().startSpan('my-span'); + registry.getTracer().withSpan(span, () => { + assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), span); return done(); }); - assert.deepStrictEqual(tracer.getCurrentSpan(), null); + assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), null); }); it('should run scope with AsyncHooksScopeManager scope manager with multiple spans', done => { - tracer = new NodeTracer({}); - const span = tracer.startSpan('my-span'); - tracer.withSpan(span, () => { - assert.deepStrictEqual(tracer.getCurrentSpan(), span); - - const span1 = tracer.startSpan('my-span1', { parent: span }); - tracer.withSpan(span1, () => { - assert.deepStrictEqual(tracer.getCurrentSpan(), span1); + registry = new NodeTracerRegistry({}); + const span = registry.getTracer().startSpan('my-span'); + registry.getTracer().withSpan(span, () => { + assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), span); + + const span1 = registry.getTracer().startSpan('my-span1', { parent: span }); + registry.getTracer().withSpan(span1, () => { + assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), span1); assert.deepStrictEqual( span1.context().traceId, span.context().traceId @@ -202,48 +202,48 @@ describe('NodeTracer', () => { }); // when span ended. // @todo: below check is not running. - assert.deepStrictEqual(tracer.getCurrentSpan(), null); + assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), null); }); it('should find correct scope with promises', done => { - tracer = new NodeTracer({}); - const span = tracer.startSpan('my-span'); - tracer.withSpan(span, async () => { + registry = new NodeTracerRegistry({}); + const span = registry.getTracer().startSpan('my-span'); + registry.getTracer().withSpan(span, async () => { for (let i = 0; i < 3; i++) { await sleep(5).then(() => { - assert.deepStrictEqual(tracer.getCurrentSpan(), span); + assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), span); }); } return done(); }); - assert.deepStrictEqual(tracer.getCurrentSpan(), null); + assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), null); }); }); describe('.bind()', () => { it('should bind scope with AsyncHooksScopeManager scope manager', done => { - const tracer = new NodeTracer({}); - const span = tracer.startSpan('my-span'); + const registry = new NodeTracerRegistry({}); + const span = registry.getTracer().startSpan('my-span'); const fn = () => { - assert.deepStrictEqual(tracer.getCurrentSpan(), span); + assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), span); return done(); }; - const patchedFn = tracer.bind(fn, span); + const patchedFn = registry.getTracer().bind(fn, span); return patchedFn(); }); }); describe('.getBinaryFormat()', () => { it('should get default binary formatter', () => { - tracer = new NodeTracer({}); - assert.ok(tracer.getBinaryFormat() instanceof BinaryTraceContext); + registry = new NodeTracerRegistry({}); + assert.ok(registry.getTracer().getBinaryFormat() instanceof BinaryTraceContext); }); }); describe('.getHttpTextFormat()', () => { it('should get default HTTP text formatter', () => { - tracer = new NodeTracer({}); - assert.ok(tracer.getHttpTextFormat() instanceof HttpTraceContext); + registry = new NodeTracerRegistry({}); + assert.ok(registry.getTracer().getHttpTextFormat() instanceof HttpTraceContext); }); }); }); diff --git a/packages/opentelemetry-node/test/instrumentation/PluginLoader.test.ts b/packages/opentelemetry-node/test/instrumentation/PluginLoader.test.ts index af6ca193e7..c36a2f8070 100644 --- a/packages/opentelemetry-node/test/instrumentation/PluginLoader.test.ts +++ b/packages/opentelemetry-node/test/instrumentation/PluginLoader.test.ts @@ -14,15 +14,10 @@ * limitations under the License. */ -import { NoopLogger, NoopTracer } from '@opentelemetry/core'; +import { NoopLogger, NoopTracerRegistry } from '@opentelemetry/core'; import * as assert from 'assert'; import * as path from 'path'; -import { - HookState, - PluginLoader, - searchPathForTest, - Plugins, -} from '../../src/instrumentation/PluginLoader'; +import { HookState, PluginLoader, Plugins, searchPathForTest } from '../../src/instrumentation/PluginLoader'; const INSTALLED_PLUGINS_PATH = path.join(__dirname, 'node_modules'); @@ -86,7 +81,7 @@ const notSupportedVersionPlugins: Plugins = { }; describe('PluginLoader', () => { - const tracer = new NoopTracer(); + const registry = new NoopTracerRegistry(); const logger = new NoopLogger(); before(() => { @@ -101,19 +96,19 @@ describe('PluginLoader', () => { describe('.state()', () => { it('returns UNINITIALIZED when first called', () => { - const pluginLoader = new PluginLoader(tracer, logger); + const pluginLoader = new PluginLoader(registry, logger); assert.strictEqual(pluginLoader['_hookState'], HookState.UNINITIALIZED); }); it('transitions from UNINITIALIZED to ENABLED', () => { - const pluginLoader = new PluginLoader(tracer, logger); + const pluginLoader = new PluginLoader(registry, logger); pluginLoader.load(simplePlugins); assert.strictEqual(pluginLoader['_hookState'], HookState.ENABLED); pluginLoader.unload(); }); it('transitions from ENABLED to DISABLED', () => { - const pluginLoader = new PluginLoader(tracer, logger); + const pluginLoader = new PluginLoader(registry, logger); pluginLoader.load(simplePlugins).unload(); assert.strictEqual(pluginLoader['_hookState'], HookState.DISABLED); }); @@ -138,7 +133,7 @@ describe('PluginLoader', () => { }); it('should load a plugin and patch the target modules', () => { - const pluginLoader = new PluginLoader(tracer, logger); + const pluginLoader = new PluginLoader(registry, logger); assert.strictEqual(pluginLoader['_plugins'].length, 0); pluginLoader.load(simplePlugins); // The hook is only called the first time the module is loaded. @@ -150,7 +145,7 @@ describe('PluginLoader', () => { }); it('should load a plugin and patch the core module', () => { - const pluginLoader = new PluginLoader(tracer, logger); + const pluginLoader = new PluginLoader(registry, logger); assert.strictEqual(pluginLoader['_plugins'].length, 0); pluginLoader.load(httpPlugins); // The hook is only called the first time the module is loaded. @@ -161,7 +156,7 @@ describe('PluginLoader', () => { }); // @TODO: simplify this test once we can load module with custom path it('should not load the plugin when supported versions does not match', () => { - const pluginLoader = new PluginLoader(tracer, logger); + const pluginLoader = new PluginLoader(registry, logger); assert.strictEqual(pluginLoader['_plugins'].length, 0); pluginLoader.load(notSupportedVersionPlugins); // The hook is only called the first time the module is loaded. @@ -171,7 +166,7 @@ describe('PluginLoader', () => { }); // @TODO: simplify this test once we can load module with custom path it('should load a plugin and patch the target modules when supported versions match', () => { - const pluginLoader = new PluginLoader(tracer, logger); + const pluginLoader = new PluginLoader(registry, logger); assert.strictEqual(pluginLoader['_plugins'].length, 0); pluginLoader.load(supportedVersionPlugins); // The hook is only called the first time the module is loaded. @@ -183,7 +178,7 @@ describe('PluginLoader', () => { }); it('should not load a plugin when value is false', () => { - const pluginLoader = new PluginLoader(tracer, logger); + const pluginLoader = new PluginLoader(registry, logger); assert.strictEqual(pluginLoader['_plugins'].length, 0); pluginLoader.load(disablePlugins); const simpleModule = require('simple-module'); @@ -194,7 +189,7 @@ describe('PluginLoader', () => { }); it('should not load a plugin when value is true but path is missing', () => { - const pluginLoader = new PluginLoader(tracer, logger); + const pluginLoader = new PluginLoader(registry, logger); assert.strictEqual(pluginLoader['_plugins'].length, 0); pluginLoader.load(missingPathPlugins); const simpleModule = require('simple-module'); @@ -205,7 +200,7 @@ describe('PluginLoader', () => { }); it('should not load a non existing plugin', () => { - const pluginLoader = new PluginLoader(tracer, logger); + const pluginLoader = new PluginLoader(registry, logger); assert.strictEqual(pluginLoader['_plugins'].length, 0); pluginLoader.load(nonexistentPlugins); assert.strictEqual(pluginLoader['_plugins'].length, 0); @@ -213,7 +208,7 @@ describe('PluginLoader', () => { }); it(`doesn't patch modules for which plugins aren't specified`, () => { - const pluginLoader = new PluginLoader(tracer, logger); + const pluginLoader = new PluginLoader(registry, logger); pluginLoader.load({}); assert.strictEqual(require('simple-module').value(), 0); pluginLoader.unload(); @@ -222,7 +217,7 @@ describe('PluginLoader', () => { describe('.unload()', () => { it('should unload the plugins and unpatch the target module when unloads', () => { - const pluginLoader = new PluginLoader(tracer, logger); + const pluginLoader = new PluginLoader(registry, logger); assert.strictEqual(pluginLoader['_plugins'].length, 0); pluginLoader.load(simplePlugins); // The hook is only called the first time the module is loaded. diff --git a/packages/opentelemetry-plugin-dns/src/dns.ts b/packages/opentelemetry-plugin-dns/src/dns.ts index 2046ecb320..38edadf5e0 100644 --- a/packages/opentelemetry-plugin-dns/src/dns.ts +++ b/packages/opentelemetry-plugin-dns/src/dns.ts @@ -39,7 +39,7 @@ export class DnsPlugin extends BasePlugin { protected _config!: DnsPluginConfig; constructor(readonly moduleName: string, readonly version: string) { - super(); + super(`opentelemetry.${moduleName}`, "0.2.0"); // For now component is equal to moduleName but it can change in the future. this.component = this.moduleName; this._config = {}; diff --git a/packages/opentelemetry-plugin-dns/test/functionals/dns-disable.test.ts b/packages/opentelemetry-plugin-dns/test/functionals/dns-disable.test.ts index c3bd111b53..5251829324 100644 --- a/packages/opentelemetry-plugin-dns/test/functionals/dns-disable.test.ts +++ b/packages/opentelemetry-plugin-dns/test/functionals/dns-disable.test.ts @@ -20,19 +20,20 @@ import { } from '@opentelemetry/tracing'; import * as assert from 'assert'; import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { plugin } from '../../src/dns'; import * as sinon from 'sinon'; import * as dns from 'dns'; const memoryExporter = new InMemorySpanExporter(); const logger = new NoopLogger(); -const tracer = new NodeTracer({ logger }); -tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const registry = new NodeTracerRegistry({ logger }); +const tracer = registry.getTracer(); +registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); describe('DnsPlugin', () => { before(() => { - plugin.enable(dns, tracer, tracer.logger); + plugin.enable(dns, registry, tracer.logger); assert.strictEqual(dns.lookup.__wrapped, true); }); diff --git a/packages/opentelemetry-plugin-dns/test/functionals/dns-enable.test.ts b/packages/opentelemetry-plugin-dns/test/functionals/dns-enable.test.ts index be6fde2d93..cb59bcb133 100644 --- a/packages/opentelemetry-plugin-dns/test/functionals/dns-enable.test.ts +++ b/packages/opentelemetry-plugin-dns/test/functionals/dns-enable.test.ts @@ -20,18 +20,18 @@ import { } from '@opentelemetry/tracing'; import * as assert from 'assert'; import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { plugin, DnsPlugin } from '../../src/dns'; import * as dns from 'dns'; const memoryExporter = new InMemorySpanExporter(); const logger = new NoopLogger(); -const tracer = new NodeTracer({ logger }); -tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const registry = new NodeTracerRegistry({ logger }); +registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); describe('DnsPlugin', () => { before(() => { - plugin.enable(dns, tracer, tracer.logger); + plugin.enable(dns, registry, registry.logger); }); after(() => { diff --git a/packages/opentelemetry-plugin-dns/test/functionals/utils.test.ts b/packages/opentelemetry-plugin-dns/test/functionals/utils.test.ts index 8bda076750..f0b74c17ce 100644 --- a/packages/opentelemetry-plugin-dns/test/functionals/utils.test.ts +++ b/packages/opentelemetry-plugin-dns/test/functionals/utils.test.ts @@ -14,14 +14,14 @@ * limitations under the License. */ +import { NoopLogger } from '@opentelemetry/core'; +import { BasicTracerRegistry, Span } from '@opentelemetry/tracing'; +import { CanonicalCode, SpanKind } from '@opentelemetry/types'; import * as assert from 'assert'; import * as sinon from 'sinon'; -import { CanonicalCode, SpanKind } from '@opentelemetry/types'; +import { AttributeNames } from '../../src/enums/AttributeNames'; import { IgnoreMatcher } from '../../src/types'; import * as utils from '../../src/utils'; -import { Span, BasicTracer } from '@opentelemetry/tracing'; -import { NoopLogger } from '@opentelemetry/core'; -import { AttributeNames } from '../../src/enums/AttributeNames'; describe('Utility', () => { describe('parseResponseStatus()', () => { @@ -162,7 +162,7 @@ describe('Utility', () => { it('should have error attributes', () => { const errorMessage = 'test error'; const span = new Span( - new BasicTracer(), + new BasicTracerRegistry().getTracer(), 'test', { spanId: '', traceId: '' }, SpanKind.INTERNAL diff --git a/packages/opentelemetry-plugin-dns/test/integrations/dns-lookup.test.ts b/packages/opentelemetry-plugin-dns/test/integrations/dns-lookup.test.ts index 05ba0effb4..088a6ea93d 100644 --- a/packages/opentelemetry-plugin-dns/test/integrations/dns-lookup.test.ts +++ b/packages/opentelemetry-plugin-dns/test/integrations/dns-lookup.test.ts @@ -20,7 +20,7 @@ import { } from '@opentelemetry/tracing'; import * as assert from 'assert'; import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { plugin } from '../../src/dns'; import * as dns from 'dns'; import * as utils from '../utils/utils'; @@ -29,14 +29,14 @@ import { CanonicalCode } from '@opentelemetry/types'; const memoryExporter = new InMemorySpanExporter(); const logger = new NoopLogger(); -const tracer = new NodeTracer({ logger }); -tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const registry = new NodeTracerRegistry({ logger }); +registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); describe('dns.lookup()', () => { before(function(done) { // mandatory if (process.env.CI) { - plugin.enable(dns, tracer, tracer.logger); + plugin.enable(dns, registry, registry.logger); done(); return; } @@ -48,7 +48,7 @@ describe('dns.lookup()', () => { } done(); }); - plugin.enable(dns, tracer, tracer.logger); + plugin.enable(dns, registry, registry.logger); }); afterEach(() => { diff --git a/packages/opentelemetry-plugin-dns/test/integrations/dnspromise-lookup.test.ts b/packages/opentelemetry-plugin-dns/test/integrations/dnspromise-lookup.test.ts index aec20fa398..ec9e49ae51 100644 --- a/packages/opentelemetry-plugin-dns/test/integrations/dnspromise-lookup.test.ts +++ b/packages/opentelemetry-plugin-dns/test/integrations/dnspromise-lookup.test.ts @@ -20,7 +20,7 @@ import { } from '@opentelemetry/tracing'; import * as assert from 'assert'; import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { plugin } from '../../src/dns'; import * as dns from 'dns'; import * as utils from '../utils/utils'; @@ -30,8 +30,8 @@ import { CanonicalCode } from '@opentelemetry/types'; const memoryExporter = new InMemorySpanExporter(); const logger = new NoopLogger(); -const tracer = new NodeTracer({ logger }); -tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +const registry = new NodeTracerRegistry({ logger }); +registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); describe('dns.promises.lookup()', () => { before(function(done) { @@ -42,7 +42,7 @@ describe('dns.promises.lookup()', () => { // if node version is supported, it's mandatory for CI if (process.env.CI) { - plugin.enable(dns, tracer, tracer.logger); + plugin.enable(dns, registry, registry.logger); done(); return; } @@ -54,7 +54,7 @@ describe('dns.promises.lookup()', () => { } done(); }); - plugin.enable(dns, tracer, tracer.logger); + plugin.enable(dns, registry, registry.logger); }); afterEach(() => { diff --git a/packages/opentelemetry-plugin-document-load/src/documentLoad.ts b/packages/opentelemetry-plugin-document-load/src/documentLoad.ts index 8e2e3da7d8..1d02dac110 100644 --- a/packages/opentelemetry-plugin-document-load/src/documentLoad.ts +++ b/packages/opentelemetry-plugin-document-load/src/documentLoad.ts @@ -40,7 +40,7 @@ export class DocumentLoad extends BasePlugin { * @param config */ constructor(config: PluginConfig = {}) { - super(); + super("opentelemetry.document-load", "0.2.0"); this._onDocumentLoaded = this._onDocumentLoaded.bind(this); this._config = config; } diff --git a/packages/opentelemetry-plugin-document-load/test/documentLoad.test.ts b/packages/opentelemetry-plugin-document-load/test/documentLoad.test.ts index cb17ceb566..adf4cb9d0f 100644 --- a/packages/opentelemetry-plugin-document-load/test/documentLoad.test.ts +++ b/packages/opentelemetry-plugin-document-load/test/documentLoad.test.ts @@ -18,18 +18,11 @@ * Can't use Sinon Fake Time here as then cannot stub the performance getEntriesByType with desired metrics */ -import * as assert from 'assert'; -import * as sinon from 'sinon'; - import { ConsoleLogger, TRACE_PARENT_HEADER } from '@opentelemetry/core'; -import { - BasicTracer, - ReadableSpan, - SimpleSpanProcessor, - SpanExporter, -} from '@opentelemetry/tracing'; +import { BasicTracerRegistry, ReadableSpan, SimpleSpanProcessor, SpanExporter } from '@opentelemetry/tracing'; import { Logger, PluginConfig, TimedEvent } from '@opentelemetry/types'; - +import * as assert from 'assert'; +import * as sinon from 'sinon'; import { ExportResult } from '../../opentelemetry-base/build/src'; import { DocumentLoad } from '../src'; import { PerformanceTimingNames as PTN } from '../src/enums/PerformanceTimingNames'; @@ -193,7 +186,7 @@ function ensureNetworkEventsExists(events: TimedEvent[]) { describe('DocumentLoad Plugin', () => { let plugin: DocumentLoad; let moduleExports: any; - let tracer: BasicTracer; + let registry: BasicTracerRegistry; let logger: Logger; let config: PluginConfig; let spanProcessor: SimpleSpanProcessor; @@ -205,13 +198,13 @@ describe('DocumentLoad Plugin', () => { value: 'complete', }); moduleExports = {}; - tracer = new BasicTracer(); + registry = new BasicTracerRegistry(); logger = new ConsoleLogger(); config = {}; plugin = new DocumentLoad(); dummyExporter = new DummyExporter(); spanProcessor = new SimpleSpanProcessor(dummyExporter); - tracer.addSpanProcessor(spanProcessor); + registry.addSpanProcessor(spanProcessor); }); afterEach(() => { @@ -239,7 +232,7 @@ describe('DocumentLoad Plugin', () => { spyEntries.restore(); }); it('should start collecting the performance immediately', done => { - plugin.enable(moduleExports, tracer, logger, config); + plugin.enable(moduleExports, registry, logger, config); setTimeout(() => { assert.strictEqual(window.document.readyState, 'complete'); assert.strictEqual(spyEntries.callCount, 2); @@ -266,7 +259,7 @@ describe('DocumentLoad Plugin', () => { it('should collect performance after document load event', done => { const spy = sinon.spy(window, 'addEventListener'); - plugin.enable(moduleExports, tracer, logger, config); + plugin.enable(moduleExports, registry, logger, config); const args = spy.args[0]; const name = args[0]; assert.strictEqual(name, 'load'); @@ -301,7 +294,7 @@ describe('DocumentLoad Plugin', () => { it('should export correct span with events', done => { const spyOnEnd = sinon.spy(dummyExporter, 'export'); - plugin.enable(moduleExports, tracer, logger, config); + plugin.enable(moduleExports, registry, logger, config); setTimeout(() => { const rootSpan = spyOnEnd.args[0][0][0] as ReadableSpan; @@ -358,7 +351,7 @@ describe('DocumentLoad Plugin', () => { it('should create a root span with server context traceId', done => { const spyOnEnd = sinon.spy(dummyExporter, 'export'); - plugin.enable(moduleExports, tracer, logger, config); + plugin.enable(moduleExports, registry, logger, config); setTimeout(() => { const rootSpan = spyOnEnd.args[0][0][0] as ReadableSpan; const fetchSpan = spyOnEnd.args[1][0][0] as ReadableSpan; @@ -394,7 +387,7 @@ describe('DocumentLoad Plugin', () => { it('should create span for each of the resource', done => { const spyOnEnd = sinon.spy(dummyExporter, 'export'); - plugin.enable(moduleExports, tracer, logger, config); + plugin.enable(moduleExports, registry, logger, config); setTimeout(() => { const spanResource1 = spyOnEnd.args[1][0][0] as ReadableSpan; const spanResource2 = spyOnEnd.args[2][0][0] as ReadableSpan; @@ -432,7 +425,7 @@ describe('DocumentLoad Plugin', () => { it('should create span for each of the resource', done => { const spyOnEnd = sinon.spy(dummyExporter, 'export'); - plugin.enable(moduleExports, tracer, logger, config); + plugin.enable(moduleExports, registry, logger, config); setTimeout(() => { const spanResource1 = spyOnEnd.args[1][0][0] as ReadableSpan; @@ -473,7 +466,7 @@ describe('DocumentLoad Plugin', () => { it('should still export rootSpan and fetchSpan', done => { const spyOnEnd = sinon.spy(dummyExporter, 'export'); - plugin.enable(moduleExports, tracer, logger, config); + plugin.enable(moduleExports, registry, logger, config); setTimeout(() => { const rootSpan = spyOnEnd.args[0][0][0] as ReadableSpan; @@ -505,7 +498,7 @@ describe('DocumentLoad Plugin', () => { it('should export correct span with events', done => { const spyOnEnd = sinon.spy(dummyExporter, 'export'); - plugin.enable(moduleExports, tracer, logger, config); + plugin.enable(moduleExports, registry, logger, config); setTimeout(() => { const rootSpan = spyOnEnd.args[0][0][0] as ReadableSpan; const fetchSpan = spyOnEnd.args[1][0][0] as ReadableSpan; @@ -553,7 +546,7 @@ describe('DocumentLoad Plugin', () => { it('should not create any span', done => { const spyOnEnd = sinon.spy(dummyExporter, 'export'); - plugin.enable(moduleExports, tracer, logger, config); + plugin.enable(moduleExports, registry, logger, config); setTimeout(() => { assert.ok(spyOnEnd.callCount === 0); done(); diff --git a/packages/opentelemetry-plugin-grpc/src/grpc.ts b/packages/opentelemetry-plugin-grpc/src/grpc.ts index 9c44c65abd..3f8475993c 100644 --- a/packages/opentelemetry-plugin-grpc/src/grpc.ts +++ b/packages/opentelemetry-plugin-grpc/src/grpc.ts @@ -56,7 +56,7 @@ export class GrpcPlugin extends BasePlugin { protected _config!: GrpcPluginOptions; constructor(readonly moduleName: string, readonly version: string) { - super(); + super(`opentelemetry.${moduleName}`, "0.2.0"); this._config = {}; } diff --git a/packages/opentelemetry-plugin-grpc/test/grpc.test.ts b/packages/opentelemetry-plugin-grpc/test/grpc.test.ts index eb88eed59b..b38735f3cb 100644 --- a/packages/opentelemetry-plugin-grpc/test/grpc.test.ts +++ b/packages/opentelemetry-plugin-grpc/test/grpc.test.ts @@ -14,22 +14,17 @@ * limitations under the License. */ -import { NoopLogger, NoopTracer } from '@opentelemetry/core'; -import { - InMemorySpanExporter, - SimpleSpanProcessor, -} from '@opentelemetry/tracing'; -import { SpanKind, Tracer } from '@opentelemetry/types'; -import { NodeTracer } from '@opentelemetry/node'; - -import { assertSpan, assertPropagation } from './utils/assertionUtils'; -import { GrpcPlugin, plugin } from '../src'; -import { SendUnaryDataCallback } from '../src/types'; - +import { NoopLogger, NoopTracerRegistry } from '@opentelemetry/core'; +import { NodeTracerRegistry } from '@opentelemetry/node'; +import { InMemorySpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing'; +import { SpanKind } from '@opentelemetry/types'; import * as assert from 'assert'; -import * as semver from 'semver'; import * as grpc from 'grpc'; +import * as semver from 'semver'; import * as sinon from 'sinon'; +import { GrpcPlugin, plugin } from '../src'; +import { SendUnaryDataCallback } from '../src/types'; +import { assertPropagation, assertSpan } from './utils/assertionUtils'; const PROTO_PATH = __dirname + '/fixtures/grpc-test.proto'; const memoryExporter = new InMemorySpanExporter(); @@ -298,7 +293,7 @@ describe('GrpcPlugin', () => { }); it('should patch client constructor makeClientConstructor() and makeGenericClientConstructor()', () => { - plugin.enable(grpc, new NoopTracer(), new NoopLogger()); + plugin.enable(grpc, new NoopTracerRegistry(), new NoopLogger()); (plugin['_moduleExports'] as any).makeGenericClientConstructor({}); assert.strictEqual(clientPatchStub.callCount, 1); }); @@ -343,7 +338,7 @@ describe('GrpcPlugin', () => { const runTest = ( method: typeof methodList[0], - tracer: Tracer, + registry: NodeTracerRegistry, checkSpans = true ) => { it(`should ${ @@ -383,9 +378,9 @@ describe('GrpcPlugin', () => { const expectEmpty = memoryExporter.getFinishedSpans(); assert.strictEqual(expectEmpty.length, 0); - const span = tracer.startSpan('TestSpan', { kind: SpanKind.PRODUCER }); - return tracer.withSpan(span, async () => { - const rootSpan = tracer.getCurrentSpan(); + const span = registry.getTracer().startSpan('TestSpan', { kind: SpanKind.PRODUCER }); + return registry.getTracer().withSpan(span, async () => { + const rootSpan = registry.getTracer().getCurrentSpan(); if (!rootSpan) { assert.ok(false); return; // return so typechecking passes for rootSpan.end() @@ -438,7 +433,7 @@ describe('GrpcPlugin', () => { method: typeof methodList[0], key: string, errorCode: number, - tracer: Tracer + registry: NodeTracerRegistry ) => { it(`should raise an error for client/server rootSpans: method=${method.methodName}, status=${key}`, async () => { const expectEmpty = memoryExporter.getFinishedSpans(); @@ -476,9 +471,9 @@ describe('GrpcPlugin', () => { const expectEmpty = memoryExporter.getFinishedSpans(); assert.strictEqual(expectEmpty.length, 0); - const span = tracer.startSpan('TestSpan', { kind: SpanKind.PRODUCER }); - return tracer.withSpan(span, async () => { - const rootSpan = tracer.getCurrentSpan(); + const span = registry.getTracer().startSpan('TestSpan', { kind: SpanKind.PRODUCER }); + return registry.getTracer().withSpan(span, async () => { + const rootSpan = registry.getTracer().getCurrentSpan(); if (!rootSpan) { assert.ok(false); return; // return so typechecking passes for rootSpan.end() @@ -525,8 +520,8 @@ describe('GrpcPlugin', () => { describe('enable()', () => { const logger = new NoopLogger(); - const tracer = new NodeTracer({ logger }); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + const registry = new NodeTracerRegistry({ logger }); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); beforeEach(() => { memoryExporter.reset(); }); @@ -535,7 +530,7 @@ describe('GrpcPlugin', () => { const config = { // TODO: add plugin options here once supported }; - plugin.enable(grpc, tracer, logger, config); + plugin.enable(grpc, registry, logger, config); const proto = grpc.load(PROTO_PATH).pkg_test; server = startServer(grpc, proto); @@ -552,7 +547,7 @@ describe('GrpcPlugin', () => { methodList.map(method => { describe(`Test automatic tracing for grpc remote method ${method.description}`, () => { - runTest(method, tracer); + runTest(method, registry); }); }); @@ -562,7 +557,7 @@ describe('GrpcPlugin', () => { // tslint:disable-next-line:no-any const errorCode = Number(grpc.status[statusKey as any]); if (errorCode > grpc.status.OK) { - runErrorTest(method, statusKey, errorCode, tracer); + runErrorTest(method, statusKey, errorCode, registry); } }); }); @@ -571,14 +566,14 @@ describe('GrpcPlugin', () => { describe('disable()', () => { const logger = new NoopLogger(); - const tracer = new NodeTracer({ logger }); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + const registry = new NodeTracerRegistry({ logger }); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); beforeEach(() => { memoryExporter.reset(); }); before(() => { - plugin.enable(grpc, tracer, logger); + plugin.enable(grpc, registry, logger); plugin.disable(); const proto = grpc.load(PROTO_PATH).pkg_test; @@ -595,7 +590,7 @@ describe('GrpcPlugin', () => { methodList.map(method => { describe(`Test automatic tracing for grpc remote method ${method.description}`, () => { - runTest(method, tracer, false); + runTest(method, registry, false); }); }); }); diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index 22c34c62b6..b71bce7aa9 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -56,7 +56,7 @@ export class HttpPlugin extends BasePlugin { private readonly _spanNotEnded: WeakSet; constructor(readonly moduleName: string, readonly version: string) { - super(); + super(`opentelemetry.${moduleName}`, "0.2.0"); // For now component is equal to moduleName but it can change in the future. this.component = this.moduleName; this._spanNotEnded = new WeakSet(); diff --git a/packages/opentelemetry-plugin-http/test/functionals/http-disable.test.ts b/packages/opentelemetry-plugin-http/test/functionals/http-disable.test.ts index 4aba514d61..d92e44b33d 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/http-disable.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/http-disable.test.ts @@ -20,10 +20,8 @@ import * as nock from 'nock'; import * as sinon from 'sinon'; import { plugin } from '../../src/http'; -import { NodeTracer } from '@opentelemetry/node'; -import { NoopLogger } from '@opentelemetry/core'; +import { NoopLogger, NoopTracerRegistry, noopTracer } from '@opentelemetry/core'; import { AddressInfo } from 'net'; -import { DummyPropagation } from '../utils/DummyPropagation'; import { httpRequest } from '../utils/httpRequest'; describe('HttpPlugin', () => { @@ -31,17 +29,13 @@ describe('HttpPlugin', () => { let serverPort = 0; describe('disable()', () => { - const httpTextFormat = new DummyPropagation(); const logger = new NoopLogger(); - const tracer = new NodeTracer({ - logger, - httpTextFormat, - }); + const registry = new NoopTracerRegistry(); before(() => { nock.cleanAll(); nock.enableNetConnect(); - plugin.enable(http, tracer, tracer.logger); + plugin.enable(http, registry, logger); // Ensure that http module is patched. assert.strictEqual(http.Server.prototype.emit.__wrapped, true); server = http.createServer((request, response) => { @@ -55,8 +49,8 @@ describe('HttpPlugin', () => { }); beforeEach(() => { - tracer.startSpan = sinon.spy(); - tracer.withSpan = sinon.spy(); + noopTracer.startSpan = sinon.spy(); + noopTracer.withSpan = sinon.spy(); }); afterEach(() => { @@ -67,7 +61,7 @@ describe('HttpPlugin', () => { server.close(); }); describe('unpatch()', () => { - it('should not call tracer methods for creating span', async () => { + it('should not call registry methods for creating span', async () => { plugin.disable(); const testPath = '/incoming/unpatch/'; @@ -75,12 +69,12 @@ describe('HttpPlugin', () => { await httpRequest.get(options).then(result => { assert.strictEqual( - (tracer.startSpan as sinon.SinonSpy).called, + (noopTracer.startSpan as sinon.SinonSpy).called, false ); assert.strictEqual(http.Server.prototype.emit.__wrapped, undefined); - assert.strictEqual((tracer.withSpan as sinon.SinonSpy).called, false); + assert.strictEqual((noopTracer.withSpan as sinon.SinonSpy).called, false); }); }); }); diff --git a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts index d64f960481..e750c90af3 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts @@ -19,7 +19,7 @@ import { SimpleSpanProcessor, } from '@opentelemetry/tracing'; import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { CanonicalCode, Span as ISpan, SpanKind } from '@opentelemetry/types'; import * as assert from 'assert'; import * as http from 'http'; @@ -43,11 +43,11 @@ const pathname = '/test'; const memoryExporter = new InMemorySpanExporter(); const httpTextFormat = new DummyPropagation(); const logger = new NoopLogger(); -const tracer = new NodeTracer({ +const registry = new NodeTracerRegistry({ logger, httpTextFormat, }); -tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); +registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); function doNock( hostname: string, @@ -107,7 +107,7 @@ describe('HttpPlugin', () => { plugin.component, process.versions.node ); - pluginWithBadOptions.enable(http, tracer, tracer.logger, config); + pluginWithBadOptions.enable(http, registry, registry.logger, config); server = http.createServer((request, response) => { response.end('Test Server Response'); }); @@ -176,7 +176,7 @@ describe('HttpPlugin', () => { ], applyCustomAttributesOnSpan: customAttributeFunction, }; - plugin.enable(http, tracer, tracer.logger, config); + plugin.enable(http, registry, registry.logger, config); server = http.createServer((request, response) => { response.end('Test Server Response'); }); @@ -197,7 +197,7 @@ describe('HttpPlugin', () => { const httpNotPatched = new HttpPlugin( plugin.component, process.versions.node - ).enable({} as Http, tracer, tracer.logger, {}); + ).enable({} as Http, registry, registry.logger, {}); assert.strictEqual(Object.keys(httpNotPatched).length, 0); }); @@ -281,8 +281,8 @@ describe('HttpPlugin', () => { const testPath = '/outgoing/rootSpan/childs/1'; doNock(hostname, testPath, 200, 'Ok'); const name = 'TestRootSpan'; - const span = tracer.startSpan(name); - return tracer.withSpan(span, async () => { + const span = registry.getTracer().startSpan(name); + return registry.getTracer().withSpan(span, async () => { const result = await httpRequest.get( `${protocol}://${hostname}${testPath}` ); @@ -324,8 +324,8 @@ describe('HttpPlugin', () => { httpErrorCodes[i].toString() ); const name = 'TestRootSpan'; - const span = tracer.startSpan(name); - return tracer.withSpan(span, async () => { + const span = registry.getTracer().startSpan(name); + return registry.getTracer().withSpan(span, async () => { const result = await httpRequest.get( `${protocol}://${hostname}${testPath}` ); @@ -363,8 +363,8 @@ describe('HttpPlugin', () => { const num = 5; doNock(hostname, testPath, 200, 'Ok', num); const name = 'TestRootSpan'; - const span = tracer.startSpan(name); - await tracer.withSpan(span, async () => { + const span = registry.getTracer().startSpan(name); + await registry.getTracer().withSpan(span, async () => { for (let i = 0; i < num; i++) { await httpRequest.get(`${protocol}://${hostname}${testPath}`); const spans = memoryExporter.getFinishedSpans(); diff --git a/packages/opentelemetry-plugin-http/test/functionals/http-package.test.ts b/packages/opentelemetry-plugin-http/test/functionals/http-package.test.ts index 278c6aec2c..ecaf307d3b 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/http-package.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/http-package.test.ts @@ -28,7 +28,7 @@ import * as superagent from 'superagent'; import * as got from 'got'; import * as request from 'request-promise-native'; import * as path from 'path'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { InMemorySpanExporter, SimpleSpanProcessor, @@ -44,11 +44,11 @@ describe('Packages', () => { const httpTextFormat = new DummyPropagation(); const logger = new NoopLogger(); - const tracer = new NodeTracer({ + const registry = new NodeTracerRegistry({ logger, httpTextFormat, }); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); beforeEach(() => { memoryExporter.reset(); }); @@ -57,7 +57,7 @@ describe('Packages', () => { const config: HttpPluginConfig = { applyCustomAttributesOnSpan: customAttributeFunction, }; - plugin.enable(http, tracer, tracer.logger, config); + plugin.enable(http, registry, registry.logger, config); }); after(() => { diff --git a/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts b/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts index 0a453cdcae..e6b3cea9b7 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts @@ -22,7 +22,7 @@ import { NoopScopeManager } from '@opentelemetry/scope-base'; import { IgnoreMatcher } from '../../src/types'; import * as utils from '../../src/utils'; import * as http from 'http'; -import { Span, BasicTracer } from '@opentelemetry/tracing'; +import { Span, BasicTracerRegistry } from '@opentelemetry/tracing'; import { AttributeNames } from '../../src'; import { NoopLogger } from '@opentelemetry/core'; @@ -54,7 +54,7 @@ describe('Utility', () => { try { utils.hasExpectHeader('' as http.RequestOptions); assert.fail(); - } catch (ignore) {} + } catch (ignore) { } }); it('should not throw if no headers', () => { @@ -241,9 +241,9 @@ describe('Utility', () => { const errorMessage = 'test error'; for (const obj of [undefined, { statusCode: 400 }]) { const span = new Span( - new BasicTracer({ + new BasicTracerRegistry({ scopeManager: new NoopScopeManager(), - }), + }).getTracer(), 'test', { spanId: '', traceId: '' }, SpanKind.INTERNAL diff --git a/packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts b/packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts index 8712ca5898..d957a5bd2f 100644 --- a/packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts +++ b/packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts @@ -24,7 +24,7 @@ import { DummyPropagation } from '../utils/DummyPropagation'; import { httpRequest } from '../utils/httpRequest'; import * as url from 'url'; import * as utils from '../utils/utils'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { InMemorySpanExporter, SimpleSpanProcessor, @@ -59,11 +59,11 @@ describe('HttpPlugin Integration tests', () => { const httpTextFormat = new DummyPropagation(); const logger = new NoopLogger(); - const tracer = new NodeTracer({ + const registry = new NodeTracerRegistry({ logger, httpTextFormat, }); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); beforeEach(() => { memoryExporter.reset(); }); @@ -82,7 +82,7 @@ describe('HttpPlugin Integration tests', () => { try { plugin.disable(); } catch (e) {} - plugin.enable(http, tracer, tracer.logger, config); + plugin.enable(http, registry, registry.logger, config); }); after(() => { diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts index 049af1be4b..9b92387690 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; +import { NoopLogger, NoopTracerRegistry, noopTracer } from '@opentelemetry/core'; import { Http } from '@opentelemetry/plugin-http'; import * as assert from 'assert'; import * as fs from 'fs'; @@ -24,7 +23,6 @@ import { AddressInfo } from 'net'; import * as nock from 'nock'; import * as sinon from 'sinon'; import { plugin } from '../../src/https'; -import { DummyPropagation } from '../utils/DummyPropagation'; import { httpsRequest } from '../utils/httpsRequest'; describe('HttpsPlugin', () => { @@ -32,17 +30,13 @@ describe('HttpsPlugin', () => { let serverPort = 0; describe('disable()', () => { - const httpTextFormat = new DummyPropagation(); const logger = new NoopLogger(); - const tracer = new NodeTracer({ - logger, - httpTextFormat, - }); + const registry = new NoopTracerRegistry(); before(() => { nock.cleanAll(); nock.enableNetConnect(); - plugin.enable((https as unknown) as Http, tracer, tracer.logger); + plugin.enable((https as unknown) as Http, registry, logger); // Ensure that https module is patched. assert.strictEqual(https.Server.prototype.emit.__wrapped, true); server = https.createServer( @@ -62,8 +56,8 @@ describe('HttpsPlugin', () => { }); beforeEach(() => { - tracer.startSpan = sinon.spy(); - tracer.withSpan = sinon.spy(); + noopTracer.startSpan = sinon.spy(); + noopTracer.withSpan = sinon.spy(); }); afterEach(() => { @@ -74,7 +68,7 @@ describe('HttpsPlugin', () => { server.close(); }); describe('unpatch()', () => { - it('should not call tracer methods for creating span', async () => { + it('should not call registry methods for creating span', async () => { plugin.disable(); const testPath = '/incoming/unpatch/'; @@ -82,12 +76,12 @@ describe('HttpsPlugin', () => { await httpsRequest.get(options).then(result => { assert.strictEqual( - (tracer.startSpan as sinon.SinonSpy).called, + (noopTracer.startSpan as sinon.SinonSpy).called, false ); assert.strictEqual(https.Server.prototype.emit.__wrapped, undefined); - assert.strictEqual((tracer.withSpan as sinon.SinonSpy).called, false); + assert.strictEqual((noopTracer.withSpan as sinon.SinonSpy).called, false); }); }); }); diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts index cc449ddb4a..8cd908986b 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts @@ -19,7 +19,7 @@ import { SimpleSpanProcessor, } from '@opentelemetry/tracing'; import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { Http, HttpPluginConfig, @@ -77,11 +77,11 @@ describe('HttpsPlugin', () => { describe('enable()', () => { const httpTextFormat = new DummyPropagation(); const logger = new NoopLogger(); - const tracer = new NodeTracer({ + const registry = new NodeTracerRegistry({ logger, httpTextFormat, }); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); beforeEach(() => { memoryExporter.reset(); }); @@ -100,7 +100,7 @@ describe('HttpsPlugin', () => { ], applyCustomAttributesOnSpan: customAttributeFunction, }; - plugin.enable((https as unknown) as Http, tracer, tracer.logger, config); + plugin.enable((https as unknown) as Http, registry, registry.logger, config); server = https.createServer( { key: fs.readFileSync('test/fixtures/server-key.pem'), @@ -126,8 +126,8 @@ describe('HttpsPlugin', () => { it("should not patch if it's not a http module", () => { const httpNotPatched = new HttpsPlugin(process.versions.node).enable( {} as Http, - tracer, - tracer.logger, + registry, + registry.logger, {} ); assert.strictEqual(Object.keys(httpNotPatched).length, 0); @@ -213,8 +213,8 @@ describe('HttpsPlugin', () => { const testPath = '/outgoing/rootSpan/childs/1'; doNock(hostname, testPath, 200, 'Ok'); const name = 'TestRootSpan'; - const span = tracer.startSpan(name); - return tracer.withSpan(span, async () => { + const span = registry.getTracer().startSpan(name); + return registry.getTracer().withSpan(span, async () => { const result = await httpsRequest.get( `${protocol}://${hostname}${testPath}` ); @@ -256,8 +256,8 @@ describe('HttpsPlugin', () => { httpErrorCodes[i].toString() ); const name = 'TestRootSpan'; - const span = tracer.startSpan(name); - return tracer.withSpan(span, async () => { + const span = registry.getTracer().startSpan(name); + return registry.getTracer().withSpan(span, async () => { const result = await httpsRequest.get( `${protocol}://${hostname}${testPath}` ); @@ -295,8 +295,8 @@ describe('HttpsPlugin', () => { const num = 5; doNock(hostname, testPath, 200, 'Ok', num); const name = 'TestRootSpan'; - const span = tracer.startSpan(name); - await tracer.withSpan(span, async () => { + const span = registry.getTracer().startSpan(name); + await registry.getTracer().withSpan(span, async () => { for (let i = 0; i < num; i++) { await httpsRequest.get(`${protocol}://${hostname}${testPath}`); const spans = memoryExporter.getFinishedSpans(); diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-package.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-package.test.ts index 0604149ff4..d0f2d90c87 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-package.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-package.test.ts @@ -29,7 +29,7 @@ import * as superagent from 'superagent'; import * as got from 'got'; import * as request from 'request-promise-native'; import * as path from 'path'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { InMemorySpanExporter, SimpleSpanProcessor, @@ -47,17 +47,17 @@ describe('Packages', () => { const httpTextFormat = new DummyPropagation(); const logger = new NoopLogger(); - const tracer = new NodeTracer({ + const registry = new NodeTracerRegistry({ logger, httpTextFormat, }); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); beforeEach(() => { memoryExporter.reset(); }); before(() => { - plugin.enable((https as unknown) as Http, tracer, tracer.logger); + plugin.enable((https as unknown) as Http, registry, registry.logger); }); after(() => { diff --git a/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts index a3ad0e487f..1a27ed90b6 100644 --- a/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts @@ -19,7 +19,7 @@ import { SimpleSpanProcessor, } from '@opentelemetry/tracing'; import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { HttpPluginConfig, Http } from '@opentelemetry/plugin-http'; import { Span, SpanKind } from '@opentelemetry/types'; import * as assert from 'assert'; @@ -60,11 +60,11 @@ describe('HttpsPlugin Integration tests', () => { const httpTextFormat = new DummyPropagation(); const logger = new NoopLogger(); - const tracer = new NodeTracer({ + const registry = new NodeTracerRegistry({ logger, httpTextFormat, }); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); beforeEach(() => { memoryExporter.reset(); }); @@ -83,7 +83,7 @@ describe('HttpsPlugin Integration tests', () => { try { plugin.disable(); } catch (e) {} - plugin.enable((https as unknown) as Http, tracer, tracer.logger, config); + plugin.enable((https as unknown) as Http, registry, registry.logger, config); }); after(() => { diff --git a/packages/opentelemetry-plugin-mongodb-core/package.json b/packages/opentelemetry-plugin-mongodb-core/package.json index f54d725add..d3644718d3 100644 --- a/packages/opentelemetry-plugin-mongodb-core/package.json +++ b/packages/opentelemetry-plugin-mongodb-core/package.json @@ -40,8 +40,8 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/node": "^0.1.1", - "@opentelemetry/tracing": "^0.1.1", + "@opentelemetry/node": "^0.2.0", + "@opentelemetry/tracing": "^0.2.0", "@types/mocha": "^5.2.7", "@types/mongodb": "^3.2.3", "@types/node": "^12.7.2", diff --git a/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts b/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts index e3e179c7b2..4095190e63 100644 --- a/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts +++ b/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts @@ -40,7 +40,7 @@ export class MongoDBCorePlugin extends BasePlugin { readonly supportedVersions = ['>=2 <3']; constructor(readonly moduleName: string) { - super(); + super(`opentelemetry.${moduleName}`, "0.2.0"); } /** diff --git a/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts b/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts index b0f4ee15fc..c9572a414a 100644 --- a/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts +++ b/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import * as assert from 'assert'; import * as mongodb from 'mongodb'; import { plugin } from '../src'; @@ -104,12 +104,12 @@ describe('MongoDBPlugin', () => { let client: mongodb.MongoClient; let collection: mongodb.Collection; const logger = new NoopLogger(); - const tracer = new NodeTracer(); + const registry = new NodeTracerRegistry(); const memoryExporter = new InMemorySpanExporter(); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); before(done => { - plugin.enable(mongodb, tracer, logger); + plugin.enable(mongodb, registry, logger); accessCollection(URL, DB_NAME, COLLECTION_NAME) .then(result => { client = result.client; @@ -155,8 +155,8 @@ describe('MongoDBPlugin', () => { it('should create a child span for insert', done => { const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }]; - const span = tracer.startSpan(`insertRootSpan`); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan(`insertRootSpan`); + registry.getTracer().withSpan(span, () => { collection.insertMany(insertData, (err, result) => { span.end(); assert.ifError(err); @@ -171,8 +171,8 @@ describe('MongoDBPlugin', () => { }); it('should create a child span for update', done => { - const span = tracer.startSpan('updateRootSpan'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('updateRootSpan'); + registry.getTracer().withSpan(span, () => { collection.updateOne({ a: 2 }, { $set: { b: 1 } }, (err, result) => { span.end(); assert.ifError(err); @@ -187,8 +187,8 @@ describe('MongoDBPlugin', () => { }); it('should create a child span for remove', done => { - const span = tracer.startSpan('removeRootSpan'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('removeRootSpan'); + registry.getTracer().withSpan(span, () => { collection.deleteOne({ a: 3 }, (err, result) => { span.end(); assert.ifError(err); @@ -206,8 +206,8 @@ describe('MongoDBPlugin', () => { /** Should intercept cursor */ describe('Instrumenting cursor operations', () => { it('should create a child span for find', done => { - const span = tracer.startSpan('findRootSpan'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('findRootSpan'); + registry.getTracer().withSpan(span, () => { collection.find({}).toArray((err, result) => { span.end(); assert.ifError(err); @@ -225,8 +225,8 @@ describe('MongoDBPlugin', () => { /** Should intercept command */ describe('Instrumenting command operations', () => { it('should create a child span for create index', done => { - const span = tracer.startSpan('indexRootSpan'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('indexRootSpan'); + registry.getTracer().withSpan(span, () => { collection.createIndex({ a: 1 }, (err, result) => { span.end(); assert.ifError(err); @@ -252,7 +252,7 @@ describe('MongoDBPlugin', () => { it('should not create a child span for query', done => { const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }]; - const span = tracer.startSpan('insertRootSpan'); + const span = registry.getTracer().startSpan('insertRootSpan'); collection.insertMany(insertData, (err, result) => { span.end(); assert.ifError(err); @@ -262,7 +262,7 @@ describe('MongoDBPlugin', () => { }); it('should not create a child span for cursor', done => { - const span = tracer.startSpan('findRootSpan'); + const span = registry.getTracer().startSpan('findRootSpan'); collection.find({}).toArray((err, result) => { span.end(); assert.ifError(err); @@ -272,7 +272,7 @@ describe('MongoDBPlugin', () => { }); it('should not create a child span for command', done => { - const span = tracer.startSpan('indexRootSpan'); + const span = registry.getTracer().startSpan('indexRootSpan'); collection.createIndex({ a: 1 }, (err, result) => { span.end(); assert.ifError(err); diff --git a/packages/opentelemetry-plugin-mongodb-core/tsconfig.json b/packages/opentelemetry-plugin-mongodb-core/tsconfig.json index 3e83278f6c..a2042cd68b 100644 --- a/packages/opentelemetry-plugin-mongodb-core/tsconfig.json +++ b/packages/opentelemetry-plugin-mongodb-core/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "build" }, "include": [ - "src/**/*.ts" + "src/**/*.ts", + "test/**/*.ts" ] } diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts index a6841ae33a..46ca121a92 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts @@ -37,7 +37,7 @@ export class PostgresPlugin extends BasePlugin { readonly supportedVersions = ['7.*']; constructor(readonly moduleName: string) { - super(); + super(`opentelemetry.${moduleName}`, "0.2.0"); this._config = {}; } diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/test/pg.test.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/test/pg.test.ts index d30ad3a325..d9c45bffac 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/test/pg.test.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/test/pg.test.ts @@ -15,7 +15,7 @@ */ import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { InMemorySpanExporter, SimpleSpanProcessor, @@ -88,7 +88,8 @@ const runCallbackTest = ( describe('pg@7.x', () => { let client: pg.Client; - const tracer = new NodeTracer(); + const registry = new NodeTracerRegistry(); + const tracer = registry.getTracer("external"); const logger = new NoopLogger(); const testPostgres = process.env.RUN_POSTGRES_TESTS; // For CI: assumes local postgres db is already available const testPostgresLocally = process.env.RUN_POSTGRES_TESTS_LOCAL; // For local: spins up local postgres db via docker @@ -101,7 +102,7 @@ describe('pg@7.x', () => { this.test!.parent!.pending = true; this.skip(); } - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); if (testPostgresLocally) { testUtils.startDocker(); } @@ -122,7 +123,7 @@ describe('pg@7.x', () => { }); beforeEach(function() { - plugin.enable(pg, tracer, logger); + plugin.enable(pg, registry, logger); }); afterEach(() => { diff --git a/packages/opentelemetry-plugin-redis/src/redis.ts b/packages/opentelemetry-plugin-redis/src/redis.ts index 5d4cb833f8..80868cc2e2 100644 --- a/packages/opentelemetry-plugin-redis/src/redis.ts +++ b/packages/opentelemetry-plugin-redis/src/redis.ts @@ -28,7 +28,7 @@ export class RedisPlugin extends BasePlugin { readonly supportedVersions = ['^2.6.0']; // equivalent to >= 2.6.0 <3 constructor(readonly moduleName: string) { - super(); + super(`opentelemetry.${moduleName}`, "0.2.0"); } protected patch() { diff --git a/packages/opentelemetry-plugin-redis/test/redis.test.ts b/packages/opentelemetry-plugin-redis/test/redis.test.ts index 72d6730a69..d7c7713d62 100644 --- a/packages/opentelemetry-plugin-redis/test/redis.test.ts +++ b/packages/opentelemetry-plugin-redis/test/redis.test.ts @@ -19,7 +19,7 @@ import { InMemorySpanExporter, SimpleSpanProcessor, } from '@opentelemetry/tracing'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { plugin, RedisPlugin } from '../src'; import * as redisTypes from 'redis'; import { NoopLogger } from '@opentelemetry/core'; @@ -49,7 +49,8 @@ const okStatus: Status = { }; describe('redis@2.x', () => { - const tracer = new NodeTracer(); + const registry = new NodeTracerRegistry(); + const tracer = registry.getTracer("external"); let redis: typeof redisTypes; const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL; const shouldTest = process.env.RUN_REDIS_TESTS || shouldTestLocal; @@ -68,8 +69,8 @@ describe('redis@2.x', () => { } redis = require('redis'); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - plugin.enable(redis, tracer, new NoopLogger()); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + plugin.enable(redis, registry, new NoopLogger()); }); after(() => { diff --git a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts index bd2763247d..c583811ab7 100644 --- a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts +++ b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts @@ -16,14 +16,14 @@ import * as assert from 'assert'; import * as opentracing from 'opentracing'; -import { BasicTracer, Span } from '@opentelemetry/tracing'; +import { BasicTracerRegistry, Span } from '@opentelemetry/tracing'; import { TracerShim, SpanShim, SpanContextShim } from '../src/shim'; import { INVALID_SPAN_CONTEXT, timeInputToHrTime } from '@opentelemetry/core'; import { performance } from 'perf_hooks'; describe('OpenTracing Shim', () => { - const tracer = new BasicTracer(); - const shimTracer: opentracing.Tracer = new TracerShim(tracer); + const registry = new BasicTracerRegistry(); + const shimTracer: opentracing.Tracer = new TracerShim(registry.getTracer()); opentracing.initGlobalTracer(shimTracer); describe('TracerShim', () => { diff --git a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts new file mode 100644 index 0000000000..fc71b82634 --- /dev/null +++ b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts @@ -0,0 +1,64 @@ +/*! + * 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 { ConsoleLogger } from '@opentelemetry/core'; +import * as types from '@opentelemetry/types'; +import { Logger } from '@opentelemetry/types'; +import { SpanProcessor, Tracer } from '.'; +import { DEFAULT_CONFIG } from './config'; +import { MultiSpanProcessor } from './MultiSpanProcessor'; +import { NoopSpanProcessor } from './NoopSpanProcessor'; +import { TracerConfig } from './types'; + +export class BasicTracerRegistry implements types.TracerRegistry { + private readonly _registeredSpanProcessors: SpanProcessor[] = []; + private readonly _tracers: Map = new Map(); + + activeSpanProcessor = new NoopSpanProcessor(); + readonly logger: Logger; + + constructor(private _config: TracerConfig = DEFAULT_CONFIG) { + this.logger = _config.logger || new ConsoleLogger(_config.logLevel); + } + + getTracer( + name = 'DEFAULT_TRACER', + version = '*', + config?: TracerConfig + ): Tracer { + const key = `${name}@${version}`; + if (!this._tracers.has(key)) { + this._tracers.set(key, new Tracer(config || this._config, this)); + } + + return this._tracers.get(key)!; + } + + /** + * Adds a new {@link SpanProcessor} to this tracer. + * @param spanProcessor the new SpanProcessor to be added. + */ + addSpanProcessor(spanProcessor: SpanProcessor): void { + this._registeredSpanProcessors.push(spanProcessor); + this.activeSpanProcessor = new MultiSpanProcessor( + this._registeredSpanProcessors + ); + } + + getActiveSpanProcessor(): SpanProcessor { + return this.activeSpanProcessor; + } +} diff --git a/packages/opentelemetry-tracing/src/Span.ts b/packages/opentelemetry-tracing/src/Span.ts index 0fe7cfdbd2..64a94630e2 100644 --- a/packages/opentelemetry-tracing/src/Span.ts +++ b/packages/opentelemetry-tracing/src/Span.ts @@ -22,7 +22,7 @@ import { timeInputToHrTime, } from '@opentelemetry/core'; import { ReadableSpan } from './export/ReadableSpan'; -import { BasicTracer } from './BasicTracer'; +import { Tracer } from './Tracer'; import { SpanProcessor } from './SpanProcessor'; import { TraceParams } from './types'; @@ -52,7 +52,7 @@ export class Span implements types.Span, ReadableSpan { /** Constructs a new Span instance. */ constructor( - parentTracer: BasicTracer, + parentTracer: Tracer, spanName: string, spanContext: types.SpanContext, kind: types.SpanKind, @@ -68,7 +68,7 @@ export class Span implements types.Span, ReadableSpan { this.startTime = timeInputToHrTime(startTime); this._logger = parentTracer.logger; this._traceParams = parentTracer.getActiveTraceParams(); - this._spanProcessor = parentTracer.activeSpanProcessor; + this._spanProcessor = parentTracer.getActiveSpanProcessor(); this._spanProcessor.onStart(this); } diff --git a/packages/opentelemetry-tracing/src/BasicTracer.ts b/packages/opentelemetry-tracing/src/Tracer.ts similarity index 86% rename from packages/opentelemetry-tracing/src/BasicTracer.ts rename to packages/opentelemetry-tracing/src/Tracer.ts index 2e4b9b072d..9c5628244e 100644 --- a/packages/opentelemetry-tracing/src/BasicTracer.ts +++ b/packages/opentelemetry-tracing/src/Tracer.ts @@ -28,19 +28,17 @@ import { TraceFlags, Logger, } from '@opentelemetry/types'; -import { BasicTracerConfig, TraceParams } from './types'; +import { TracerConfig, TraceParams } from './types'; import { ScopeManager } from '@opentelemetry/scope-base'; import { Span } from './Span'; import { mergeConfig } from './utility'; -import { SpanProcessor } from './SpanProcessor'; -import { NoopSpanProcessor } from './NoopSpanProcessor'; -import { MultiSpanProcessor } from './MultiSpanProcessor'; import { DEFAULT_CONFIG } from './config'; +import { BasicTracerRegistry } from './BasicTracerRegistry'; /** * This class represents a basic tracer. */ -export class BasicTracer implements types.Tracer { +export class Tracer implements types.Tracer { private readonly _defaultAttributes: types.Attributes; private readonly _binaryFormat: types.BinaryFormat; private readonly _httpTextFormat: types.HttpTextFormat; @@ -48,13 +46,14 @@ export class BasicTracer implements types.Tracer { private readonly _scopeManager: ScopeManager; private readonly _traceParams: TraceParams; readonly logger: Logger; - private readonly _registeredSpanProcessor: SpanProcessor[] = []; - activeSpanProcessor = new NoopSpanProcessor(); /** * Constructs a new Tracer instance. */ - constructor(config: BasicTracerConfig = DEFAULT_CONFIG) { + constructor( + config: TracerConfig = DEFAULT_CONFIG, + private _tracerRegistry: BasicTracerRegistry + ) { const localConfig = mergeConfig(config); this._binaryFormat = localConfig.binaryFormat; this._defaultAttributes = localConfig.defaultAttributes; @@ -162,15 +161,8 @@ export class BasicTracer implements types.Tracer { return this._traceParams; } - /** - * Adds a new {@link SpanProcessor} to this tracer. - * @param spanProcessor the new SpanProcessor to be added. - */ - addSpanProcessor(spanProcessor: SpanProcessor): void { - this._registeredSpanProcessor.push(spanProcessor); - this.activeSpanProcessor = new MultiSpanProcessor( - this._registeredSpanProcessor - ); + getActiveSpanProcessor() { + return this._tracerRegistry.getActiveSpanProcessor(); } private _getParentSpanContext( diff --git a/packages/opentelemetry-tracing/src/index.ts b/packages/opentelemetry-tracing/src/index.ts index 55a68cbde6..d6fb9fb54b 100644 --- a/packages/opentelemetry-tracing/src/index.ts +++ b/packages/opentelemetry-tracing/src/index.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -export * from './BasicTracer'; +export * from './Tracer'; +export * from './BasicTracerRegistry'; export * from './export/ConsoleSpanExporter'; export * from './export/BatchSpanProcessor'; export * from './export/InMemorySpanExporter'; diff --git a/packages/opentelemetry-tracing/src/types.ts b/packages/opentelemetry-tracing/src/types.ts index ec2977372c..dd2be6b970 100644 --- a/packages/opentelemetry-tracing/src/types.ts +++ b/packages/opentelemetry-tracing/src/types.ts @@ -25,9 +25,9 @@ import { import { LogLevel } from '@opentelemetry/core'; /** - * BasicTracerConfig provides an interface for configuring a Basic Tracer. + * TracerConfig provides an interface for configuring a Basic Tracer. */ -export interface BasicTracerConfig { +export interface TracerConfig { /** * Binary formatter which can serialize/deserialize Spans. */ diff --git a/packages/opentelemetry-tracing/src/utility.ts b/packages/opentelemetry-tracing/src/utility.ts index 605bac8eb8..a417c6e74b 100644 --- a/packages/opentelemetry-tracing/src/utility.ts +++ b/packages/opentelemetry-tracing/src/utility.ts @@ -14,19 +14,19 @@ * limitations under the License. */ -import { BasicTracerConfig } from './types'; import { + DEFAULT_CONFIG, DEFAULT_MAX_ATTRIBUTES_PER_SPAN, DEFAULT_MAX_EVENTS_PER_SPAN, DEFAULT_MAX_LINKS_PER_SPAN, } from './config'; -import { DEFAULT_CONFIG } from './config'; +import { TracerConfig } from './types'; /** * Function to merge Default configuration (as specified in './config') with * user provided configurations. */ -export function mergeConfig(userConfig: BasicTracerConfig) { +export function mergeConfig(userConfig: TracerConfig) { const traceParams = userConfig.traceParams; const target = Object.assign({}, DEFAULT_CONFIG, userConfig); diff --git a/packages/opentelemetry-tracing/test/BasicTracer.test.ts b/packages/opentelemetry-tracing/test/BasicTracerRegistry.test.ts similarity index 82% rename from packages/opentelemetry-tracing/test/BasicTracer.test.ts rename to packages/opentelemetry-tracing/test/BasicTracerRegistry.test.ts index 44af7ba31e..c286ce720b 100644 --- a/packages/opentelemetry-tracing/test/BasicTracer.test.ts +++ b/packages/opentelemetry-tracing/test/BasicTracerRegistry.test.ts @@ -14,62 +14,62 @@ * limitations under the License. */ -import * as assert from 'assert'; import { ALWAYS_SAMPLER, BinaryTraceContext, HttpTraceContext, NEVER_SAMPLER, NoopLogger, - TraceState, NoRecordingSpan, + TraceState, } from '@opentelemetry/core'; -import { TraceFlags } from '@opentelemetry/types'; -import { BasicTracer, Span } from '../src'; import { NoopScopeManager, ScopeManager } from '@opentelemetry/scope-base'; +import { TraceFlags } from '@opentelemetry/types'; +import * as assert from 'assert'; +import { BasicTracerRegistry, Span } from '../src'; -describe('BasicTracer', () => { +describe('BasicTracerRegistry', () => { describe('constructor', () => { it('should construct an instance without any options', () => { - const tracer = new BasicTracer(); - assert.ok(tracer instanceof BasicTracer); + const registry = new BasicTracerRegistry(); + assert.ok(registry instanceof BasicTracerRegistry); }); it('should construct an instance with binary format', () => { - const tracer = new BasicTracer({ + const registry = new BasicTracerRegistry({ binaryFormat: new BinaryTraceContext(), }); - assert.ok(tracer instanceof BasicTracer); + assert.ok(registry instanceof BasicTracerRegistry); }); it('should construct an instance with http text format', () => { - const tracer = new BasicTracer({ + const registry = new BasicTracerRegistry({ httpTextFormat: new HttpTraceContext(), scopeManager: new NoopScopeManager(), }); - assert.ok(tracer instanceof BasicTracer); + assert.ok(registry instanceof BasicTracerRegistry); }); it('should construct an instance with logger', () => { - const tracer = new BasicTracer({ + const registry = new BasicTracerRegistry({ logger: new NoopLogger(), scopeManager: new NoopScopeManager(), }); - assert.ok(tracer instanceof BasicTracer); + assert.ok(registry instanceof BasicTracerRegistry); }); it('should construct an instance with sampler', () => { - const tracer = new BasicTracer({ + const registry = new BasicTracerRegistry({ scopeManager: new NoopScopeManager(), sampler: ALWAYS_SAMPLER, }); - assert.ok(tracer instanceof BasicTracer); + assert.ok(registry instanceof BasicTracerRegistry); }); it('should construct an instance with default trace params', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ scopeManager: new NoopScopeManager(), - }); + }).getTracer(); assert.deepStrictEqual(tracer.getActiveTraceParams(), { numberOfAttributesPerSpan: 32, numberOfEventsPerSpan: 128, @@ -78,12 +78,12 @@ describe('BasicTracer', () => { }); it('should construct an instance with customized numberOfAttributesPerSpan trace params', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ scopeManager: new NoopScopeManager(), traceParams: { numberOfAttributesPerSpan: 100, }, - }); + }).getTracer(); assert.deepStrictEqual(tracer.getActiveTraceParams(), { numberOfAttributesPerSpan: 100, numberOfEventsPerSpan: 128, @@ -92,12 +92,12 @@ describe('BasicTracer', () => { }); it('should construct an instance with customized numberOfEventsPerSpan trace params', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ scopeManager: new NoopScopeManager(), traceParams: { numberOfEventsPerSpan: 300, }, - }); + }).getTracer(); assert.deepStrictEqual(tracer.getActiveTraceParams(), { numberOfAttributesPerSpan: 32, numberOfEventsPerSpan: 300, @@ -106,12 +106,12 @@ describe('BasicTracer', () => { }); it('should construct an instance with customized numberOfLinksPerSpan trace params', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ scopeManager: new NoopScopeManager(), traceParams: { numberOfLinksPerSpan: 10, }, - }); + }).getTracer(); assert.deepStrictEqual(tracer.getActiveTraceParams(), { numberOfAttributesPerSpan: 32, numberOfEventsPerSpan: 128, @@ -120,26 +120,26 @@ describe('BasicTracer', () => { }); it('should construct an instance with default attributes', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ defaultAttributes: { region: 'eu-west', asg: 'my-asg', }, }); - assert.ok(tracer instanceof BasicTracer); + assert.ok(tracer instanceof BasicTracerRegistry); }); }); describe('.startSpan()', () => { it('should start a span with name only', () => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); const span = tracer.startSpan('my-span'); assert.ok(span); assert.ok(span instanceof Span); }); it('should start a span with name and options', () => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); const span = tracer.startSpan('my-span', {}); assert.ok(span); assert.ok(span instanceof Span); @@ -152,9 +152,9 @@ describe('BasicTracer', () => { }); it('should start a span with defaultAttributes and spanoptions->attributes', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ defaultAttributes: { foo: 'bar' }, - }); + }).getTracer(); const span = tracer.startSpan('my-span', { attributes: { foo: 'foo', bar: 'bar' }, }) as Span; @@ -163,16 +163,16 @@ describe('BasicTracer', () => { }); it('should start a span with defaultAttributes and undefined spanoptions->attributes', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ defaultAttributes: { foo: 'bar' }, - }); + }).getTracer(); const span = tracer.startSpan('my-span', {}) as Span; assert.deepStrictEqual(span.attributes, { foo: 'bar' }); span.end(); }); it('should start a span with spanoptions->attributes', () => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); const span = tracer.startSpan('my-span', { attributes: { foo: 'foo', bar: 'bar' }, }) as Span; @@ -181,7 +181,7 @@ describe('BasicTracer', () => { }); it('should start a span with name and parent spancontext', () => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); const state = new TraceState('a=1,b=2'); const span = tracer.startSpan('my-span', { parent: { @@ -199,7 +199,7 @@ describe('BasicTracer', () => { }); it('should start a span with name and parent span', () => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); const span = tracer.startSpan('my-span'); const childSpan = tracer.startSpan('child-span', { parent: span, @@ -212,7 +212,7 @@ describe('BasicTracer', () => { }); it('should start a span with name and with invalid parent span', () => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); const span = tracer.startSpan('my-span', { parent: ('invalid-parent' as unknown) as undefined, }) as Span; @@ -220,7 +220,7 @@ describe('BasicTracer', () => { }); it('should start a span with name and with invalid spancontext', () => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); const span = tracer.startSpan('my-span', { parent: { traceId: '0', spanId: '0' }, }); @@ -233,10 +233,10 @@ describe('BasicTracer', () => { }); it('should return a no recording span when never sampling', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ sampler: NEVER_SAMPLER, logger: new NoopLogger(), - }); + }).getTracer(); const span = tracer.startSpan('my-span'); assert.ok(span instanceof NoRecordingSpan); const context = span.context(); @@ -248,9 +248,9 @@ describe('BasicTracer', () => { }); it('should create real span when not sampled but recording events true', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ sampler: NEVER_SAMPLER, - }); + }).getTracer(); const span = tracer.startSpan('my-span', { isRecording: true }); assert.ok(span instanceof Span); assert.strictEqual(span.context().traceFlags, TraceFlags.UNSAMPLED); @@ -258,10 +258,10 @@ describe('BasicTracer', () => { }); it('should not create real span when not sampled and recording events false', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ sampler: NEVER_SAMPLER, logger: new NoopLogger(), - }); + }).getTracer(); const span = tracer.startSpan('my-span', { isRecording: false }); assert.ok(span instanceof NoRecordingSpan); assert.strictEqual(span.context().traceFlags, TraceFlags.UNSAMPLED); @@ -269,10 +269,10 @@ describe('BasicTracer', () => { }); it('should not create real span when not sampled and no recording events configured', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ sampler: NEVER_SAMPLER, logger: new NoopLogger(), - }); + }).getTracer(); const span = tracer.startSpan('my-span'); assert.ok(span instanceof NoRecordingSpan); assert.strictEqual(span.context().traceFlags, TraceFlags.UNSAMPLED); @@ -280,10 +280,10 @@ describe('BasicTracer', () => { }); it('should create real span when sampled and recording events true', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ sampler: ALWAYS_SAMPLER, scopeManager: new NoopScopeManager(), - }); + }).getTracer(); const span = tracer.startSpan('my-span', { isRecording: true }); assert.ok(span instanceof Span); assert.strictEqual(span.context().traceFlags, TraceFlags.SAMPLED); @@ -294,10 +294,10 @@ describe('BasicTracer', () => { const defaultAttributes = { foo: 'bar', }; - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ scopeManager: new NoopScopeManager(), defaultAttributes, - }); + }).getTracer(); const span = tracer.startSpan('my-span') as Span; assert.ok(span instanceof Span); @@ -307,24 +307,24 @@ describe('BasicTracer', () => { describe('.getCurrentSpan()', () => { it('should return null with NoopScopeManager', () => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); const currentSpan = tracer.getCurrentSpan(); assert.deepStrictEqual(currentSpan, null); }); it('should return current span when it exists', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ scopeManager: { active: () => 'foo', } as ScopeManager, - }); + }).getTracer(); assert.deepStrictEqual(tracer.getCurrentSpan(), 'foo'); }); }); describe('.withSpan()', () => { it('should run scope with NoopScopeManager scope manager', done => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); const span = tracer.startSpan('my-span'); tracer.withSpan(span, () => { assert.deepStrictEqual(tracer.getCurrentSpan(), null); @@ -335,7 +335,7 @@ describe('BasicTracer', () => { describe('.bind()', () => { it('should bind scope with NoopScopeManager scope manager', done => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); const span = tracer.startSpan('my-span'); const fn = () => { assert.deepStrictEqual(tracer.getCurrentSpan(), null); @@ -348,14 +348,14 @@ describe('BasicTracer', () => { describe('.getBinaryFormat()', () => { it('should get default binary formatter', () => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); assert.ok(tracer.getBinaryFormat() instanceof BinaryTraceContext); }); }); describe('.getHttpTextFormat()', () => { it('should get default HTTP text formatter', () => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); assert.ok(tracer.getHttpTextFormat() instanceof HttpTraceContext); }); }); diff --git a/packages/opentelemetry-tracing/test/MultiSpanProcessor.test.ts b/packages/opentelemetry-tracing/test/MultiSpanProcessor.test.ts index 756dbfa734..7a18edfe9e 100644 --- a/packages/opentelemetry-tracing/test/MultiSpanProcessor.test.ts +++ b/packages/opentelemetry-tracing/test/MultiSpanProcessor.test.ts @@ -16,7 +16,7 @@ import * as assert from 'assert'; import { MultiSpanProcessor } from '../src/MultiSpanProcessor'; -import { SpanProcessor, Span, BasicTracer } from '../src'; +import { SpanProcessor, Span, BasicTracerRegistry } from '../src'; class TestProcessor implements SpanProcessor { spans: Span[] = []; @@ -30,7 +30,7 @@ class TestProcessor implements SpanProcessor { } describe('MultiSpanProcessor', () => { - const tracer = new BasicTracer(); + const tracer = new BasicTracerRegistry().getTracer(); const span = tracer.startSpan('one'); it('should handle empty span processor', () => { diff --git a/packages/opentelemetry-tracing/test/Span.test.ts b/packages/opentelemetry-tracing/test/Span.test.ts index 9de4129dc1..9e9c4989fb 100644 --- a/packages/opentelemetry-tracing/test/Span.test.ts +++ b/packages/opentelemetry-tracing/test/Span.test.ts @@ -21,7 +21,7 @@ import { TraceFlags, SpanContext, } from '@opentelemetry/types'; -import { BasicTracer, Span } from '../src'; +import { BasicTracerRegistry, Span } from '../src'; import { hrTime, hrTimeToNanoseconds, @@ -33,9 +33,9 @@ import { const performanceTimeOrigin = hrTime(); describe('Span', () => { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ logger: new NoopLogger(), - }); + }).getTracer(); const name = 'span1'; const spanContext: SpanContext = { traceId: 'd4cda95b652f4a1592b449d5929fda1b', diff --git a/packages/opentelemetry-tracing/test/export/BatchSpanProcessor.test.ts b/packages/opentelemetry-tracing/test/export/BatchSpanProcessor.test.ts index 04805a0a2d..d3a232de19 100644 --- a/packages/opentelemetry-tracing/test/export/BatchSpanProcessor.test.ts +++ b/packages/opentelemetry-tracing/test/export/BatchSpanProcessor.test.ts @@ -18,26 +18,26 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; import { Span, - BasicTracer, + BasicTracerRegistry, InMemorySpanExporter, BatchSpanProcessor, } from '../../src'; import { NEVER_SAMPLER, ALWAYS_SAMPLER, NoopLogger } from '@opentelemetry/core'; function createSampledSpan(spanName: string): Span { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ sampler: ALWAYS_SAMPLER, - }); + }).getTracer(); const span = tracer.startSpan(spanName); span.end(); return span as Span; } function createUnSampledSpan(spanName: string): Span { - const tracer = new BasicTracer({ + const tracer = new BasicTracerRegistry({ sampler: NEVER_SAMPLER, logger: new NoopLogger(), - }); + }).getTracer(); const span = tracer.startSpan(spanName, { isRecording: false }); span.end(); return span as Span; diff --git a/packages/opentelemetry-tracing/test/export/ConsoleSpanExporter.test.ts b/packages/opentelemetry-tracing/test/export/ConsoleSpanExporter.test.ts index 95691ea0e0..0bd92c316b 100644 --- a/packages/opentelemetry-tracing/test/export/ConsoleSpanExporter.test.ts +++ b/packages/opentelemetry-tracing/test/export/ConsoleSpanExporter.test.ts @@ -17,7 +17,7 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; import { - BasicTracer, + BasicTracerRegistry, ConsoleSpanExporter, SimpleSpanProcessor, } from '../../src'; @@ -39,15 +39,17 @@ describe('ConsoleSpanExporter', () => { describe('.export()', () => { it('should export information about span', () => { assert.doesNotThrow(() => { - const basicTracer = new BasicTracer(); + const basicTracerRegistry = new BasicTracerRegistry(); consoleExporter = new ConsoleSpanExporter(); const spyConsole = sinon.spy(console, 'log'); const spyExport = sinon.spy(consoleExporter, 'export'); - basicTracer.addSpanProcessor(new SimpleSpanProcessor(consoleExporter)); + basicTracerRegistry.addSpanProcessor( + new SimpleSpanProcessor(consoleExporter) + ); - const span = basicTracer.startSpan('foo'); + const span = basicTracerRegistry.getTracer().startSpan('foo'); span.addEvent('foobar'); span.end(); diff --git a/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts b/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts index 2de250a515..c04da65db6 100644 --- a/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts +++ b/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts @@ -18,14 +18,14 @@ import * as assert from 'assert'; import { InMemorySpanExporter, SimpleSpanProcessor, - BasicTracer, + BasicTracerRegistry, } from '../../src'; import { ExportResult } from '@opentelemetry/base'; describe('InMemorySpanExporter', () => { const memoryExporter = new InMemorySpanExporter(); - const tracer = new BasicTracer(); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + const registry = new BasicTracerRegistry(); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); afterEach(() => { // reset spans in memory. @@ -33,9 +33,11 @@ describe('InMemorySpanExporter', () => { }); it('should get finished spans', () => { - const root = tracer.startSpan('root'); - const child = tracer.startSpan('child', { parent: root }); - const grandChild = tracer.startSpan('grand-child', { parent: child }); + const root = registry.getTracer().startSpan('root'); + const child = registry.getTracer().startSpan('child', { parent: root }); + const grandChild = registry + .getTracer() + .startSpan('grand-child', { parent: child }); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); grandChild.end(); @@ -56,15 +58,21 @@ describe('InMemorySpanExporter', () => { }); it('should shutdown the exorter', () => { - const root = tracer.startSpan('root'); - tracer.startSpan('child', { parent: root }).end(); + const root = registry.getTracer().startSpan('root'); + registry + .getTracer() + .startSpan('child', { parent: root }) + .end(); root.end(); assert.strictEqual(memoryExporter.getFinishedSpans().length, 2); memoryExporter.shutdown(); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); // after shutdown no new spans are accepted - tracer.startSpan('child1', { parent: root }).end(); + registry + .getTracer() + .startSpan('child1', { parent: root }) + .end(); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); }); diff --git a/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts b/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts index 18742a729e..05824f099e 100644 --- a/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts +++ b/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts @@ -17,14 +17,14 @@ import * as assert from 'assert'; import { Span, - BasicTracer, + BasicTracerRegistry, InMemorySpanExporter, SimpleSpanProcessor, } from '../../src'; import { SpanContext, SpanKind, TraceFlags } from '@opentelemetry/types'; describe('SimpleSpanProcessor', () => { - const tracer = new BasicTracer(); + const registry = new BasicTracerRegistry(); const exporter = new InMemorySpanExporter(); describe('constructor', () => { @@ -42,7 +42,7 @@ describe('SimpleSpanProcessor', () => { spanId: '5e0c63257de34c92', traceFlags: TraceFlags.SAMPLED, }; - const span = new Span(tracer, 'span-name', spanContext, SpanKind.CLIENT); + const span = new Span(registry.getTracer(), 'span-name', spanContext, SpanKind.CLIENT); processor.onStart(span); assert.strictEqual(exporter.getFinishedSpans().length, 0); @@ -60,7 +60,7 @@ describe('SimpleSpanProcessor', () => { spanId: '5e0c63257de34c92', traceFlags: TraceFlags.UNSAMPLED, }; - const span = new Span(tracer, 'span-name', spanContext, SpanKind.CLIENT); + const span = new Span(registry.getTracer(), 'span-name', spanContext, SpanKind.CLIENT); processor.onStart(span); assert.strictEqual(exporter.getFinishedSpans().length, 0); diff --git a/packages/opentelemetry-types/src/index.ts b/packages/opentelemetry-types/src/index.ts index 6e90dd1690..1308939419 100644 --- a/packages/opentelemetry-types/src/index.ts +++ b/packages/opentelemetry-types/src/index.ts @@ -35,5 +35,6 @@ export * from './trace/span_kind'; export * from './trace/status'; export * from './trace/TimedEvent'; export * from './trace/tracer'; +export * from './trace/tracer_registry'; export * from './trace/trace_flags'; export * from './trace/trace_state'; diff --git a/packages/opentelemetry-types/src/trace/instrumentation/Plugin.ts b/packages/opentelemetry-types/src/trace/instrumentation/Plugin.ts index efc63f8edf..3462a5df09 100644 --- a/packages/opentelemetry-types/src/trace/instrumentation/Plugin.ts +++ b/packages/opentelemetry-types/src/trace/instrumentation/Plugin.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { Tracer } from '../tracer'; import { Logger } from '../../common/Logger'; +import { TracerRegistry } from '../tracer_registry'; /** Interface Plugin to apply patch. */ // tslint:disable-next-line:no-any @@ -32,13 +32,13 @@ export interface Plugin { * Method that enables the instrumentation patch. * @param moduleExports The value of the `module.exports` property that would * normally be exposed by the required module. ex: `http`, `https` etc. - * @param tracer a tracer instance. + * @param TracerRegistry a tracer registry. * @param logger a logger instance. * @param [config] an object to configure the plugin. */ enable( moduleExports: T, - tracer: Tracer, + TracerRegistry: TracerRegistry, logger: Logger, config?: PluginConfig ): T; diff --git a/packages/opentelemetry-types/src/trace/tracer_registry.ts b/packages/opentelemetry-types/src/trace/tracer_registry.ts new file mode 100644 index 0000000000..ecd87d148b --- /dev/null +++ b/packages/opentelemetry-types/src/trace/tracer_registry.ts @@ -0,0 +1,31 @@ +/*! + * 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 { Tracer } from './tracer'; + +/** + * TracerRegistry provides an interface for creating {@link Tracer}s + */ +export interface TracerRegistry { + /** + * Returns a Tracer, creating one if one with the given name and version is not already created + * + * If there is no Span associated with the current context, null is returned. + * + * @returns Tracer A Tracer with the given name and version + */ + getTracer(name?: string, version?: string): Tracer; +} diff --git a/packages/opentelemetry-web/src/WebTracer.ts b/packages/opentelemetry-web/src/WebTracerRegistry.ts similarity index 88% rename from packages/opentelemetry-web/src/WebTracer.ts rename to packages/opentelemetry-web/src/WebTracerRegistry.ts index 5d3fad465e..d5fad66b72 100644 --- a/packages/opentelemetry-web/src/WebTracer.ts +++ b/packages/opentelemetry-web/src/WebTracerRegistry.ts @@ -15,13 +15,13 @@ */ import { BasePlugin } from '@opentelemetry/core'; -import { BasicTracer, BasicTracerConfig } from '@opentelemetry/tracing'; +import { BasicTracerRegistry, TracerConfig } from '@opentelemetry/tracing'; import { StackScopeManager } from './StackScopeManager'; /** * WebTracerConfig provides an interface for configuring a Web Tracer. */ -export interface WebTracerConfig extends BasicTracerConfig { +export interface WebTracerConfig extends TracerConfig { /** * plugins to be used with tracer, they will be enabled automatically */ @@ -31,7 +31,7 @@ export interface WebTracerConfig extends BasicTracerConfig { /** * This class represents a web tracer with {@link StackScopeManager} */ -export class WebTracer extends BasicTracer { +export class WebTracerRegistry extends BasicTracerRegistry { /** * Constructs a new Tracer instance. * @param config Web Tracer config diff --git a/packages/opentelemetry-web/src/index.ts b/packages/opentelemetry-web/src/index.ts index 4b652e2a56..6ec2d0779b 100644 --- a/packages/opentelemetry-web/src/index.ts +++ b/packages/opentelemetry-web/src/index.ts @@ -14,5 +14,5 @@ * limitations under the License. */ -export * from './WebTracer'; +export * from './WebTracerRegistry'; export * from './StackScopeManager'; diff --git a/packages/opentelemetry-web/test/WebTracer.test.ts b/packages/opentelemetry-web/test/WebTracer.test.ts index 5aa3a5a859..783c47feb3 100644 --- a/packages/opentelemetry-web/test/WebTracer.test.ts +++ b/packages/opentelemetry-web/test/WebTracer.test.ts @@ -15,22 +15,23 @@ */ import { BasePlugin } from '@opentelemetry/core'; +import { ZoneScopeManager } from '@opentelemetry/scope-zone'; +import { Tracer, TracerConfig } from '@opentelemetry/tracing'; import * as assert from 'assert'; import * as sinon from 'sinon'; -import { BasicTracerConfig } from '@opentelemetry/tracing'; import { WebTracerConfig } from '../src'; import { StackScopeManager } from '../src/StackScopeManager'; -import { WebTracer } from '../src/WebTracer'; -import { ZoneScopeManager } from '@opentelemetry/scope-zone'; +import { WebTracerRegistry } from '../src/WebTracerRegistry'; class DummyPlugin extends BasePlugin { + constructor() { + super("dummy"); + } patch() {} - unpatch() {} } describe('WebTracer', () => { - let tracer: WebTracer; describe('constructor', () => { let defaultOptions: WebTracerConfig; @@ -41,17 +42,17 @@ describe('WebTracer', () => { }); it('should construct an instance with required only options', () => { - tracer = new WebTracer(Object.assign({}, defaultOptions)); - assert.ok(tracer instanceof WebTracer); + const tracer = new WebTracerRegistry(Object.assign({}, defaultOptions)).getTracer(); + assert.ok(tracer instanceof Tracer); }); it('should enable the scope manager', () => { - let options: BasicTracerConfig; + let options: TracerConfig; const scopeManager = new StackScopeManager(); options = { scopeManager }; const spy = sinon.spy(scopeManager, 'enable'); - tracer = new WebTracer(options); + new WebTracerRegistry(options); assert.ok(spy.calledOnce === true); }); @@ -68,7 +69,7 @@ describe('WebTracer', () => { const plugins = [dummyPlugin1, dummyPlugin2]; options = { plugins, scopeManager }; - tracer = new WebTracer(options); + new WebTracerRegistry(options); assert.ok(spyEnable1.calledOnce === true); assert.ok(spyEnable2.calledOnce === true); @@ -76,15 +77,15 @@ describe('WebTracer', () => { it('should work without default scope manager', () => { assert.doesNotThrow(() => { - tracer = new WebTracer({}); + new WebTracerRegistry({}); }); }); describe('when scopeManager is "ZoneScopeManager"', () => { it('should correctly return the scopes for 2 parallel actions', () => { - const webTracerWithZone = new WebTracer({ + const webTracerWithZone = new WebTracerRegistry({ scopeManager: new ZoneScopeManager(), - }); + }).getTracer(); const rootSpan = webTracerWithZone.startSpan('rootSpan'); From 50927cd530b39a2a52f21caf930bea3c06334b5d Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 2 Dec 2019 13:59:36 -0500 Subject: [PATCH 02/24] chore: mysql/mongo tracer registry support --- .../src/mongodb.ts | 6 +- .../test/mongodb.test.ts | 9 +- .../opentelemetry-plugin-mysql/src/mysql.ts | 7 +- .../test/mysql.test.ts | 104 +++++++++--------- 4 files changed, 67 insertions(+), 59 deletions(-) diff --git a/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts b/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts index 94f77e23c3..d6c0635df9 100644 --- a/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts +++ b/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts @@ -40,7 +40,7 @@ export class MongoDBCorePlugin extends BasePlugin { readonly supportedVersions = ['>=2 <3']; constructor(readonly moduleName: string) { - super(`opentelemetry.${moduleName}`, "0.2.0"); + super(`opentelemetry.${moduleName}`, '0.2.0'); } /** @@ -106,7 +106,7 @@ export class MongoDBCorePlugin extends BasePlugin { const resultHandler = typeof options === 'function' ? options : callback; if ( - currentSpan === null || + !currentSpan || typeof resultHandler !== 'function' || typeof commands !== 'object' ) { @@ -208,7 +208,7 @@ export class MongoDBCorePlugin extends BasePlugin { ): mongodb.Cursor { const currentSpan = plugin._tracer.getCurrentSpan(); const resultHandler = args[0]; - if (currentSpan === null || typeof resultHandler !== 'function') { + if (!currentSpan || typeof resultHandler !== 'function') { return original.apply(this, args); } const span = plugin._tracer.startSpan(`mongodb.query`, { diff --git a/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts b/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts index c9572a414a..f7d9df901a 100644 --- a/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts +++ b/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts @@ -65,8 +65,12 @@ function accessCollection( function assertSpans( spans: ReadableSpan[], expectedName: string, - expectedKind: SpanKind + expectedKind: SpanKind, + log = false ) { + if (log) { + console.log(spans); + } assert.strictEqual(spans.length, 2); spans.forEach(span => { assert(span.endTime instanceof Array); @@ -106,7 +110,8 @@ describe('MongoDBPlugin', () => { const logger = new NoopLogger(); const registry = new NodeTracerRegistry(); const memoryExporter = new InMemorySpanExporter(); - registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + const spanProcessor = new SimpleSpanProcessor(memoryExporter); + registry.addSpanProcessor(spanProcessor); before(done => { plugin.enable(mongodb, registry, logger); diff --git a/packages/opentelemetry-plugin-mysql/src/mysql.ts b/packages/opentelemetry-plugin-mysql/src/mysql.ts index 3255a57c2b..fb5834027b 100644 --- a/packages/opentelemetry-plugin-mysql/src/mysql.ts +++ b/packages/opentelemetry-plugin-mysql/src/mysql.ts @@ -22,7 +22,6 @@ import { AttributeNames } from './enums'; import { getConnectionAttributes, getSpanName } from './utils'; export class MysqlPlugin extends BasePlugin { - readonly moduleName = 'mysql'; readonly supportedVersions = ['2.*']; static readonly COMPONENT = 'mysql'; @@ -36,6 +35,10 @@ export class MysqlPlugin extends BasePlugin { private _enabled = false; + constructor(readonly moduleName: string) { + super(`opentelemetry.${moduleName}`, '0.2.0'); + } + protected patch(): typeof mysqlTypes { this._enabled = true; shimmer.wrap( @@ -283,4 +286,4 @@ export class MysqlPlugin extends BasePlugin { } } -export const plugin = new MysqlPlugin(); +export const plugin = new MysqlPlugin(MysqlPlugin.COMPONENT); diff --git a/packages/opentelemetry-plugin-mysql/test/mysql.test.ts b/packages/opentelemetry-plugin-mysql/test/mysql.test.ts index 600b3aa9b3..75e35b196b 100644 --- a/packages/opentelemetry-plugin-mysql/test/mysql.test.ts +++ b/packages/opentelemetry-plugin-mysql/test/mysql.test.ts @@ -15,7 +15,7 @@ */ import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { InMemorySpanExporter, SimpleSpanProcessor, @@ -38,7 +38,7 @@ describe('mysql@2.x', () => { let connection: mysql.Connection; let pool: mysql.Pool; let poolCluster: mysql.PoolCluster; - const tracer = new NodeTracer({ plugins: {} }); + const registry = new NodeTracerRegistry({ plugins: {} }); const logger = new NoopLogger(); const testMysql = process.env.RUN_MYSQL_TESTS; // For CI: assumes local mysql db is already available const testMysqlLocally = process.env.RUN_MYSQL_TESTS_LOCAL; // For local: spins up local mysql db via docker @@ -52,7 +52,7 @@ describe('mysql@2.x', () => { this.test!.parent!.pending = true; this.skip(); } - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); if (testMysqlLocally) { testUtils.startDocker(); // wait 15 seconds for docker container to start @@ -71,7 +71,7 @@ describe('mysql@2.x', () => { }); beforeEach(function() { - plugin.enable(mysql, tracer, logger); + plugin.enable(mysql, registry, logger); connection = mysql.createConnection({ port, user, @@ -118,8 +118,8 @@ describe('mysql@2.x', () => { describe('#Connection', () => { it('should intercept connection.query(text: string)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; const query = connection.query(statement); let rows = 0; @@ -140,8 +140,8 @@ describe('mysql@2.x', () => { }); it('should intercept connection.query(text: string, callback)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; connection.query(statement, (err, res) => { assert.ifError(err); @@ -156,8 +156,8 @@ describe('mysql@2.x', () => { }); it('should intercept connection.query(text: options, callback)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+? as solution'; connection.query({ sql: statement, values: [1] }, (err, res) => { assert.ifError(err); @@ -172,8 +172,8 @@ describe('mysql@2.x', () => { }); it('should intercept connection.query(text: options, values: [], callback)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+? as solution'; // @ts-ignore this is documented https://github.com/mysqljs/mysql#performing-queries // but does not match the typings @@ -190,8 +190,8 @@ describe('mysql@2.x', () => { }); it('should intercept connection.query(text: string, values: [], callback)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT ? as solution'; connection.query(statement, [1], (err, res) => { assert.ifError(err); @@ -206,8 +206,8 @@ describe('mysql@2.x', () => { }); it('should intercept connection.query(text: string, value: any, callback)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT ? as solution'; connection.query(statement, 1, (err, res) => { assert.ifError(err); @@ -222,8 +222,8 @@ describe('mysql@2.x', () => { }); it('should attach error messages to spans', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT ? as solution'; connection.query(statement, (err, res) => { assert.ok(err); @@ -238,8 +238,8 @@ describe('mysql@2.x', () => { describe('#Pool', () => { it('should intercept pool.query(text: string)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; const query = pool.query(statement); let rows = 0; @@ -260,8 +260,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.getConnection().query(text: string)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; pool.getConnection((err, conn) => { const query = conn.query(statement); @@ -284,8 +284,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.query(text: string, callback)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; pool.query(statement, (err, res) => { assert.ifError(err); @@ -300,8 +300,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.getConnection().query(text: string, callback)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; pool.getConnection((err, conn) => { conn.query(statement, (err, res) => { @@ -318,8 +318,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.query(text: options, callback)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+? as solution'; pool.query({ sql: statement, values: [1] }, (err, res) => { assert.ifError(err); @@ -334,8 +334,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.query(text: options, values: [], callback)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+? as solution'; // @ts-ignore this is documented https://github.com/mysqljs/mysql#performing-queries // but does not match the typings @@ -352,8 +352,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.query(text: string, values: [], callback)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT ? as solution'; pool.query(statement, [1], (err, res) => { assert.ifError(err); @@ -368,8 +368,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.query(text: string, value: any, callback)', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT ? as solution'; pool.query(statement, 1, (err, res) => { assert.ifError(err); @@ -384,8 +384,8 @@ describe('mysql@2.x', () => { }); it('should attach error messages to spans', done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT ? as solution'; pool.query(statement, (err, res) => { assert.ok(err); @@ -402,8 +402,8 @@ describe('mysql@2.x', () => { it('should intercept poolClusterConnection.query(text: string)', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; const query = poolClusterConnection.query(statement); let rows = 0; @@ -427,8 +427,8 @@ describe('mysql@2.x', () => { it('should intercept poolClusterConnection.query(text: string, callback)', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; poolClusterConnection.query(statement, (err, res) => { assert.ifError(err); @@ -446,8 +446,8 @@ describe('mysql@2.x', () => { it('should intercept poolClusterConnection.query(text: options, callback)', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+? as solution'; poolClusterConnection.query( { sql: statement, values: [1] }, @@ -468,8 +468,8 @@ describe('mysql@2.x', () => { it('should intercept poolClusterConnection.query(text: options, values: [], callback)', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1+? as solution'; // @ts-ignore this is documented https://github.com/mysqljs/mysql#performing-queries // but does not match the typings @@ -489,8 +489,8 @@ describe('mysql@2.x', () => { it('should intercept poolClusterConnection.query(text: string, values: [], callback)', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT ? as solution'; poolClusterConnection.query(statement, [1], (err, res) => { assert.ifError(err); @@ -508,8 +508,8 @@ describe('mysql@2.x', () => { it('should intercept poolClusterConnection.query(text: string, value: any, callback)', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT ? as solution'; poolClusterConnection.query(statement, 1, (err, res) => { assert.ifError(err); @@ -527,8 +527,8 @@ describe('mysql@2.x', () => { it('should attach error messages to spans', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT ? as solution'; poolClusterConnection.query(statement, (err, res) => { assert.ok(err); @@ -544,8 +544,8 @@ describe('mysql@2.x', () => { it('should get connection by name', done => { poolCluster.getConnection('name', (err, poolClusterConnection) => { assert.ifError(err); - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer().startSpan('test span'); + registry.getTracer().withSpan(span, () => { const statement = 'SELECT 1 as solution'; poolClusterConnection.query(statement, (err, res) => { assert.ifError(err); From c6861178898fa64b2ee5aa9704afe835b0fa971d Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 2 Dec 2019 14:00:34 -0500 Subject: [PATCH 03/24] fix: lint --- .../src/trace/globaltracer-utils.ts | 4 +++- .../src/trace/instrumentation/BasePlugin.ts | 11 ++++++++--- .../test/trace/BasePlugin.test.ts | 2 +- .../test/trace/globaltracer-utils.test.ts | 2 +- packages/opentelemetry-node/src/index.ts | 2 +- .../src/instrumentation/PluginLoader.ts | 7 ++++++- .../opentelemetry-node/test/NodeTracer.test.ts | 12 +++++++++--- .../test/instrumentation/PluginLoader.test.ts | 7 ++++++- packages/opentelemetry-plugin-dns/src/dns.ts | 2 +- .../src/documentLoad.ts | 2 +- .../test/documentLoad.test.ts | 7 ++++++- packages/opentelemetry-plugin-grpc/src/grpc.ts | 2 +- .../opentelemetry-plugin-grpc/test/grpc.test.ts | 13 ++++++++++--- packages/opentelemetry-plugin-http/src/http.ts | 2 +- .../test/functionals/http-disable.test.ts | 11 +++++++++-- .../test/functionals/utils.test.ts | 2 +- .../test/functionals/https-disable.test.ts | 11 +++++++++-- .../test/functionals/https-enable.test.ts | 7 ++++++- .../test/integrations/https-enable.test.ts | 7 ++++++- .../opentelemetry-plugin-pg/src/pg.ts | 2 +- .../opentelemetry-plugin-pg/test/pg.test.ts | 2 +- packages/opentelemetry-plugin-redis/src/redis.ts | 2 +- .../opentelemetry-plugin-redis/test/redis.test.ts | 2 +- .../test/export/SimpleSpanProcessor.test.ts | 14 ++++++++++++-- packages/opentelemetry-web/test/WebTracer.test.ts | 6 ++++-- 25 files changed, 106 insertions(+), 35 deletions(-) diff --git a/packages/opentelemetry-core/src/trace/globaltracer-utils.ts b/packages/opentelemetry-core/src/trace/globaltracer-utils.ts index 360aad57a7..f15f0f78c6 100644 --- a/packages/opentelemetry-core/src/trace/globaltracer-utils.ts +++ b/packages/opentelemetry-core/src/trace/globaltracer-utils.ts @@ -22,7 +22,9 @@ let globalTracerRegistry: types.TracerRegistry = new NoopTracerRegistry(); /** * Set the current global tracer. Returns the initialized global tracer */ -export function initGlobalTracerRegistry(tracerRegistry: types.TracerRegistry): types.TracerRegistry { +export function initGlobalTracerRegistry( + tracerRegistry: types.TracerRegistry +): types.TracerRegistry { return (globalTracerRegistry = tracerRegistry); } diff --git a/packages/opentelemetry-core/src/trace/instrumentation/BasePlugin.ts b/packages/opentelemetry-core/src/trace/instrumentation/BasePlugin.ts index 658f622edd..04ccc60b26 100644 --- a/packages/opentelemetry-core/src/trace/instrumentation/BasePlugin.ts +++ b/packages/opentelemetry-core/src/trace/instrumentation/BasePlugin.ts @@ -40,8 +40,10 @@ export abstract class BasePlugin implements Plugin { protected readonly _internalFilesList?: PluginInternalFiles; // required for internalFilesExports protected _config!: PluginConfig; - - constructor(protected readonly _tracerName: string, protected readonly _tracerVersion?: string) { } + constructor( + protected readonly _tracerName: string, + protected readonly _tracerVersion?: string + ) {} enable( moduleExports: T, @@ -50,7 +52,10 @@ export abstract class BasePlugin implements Plugin { config?: PluginConfig ): T { this._moduleExports = moduleExports; - this._tracer = tracerRegistry.getTracer(this._tracerName, this._tracerVersion); + this._tracer = tracerRegistry.getTracer( + this._tracerName, + this._tracerVersion + ); this._logger = logger; this._internalFilesExports = this._loadInternalFilesExports(); if (config) this._config = config; diff --git a/packages/opentelemetry-core/test/trace/BasePlugin.test.ts b/packages/opentelemetry-core/test/trace/BasePlugin.test.ts index b0b728d8c7..2841903009 100644 --- a/packages/opentelemetry-core/test/trace/BasePlugin.test.ts +++ b/packages/opentelemetry-core/test/trace/BasePlugin.test.ts @@ -63,7 +63,7 @@ class TestPlugin extends BasePlugin<{ [key: string]: Function }> { readonly _basedir = basedir; constructor() { - super("test-package.opentelemetry") + super('test-package.opentelemetry'); } protected readonly _internalFilesList = { diff --git a/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts b/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts index 4a0b50aa2e..ad0c611b92 100644 --- a/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts +++ b/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts @@ -67,7 +67,7 @@ describe('globaltracer-utils', () => { it('should use the global tracer registry', () => { initGlobalTracerRegistry(new TestTracerRegistry()); - const tracer = getTracerRegistry().getTracer("name"); + const tracer = getTracerRegistry().getTracer('name'); const span = tracer.startSpan('test'); assert.deepStrictEqual(span, dummySpan); }); diff --git a/packages/opentelemetry-node/src/index.ts b/packages/opentelemetry-node/src/index.ts index 7c291d3284..2ba218e18d 100644 --- a/packages/opentelemetry-node/src/index.ts +++ b/packages/opentelemetry-node/src/index.ts @@ -1,4 +1,4 @@ - /*! +/*! * Copyright 2019, OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/packages/opentelemetry-node/src/instrumentation/PluginLoader.ts b/packages/opentelemetry-node/src/instrumentation/PluginLoader.ts index 5030c9a923..99d2abf487 100644 --- a/packages/opentelemetry-node/src/instrumentation/PluginLoader.ts +++ b/packages/opentelemetry-node/src/instrumentation/PluginLoader.ts @@ -14,7 +14,12 @@ * limitations under the License. */ -import { Logger, Plugin, PluginConfig, TracerRegistry } from '@opentelemetry/types'; +import { + Logger, + Plugin, + PluginConfig, + TracerRegistry, +} from '@opentelemetry/types'; import * as hook from 'require-in-the-middle'; import * as utils from './utils'; diff --git a/packages/opentelemetry-node/test/NodeTracer.test.ts b/packages/opentelemetry-node/test/NodeTracer.test.ts index b92ed88eff..bc858118e7 100644 --- a/packages/opentelemetry-node/test/NodeTracer.test.ts +++ b/packages/opentelemetry-node/test/NodeTracer.test.ts @@ -190,7 +190,9 @@ describe('NodeTracerRegistry', () => { registry.getTracer().withSpan(span, () => { assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), span); - const span1 = registry.getTracer().startSpan('my-span1', { parent: span }); + const span1 = registry + .getTracer() + .startSpan('my-span1', { parent: span }); registry.getTracer().withSpan(span1, () => { assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), span1); assert.deepStrictEqual( @@ -236,14 +238,18 @@ describe('NodeTracerRegistry', () => { describe('.getBinaryFormat()', () => { it('should get default binary formatter', () => { registry = new NodeTracerRegistry({}); - assert.ok(registry.getTracer().getBinaryFormat() instanceof BinaryTraceContext); + assert.ok( + registry.getTracer().getBinaryFormat() instanceof BinaryTraceContext + ); }); }); describe('.getHttpTextFormat()', () => { it('should get default HTTP text formatter', () => { registry = new NodeTracerRegistry({}); - assert.ok(registry.getTracer().getHttpTextFormat() instanceof HttpTraceContext); + assert.ok( + registry.getTracer().getHttpTextFormat() instanceof HttpTraceContext + ); }); }); }); diff --git a/packages/opentelemetry-node/test/instrumentation/PluginLoader.test.ts b/packages/opentelemetry-node/test/instrumentation/PluginLoader.test.ts index c36a2f8070..93440eb294 100644 --- a/packages/opentelemetry-node/test/instrumentation/PluginLoader.test.ts +++ b/packages/opentelemetry-node/test/instrumentation/PluginLoader.test.ts @@ -17,7 +17,12 @@ import { NoopLogger, NoopTracerRegistry } from '@opentelemetry/core'; import * as assert from 'assert'; import * as path from 'path'; -import { HookState, PluginLoader, Plugins, searchPathForTest } from '../../src/instrumentation/PluginLoader'; +import { + HookState, + PluginLoader, + Plugins, + searchPathForTest, +} from '../../src/instrumentation/PluginLoader'; const INSTALLED_PLUGINS_PATH = path.join(__dirname, 'node_modules'); diff --git a/packages/opentelemetry-plugin-dns/src/dns.ts b/packages/opentelemetry-plugin-dns/src/dns.ts index 6738eee045..d6ab4edf1e 100644 --- a/packages/opentelemetry-plugin-dns/src/dns.ts +++ b/packages/opentelemetry-plugin-dns/src/dns.ts @@ -39,7 +39,7 @@ export class DnsPlugin extends BasePlugin { protected _config!: DnsPluginConfig; constructor(readonly moduleName: string, readonly version: string) { - super(`opentelemetry.${moduleName}`, "0.2.0"); + super(`opentelemetry.${moduleName}`, '0.2.0'); // For now component is equal to moduleName but it can change in the future. this.component = this.moduleName; this._config = {}; diff --git a/packages/opentelemetry-plugin-document-load/src/documentLoad.ts b/packages/opentelemetry-plugin-document-load/src/documentLoad.ts index 6a828bb29b..c5d9f0b52e 100644 --- a/packages/opentelemetry-plugin-document-load/src/documentLoad.ts +++ b/packages/opentelemetry-plugin-document-load/src/documentLoad.ts @@ -40,7 +40,7 @@ export class DocumentLoad extends BasePlugin { * @param config */ constructor(config: PluginConfig = {}) { - super("opentelemetry.document-load", "0.2.0"); + super('opentelemetry.document-load', '0.2.0'); this._onDocumentLoaded = this._onDocumentLoaded.bind(this); this._config = config; } diff --git a/packages/opentelemetry-plugin-document-load/test/documentLoad.test.ts b/packages/opentelemetry-plugin-document-load/test/documentLoad.test.ts index adf4cb9d0f..5976205827 100644 --- a/packages/opentelemetry-plugin-document-load/test/documentLoad.test.ts +++ b/packages/opentelemetry-plugin-document-load/test/documentLoad.test.ts @@ -19,7 +19,12 @@ */ import { ConsoleLogger, TRACE_PARENT_HEADER } from '@opentelemetry/core'; -import { BasicTracerRegistry, ReadableSpan, SimpleSpanProcessor, SpanExporter } from '@opentelemetry/tracing'; +import { + BasicTracerRegistry, + ReadableSpan, + SimpleSpanProcessor, + SpanExporter, +} from '@opentelemetry/tracing'; import { Logger, PluginConfig, TimedEvent } from '@opentelemetry/types'; import * as assert from 'assert'; import * as sinon from 'sinon'; diff --git a/packages/opentelemetry-plugin-grpc/src/grpc.ts b/packages/opentelemetry-plugin-grpc/src/grpc.ts index 2d39223281..a488335f1b 100644 --- a/packages/opentelemetry-plugin-grpc/src/grpc.ts +++ b/packages/opentelemetry-plugin-grpc/src/grpc.ts @@ -56,7 +56,7 @@ export class GrpcPlugin extends BasePlugin { protected _config!: GrpcPluginOptions; constructor(readonly moduleName: string, readonly version: string) { - super(`opentelemetry.${moduleName}`, "0.2.0"); + super(`opentelemetry.${moduleName}`, '0.2.0'); this._config = {}; } diff --git a/packages/opentelemetry-plugin-grpc/test/grpc.test.ts b/packages/opentelemetry-plugin-grpc/test/grpc.test.ts index dbb35b54f1..46d4c0c97a 100644 --- a/packages/opentelemetry-plugin-grpc/test/grpc.test.ts +++ b/packages/opentelemetry-plugin-grpc/test/grpc.test.ts @@ -16,7 +16,10 @@ import { NoopLogger, NoopTracerRegistry } from '@opentelemetry/core'; import { NodeTracerRegistry } from '@opentelemetry/node'; -import { InMemorySpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing'; +import { + InMemorySpanExporter, + SimpleSpanProcessor, +} from '@opentelemetry/tracing'; import { SpanKind } from '@opentelemetry/types'; import * as assert from 'assert'; import * as grpc from 'grpc'; @@ -378,7 +381,9 @@ describe('GrpcPlugin', () => { const expectEmpty = memoryExporter.getFinishedSpans(); assert.strictEqual(expectEmpty.length, 0); - const span = registry.getTracer().startSpan('TestSpan', { kind: SpanKind.PRODUCER }); + const span = registry + .getTracer() + .startSpan('TestSpan', { kind: SpanKind.PRODUCER }); return registry.getTracer().withSpan(span, async () => { const rootSpan = registry.getTracer().getCurrentSpan(); if (!rootSpan) { @@ -471,7 +476,9 @@ describe('GrpcPlugin', () => { const expectEmpty = memoryExporter.getFinishedSpans(); assert.strictEqual(expectEmpty.length, 0); - const span = registry.getTracer().startSpan('TestSpan', { kind: SpanKind.PRODUCER }); + const span = registry + .getTracer() + .startSpan('TestSpan', { kind: SpanKind.PRODUCER }); return registry.getTracer().withSpan(span, async () => { const rootSpan = registry.getTracer().getCurrentSpan(); if (!rootSpan) { diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index b71bce7aa9..86eb7b465a 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -56,7 +56,7 @@ export class HttpPlugin extends BasePlugin { private readonly _spanNotEnded: WeakSet; constructor(readonly moduleName: string, readonly version: string) { - super(`opentelemetry.${moduleName}`, "0.2.0"); + super(`opentelemetry.${moduleName}`, '0.2.0'); // For now component is equal to moduleName but it can change in the future. this.component = this.moduleName; this._spanNotEnded = new WeakSet(); diff --git a/packages/opentelemetry-plugin-http/test/functionals/http-disable.test.ts b/packages/opentelemetry-plugin-http/test/functionals/http-disable.test.ts index d92e44b33d..b9b13276b9 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/http-disable.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/http-disable.test.ts @@ -20,7 +20,11 @@ import * as nock from 'nock'; import * as sinon from 'sinon'; import { plugin } from '../../src/http'; -import { NoopLogger, NoopTracerRegistry, noopTracer } from '@opentelemetry/core'; +import { + NoopLogger, + NoopTracerRegistry, + noopTracer, +} from '@opentelemetry/core'; import { AddressInfo } from 'net'; import { httpRequest } from '../utils/httpRequest'; @@ -74,7 +78,10 @@ describe('HttpPlugin', () => { ); assert.strictEqual(http.Server.prototype.emit.__wrapped, undefined); - assert.strictEqual((noopTracer.withSpan as sinon.SinonSpy).called, false); + assert.strictEqual( + (noopTracer.withSpan as sinon.SinonSpy).called, + false + ); }); }); }); diff --git a/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts b/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts index e6b3cea9b7..22c1729e1b 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts @@ -54,7 +54,7 @@ describe('Utility', () => { try { utils.hasExpectHeader('' as http.RequestOptions); assert.fail(); - } catch (ignore) { } + } catch (ignore) {} }); it('should not throw if no headers', () => { diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts index 9b92387690..b8229f1477 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { NoopLogger, NoopTracerRegistry, noopTracer } from '@opentelemetry/core'; +import { + NoopLogger, + NoopTracerRegistry, + noopTracer, +} from '@opentelemetry/core'; import { Http } from '@opentelemetry/plugin-http'; import * as assert from 'assert'; import * as fs from 'fs'; @@ -81,7 +85,10 @@ describe('HttpsPlugin', () => { ); assert.strictEqual(https.Server.prototype.emit.__wrapped, undefined); - assert.strictEqual((noopTracer.withSpan as sinon.SinonSpy).called, false); + assert.strictEqual( + (noopTracer.withSpan as sinon.SinonSpy).called, + false + ); }); }); }); diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts index 8cd908986b..5dcaca7d79 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts @@ -100,7 +100,12 @@ describe('HttpsPlugin', () => { ], applyCustomAttributesOnSpan: customAttributeFunction, }; - plugin.enable((https as unknown) as Http, registry, registry.logger, config); + plugin.enable( + (https as unknown) as Http, + registry, + registry.logger, + config + ); server = https.createServer( { key: fs.readFileSync('test/fixtures/server-key.pem'), diff --git a/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts index 1a27ed90b6..117f5db61c 100644 --- a/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts @@ -83,7 +83,12 @@ describe('HttpsPlugin Integration tests', () => { try { plugin.disable(); } catch (e) {} - plugin.enable((https as unknown) as Http, registry, registry.logger, config); + plugin.enable( + (https as unknown) as Http, + registry, + registry.logger, + config + ); }); after(() => { diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts index 46ca121a92..c23c5735b8 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts @@ -37,7 +37,7 @@ export class PostgresPlugin extends BasePlugin { readonly supportedVersions = ['7.*']; constructor(readonly moduleName: string) { - super(`opentelemetry.${moduleName}`, "0.2.0"); + super(`opentelemetry.${moduleName}`, '0.2.0'); this._config = {}; } diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/test/pg.test.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/test/pg.test.ts index 902ea2d484..4843fb90ef 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/test/pg.test.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/test/pg.test.ts @@ -89,7 +89,7 @@ const runCallbackTest = ( describe('pg@7.x', () => { let client: pg.Client; const registry = new NodeTracerRegistry(); - const tracer = registry.getTracer("external"); + const tracer = registry.getTracer('external'); const logger = new NoopLogger(); const testPostgres = process.env.RUN_POSTGRES_TESTS; // For CI: assumes local postgres db is already available const testPostgresLocally = process.env.RUN_POSTGRES_TESTS_LOCAL; // For local: spins up local postgres db via docker diff --git a/packages/opentelemetry-plugin-redis/src/redis.ts b/packages/opentelemetry-plugin-redis/src/redis.ts index 80868cc2e2..3ce225c9fa 100644 --- a/packages/opentelemetry-plugin-redis/src/redis.ts +++ b/packages/opentelemetry-plugin-redis/src/redis.ts @@ -28,7 +28,7 @@ export class RedisPlugin extends BasePlugin { readonly supportedVersions = ['^2.6.0']; // equivalent to >= 2.6.0 <3 constructor(readonly moduleName: string) { - super(`opentelemetry.${moduleName}`, "0.2.0"); + super(`opentelemetry.${moduleName}`, '0.2.0'); } protected patch() { diff --git a/packages/opentelemetry-plugin-redis/test/redis.test.ts b/packages/opentelemetry-plugin-redis/test/redis.test.ts index d7c7713d62..347cc2b91b 100644 --- a/packages/opentelemetry-plugin-redis/test/redis.test.ts +++ b/packages/opentelemetry-plugin-redis/test/redis.test.ts @@ -50,7 +50,7 @@ const okStatus: Status = { describe('redis@2.x', () => { const registry = new NodeTracerRegistry(); - const tracer = registry.getTracer("external"); + const tracer = registry.getTracer('external'); let redis: typeof redisTypes; const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL; const shouldTest = process.env.RUN_REDIS_TESTS || shouldTestLocal; diff --git a/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts b/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts index 05824f099e..4ba1f9fc4e 100644 --- a/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts +++ b/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts @@ -42,7 +42,12 @@ describe('SimpleSpanProcessor', () => { spanId: '5e0c63257de34c92', traceFlags: TraceFlags.SAMPLED, }; - const span = new Span(registry.getTracer(), 'span-name', spanContext, SpanKind.CLIENT); + const span = new Span( + registry.getTracer(), + 'span-name', + spanContext, + SpanKind.CLIENT + ); processor.onStart(span); assert.strictEqual(exporter.getFinishedSpans().length, 0); @@ -60,7 +65,12 @@ describe('SimpleSpanProcessor', () => { spanId: '5e0c63257de34c92', traceFlags: TraceFlags.UNSAMPLED, }; - const span = new Span(registry.getTracer(), 'span-name', spanContext, SpanKind.CLIENT); + const span = new Span( + registry.getTracer(), + 'span-name', + spanContext, + SpanKind.CLIENT + ); processor.onStart(span); assert.strictEqual(exporter.getFinishedSpans().length, 0); diff --git a/packages/opentelemetry-web/test/WebTracer.test.ts b/packages/opentelemetry-web/test/WebTracer.test.ts index 783c47feb3..5d242ffd44 100644 --- a/packages/opentelemetry-web/test/WebTracer.test.ts +++ b/packages/opentelemetry-web/test/WebTracer.test.ts @@ -25,7 +25,7 @@ import { WebTracerRegistry } from '../src/WebTracerRegistry'; class DummyPlugin extends BasePlugin { constructor() { - super("dummy"); + super('dummy'); } patch() {} unpatch() {} @@ -42,7 +42,9 @@ describe('WebTracer', () => { }); it('should construct an instance with required only options', () => { - const tracer = new WebTracerRegistry(Object.assign({}, defaultOptions)).getTracer(); + const tracer = new WebTracerRegistry( + Object.assign({}, defaultOptions) + ).getTracer(); assert.ok(tracer instanceof Tracer); }); From 14fa0612fcc6052194455c433b23cb0b78796334 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 2 Dec 2019 16:00:56 -0500 Subject: [PATCH 04/24] chore: add getTracer back --- .../opentelemetry-core/src/trace/globaltracer-utils.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/opentelemetry-core/src/trace/globaltracer-utils.ts b/packages/opentelemetry-core/src/trace/globaltracer-utils.ts index f15f0f78c6..2c57810442 100644 --- a/packages/opentelemetry-core/src/trace/globaltracer-utils.ts +++ b/packages/opentelemetry-core/src/trace/globaltracer-utils.ts @@ -29,9 +29,17 @@ export function initGlobalTracerRegistry( } /** - * Returns the global tracer + * Returns the global tracer registry. */ export function getTracerRegistry(): types.TracerRegistry { // Return the global tracer registry return globalTracerRegistry; } + +/** + * Returns a tracer from the global tracer registry. + */ +export function getTracer(name?: string, version?: string): types.Tracer { + // Return the global tracer registry + return globalTracerRegistry.getTracer(name, version); +} From b1e887ca1738ad8e2c024228e8064e61e6a84ff9 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 2 Dec 2019 16:02:02 -0500 Subject: [PATCH 05/24] chore: change default tracer name to empty string --- packages/opentelemetry-tracing/src/BasicTracerRegistry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts index fc71b82634..1afa9a1ea7 100644 --- a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts +++ b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts @@ -35,7 +35,7 @@ export class BasicTracerRegistry implements types.TracerRegistry { } getTracer( - name = 'DEFAULT_TRACER', + name = '', version = '*', config?: TracerConfig ): Tracer { From 5ca0209b732b9d9183f01154a17f1fd11d6a05b8 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 2 Dec 2019 16:09:34 -0500 Subject: [PATCH 06/24] fix: lint --- packages/opentelemetry-tracing/src/BasicTracerRegistry.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts index 1afa9a1ea7..cb41ddf24a 100644 --- a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts +++ b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts @@ -34,11 +34,7 @@ export class BasicTracerRegistry implements types.TracerRegistry { this.logger = _config.logger || new ConsoleLogger(_config.logLevel); } - getTracer( - name = '', - version = '*', - config?: TracerConfig - ): Tracer { + getTracer(name = '', version = '*', config?: TracerConfig): Tracer { const key = `${name}@${version}`; if (!this._tracers.has(key)) { this._tracers.set(key, new Tracer(config || this._config, this)); From 61f46184445cbf37dab2daab0128df3260441359 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 2 Dec 2019 17:44:33 -0500 Subject: [PATCH 07/24] chore: update examples for registry --- examples/basic-tracer-node/index.js | 8 +++--- examples/dns/setup.js | 8 +++--- examples/grpc/setup.js | 8 +++--- examples/grpc_dynamic_codegen/setup.js | 8 +++--- examples/http/setup.js | 8 +++--- examples/https/setup.js | 8 +++--- examples/mysql/setup.js | 10 +++---- examples/redis/setup.js | 8 +++--- examples/tracer-web/index.js | 37 +++++++++++++------------- 9 files changed, 52 insertions(+), 51 deletions(-) diff --git a/examples/basic-tracer-node/index.js b/examples/basic-tracer-node/index.js index 19b2a7b881..5c4d4fd78d 100644 --- a/examples/basic-tracer-node/index.js +++ b/examples/basic-tracer-node/index.js @@ -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'); @@ -17,13 +17,13 @@ if (EXPORTER.toLowerCase().startsWith('z')) { exporter = new JaegerExporter(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); +opentelemetry.initGlobalTracerRegistry(registry); // Create a span. A span must be closed. const span = opentelemetry.getTracer().startSpan('main'); diff --git a/examples/dns/setup.js b/examples/dns/setup.js index 26da571236..ae7e467511 100644 --- a/examples/dns/setup.js +++ b/examples/dns/setup.js @@ -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, @@ -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; diff --git a/examples/grpc/setup.js b/examples/grpc/setup.js index 4b01ef130a..4395acce27 100644 --- a/examples/grpc/setup.js +++ b/examples/grpc/setup.js @@ -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, @@ -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; diff --git a/examples/grpc_dynamic_codegen/setup.js b/examples/grpc_dynamic_codegen/setup.js index 5ac2a903e9..b2923777d4 100644 --- a/examples/grpc_dynamic_codegen/setup.js +++ b/examples/grpc_dynamic_codegen/setup.js @@ -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, @@ -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; diff --git a/examples/http/setup.js b/examples/http/setup.js index 3e729201cd..4099852f9d 100644 --- a/examples/http/setup.js +++ b/examples/http/setup.js @@ -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')) { @@ -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; diff --git a/examples/https/setup.js b/examples/https/setup.js index d09961eec9..b4115443e0 100644 --- a/examples/https/setup.js +++ b/examples/https/setup.js @@ -1,7 +1,7 @@ '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'); @@ -9,7 +9,7 @@ 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({ @@ -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; diff --git a/examples/mysql/setup.js b/examples/mysql/setup.js index d1e0185335..fb8df79ffb 100644 --- a/examples/mysql/setup.js +++ b/examples/mysql/setup.js @@ -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, @@ -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; diff --git a/examples/redis/setup.js b/examples/redis/setup.js index 3e729201cd..4099852f9d 100644 --- a/examples/redis/setup.js +++ b/examples/redis/setup.js @@ -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')) { @@ -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; diff --git a/examples/tracer-web/index.js b/examples/tracer-web/index.js index 0e5e9956e3..ab36e71d54 100644 --- a/examples/tracer-web/index.js +++ b/examples/tracer-web/index.js @@ -1,24 +1,25 @@ 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 = () => { @@ -26,33 +27,33 @@ const prepareClickEvent = () => { 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); }); From cc4eba98ddc35fd4bd19b95b0b6c403f2971a8b6 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Tue, 17 Dec 2019 10:28:21 -0500 Subject: [PATCH 08/24] chore(tracer-registry): make name required --- .../src/trace/globaltracer-utils.ts | 2 +- .../test/trace/globaltracer-utils.test.ts | 2 +- .../test/transform.test.ts | 2 +- .../test/NodeTracer.test.ts | 50 +++++----- .../test/functionals/dns-disable.test.ts | 2 +- .../test/functionals/utils.test.ts | 2 +- .../test/grpc.test.ts | 12 +-- .../test/functionals/http-enable.test.ts | 12 +-- .../test/functionals/utils.test.ts | 2 +- .../test/functionals/https-disable.test.ts | 10 +- .../test/functionals/https-enable.test.ts | 15 +-- .../test/functionals/https-package.test.ts | 16 ++-- .../test/integrations/https-enable.test.ts | 8 +- .../test/mongodb.test.ts | 26 ++--- .../test/mysql.test.ts | 96 +++++++++---------- .../test/Shim.test.ts | 2 +- packages/opentelemetry-tracing/README.md | 2 +- .../src/BasicTracerRegistry.ts | 2 +- .../test/BasicTracerRegistry.test.ts | 50 +++++----- .../test/MultiSpanProcessor.test.ts | 2 +- .../opentelemetry-tracing/test/Span.test.ts | 2 +- .../test/export/BatchSpanProcessor.test.ts | 4 +- .../test/export/ConsoleSpanExporter.test.ts | 2 +- .../test/export/InMemorySpanExporter.test.ts | 12 +-- .../test/export/SimpleSpanProcessor.test.ts | 4 +- .../src/trace/tracer_registry.ts | 2 +- .../opentelemetry-web/test/WebTracer.test.ts | 4 +- 27 files changed, 176 insertions(+), 169 deletions(-) diff --git a/packages/opentelemetry-core/src/trace/globaltracer-utils.ts b/packages/opentelemetry-core/src/trace/globaltracer-utils.ts index 2c57810442..f61180dc8f 100644 --- a/packages/opentelemetry-core/src/trace/globaltracer-utils.ts +++ b/packages/opentelemetry-core/src/trace/globaltracer-utils.ts @@ -39,7 +39,7 @@ export function getTracerRegistry(): types.TracerRegistry { /** * Returns a tracer from the global tracer registry. */ -export function getTracer(name?: string, version?: string): types.Tracer { +export function getTracer(name: string, version?: string): types.Tracer { // Return the global tracer registry return globalTracerRegistry.getTracer(name, version); } diff --git a/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts b/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts index ad0c611b92..4fc5ae0c05 100644 --- a/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts +++ b/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts @@ -82,7 +82,7 @@ describe('globaltracer-utils', () => { } class TestTracerRegistry extends NoopTracerRegistry { - getTracer() { + getTracer(_name: string, version?: string) { return new TestTracer(); } } diff --git a/packages/opentelemetry-exporter-zipkin/test/transform.test.ts b/packages/opentelemetry-exporter-zipkin/test/transform.test.ts index 5a0bb439e9..641803902f 100644 --- a/packages/opentelemetry-exporter-zipkin/test/transform.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/transform.test.ts @@ -34,7 +34,7 @@ import * as zipkinTypes from '../src/types'; const logger = new NoopLogger(); const tracer = new BasicTracerRegistry({ logger, -}).getTracer(); +}).getTracer('default'); const parentId = '5c1c63257de34c67'; const spanContext: types.SpanContext = { traceId: 'd4cda95b652f4a1592b449d5929fda1b', diff --git a/packages/opentelemetry-node/test/NodeTracer.test.ts b/packages/opentelemetry-node/test/NodeTracer.test.ts index bc858118e7..ec31ef4ed3 100644 --- a/packages/opentelemetry-node/test/NodeTracer.test.ts +++ b/packages/opentelemetry-node/test/NodeTracer.test.ts @@ -126,7 +126,7 @@ describe('NodeTracerRegistry', () => { registry = new NodeTracerRegistry({ logger: new NoopLogger(), }); - const span = registry.getTracer().startSpan('my-span'); + const span = registry.getTracer('default').startSpan('my-span'); assert.ok(span); }); @@ -134,7 +134,7 @@ describe('NodeTracerRegistry', () => { registry = new NodeTracerRegistry({ logger: new NoopLogger(), }); - const span = registry.getTracer().startSpan('my-span', {}); + const span = registry.getTracer('default').startSpan('my-span', {}); assert.ok(span); }); @@ -143,7 +143,7 @@ describe('NodeTracerRegistry', () => { sampler: NEVER_SAMPLER, logger: new NoopLogger(), }); - const span = registry.getTracer().startSpan('my-span'); + const span = registry.getTracer('default').startSpan('my-span'); assert.ok(span instanceof NoRecordingSpan); assert.strictEqual(span.context().traceFlags, TraceFlags.UNSAMPLED); assert.strictEqual(span.isRecording(), false); @@ -160,7 +160,7 @@ describe('NodeTracerRegistry', () => { defaultAttributes, }); - const span = registry.getTracer().startSpan('my-span') as Span; + const span = registry.getTracer('default').startSpan('my-span') as Span; assert.ok(span instanceof Span); assert.deepStrictEqual(span.attributes, defaultAttributes); }); @@ -169,32 +169,32 @@ describe('NodeTracerRegistry', () => { describe('.getCurrentSpan()', () => { it('should return undefined with AsyncHooksScopeManager when no span started', () => { registry = new NodeTracerRegistry({}); - assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), undefined); + assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), undefined); }); }); describe('.withSpan()', () => { it('should run scope with AsyncHooksScopeManager scope manager', done => { registry = new NodeTracerRegistry({}); - const span = registry.getTracer().startSpan('my-span'); - registry.getTracer().withSpan(span, () => { - assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), span); + const span = registry.getTracer('default').startSpan('my-span'); + registry.getTracer('default').withSpan(span, () => { + assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), span); return done(); }); - assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), undefined); + assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), undefined); }); it('should run scope with AsyncHooksScopeManager scope manager with multiple spans', done => { registry = new NodeTracerRegistry({}); - const span = registry.getTracer().startSpan('my-span'); - registry.getTracer().withSpan(span, () => { - assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), span); + const span = registry.getTracer('default').startSpan('my-span'); + registry.getTracer('default').withSpan(span, () => { + assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), span); const span1 = registry - .getTracer() + .getTracer('default') .startSpan('my-span1', { parent: span }); - registry.getTracer().withSpan(span1, () => { - assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), span1); + registry.getTracer('default').withSpan(span1, () => { + assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), span1); assert.deepStrictEqual( span1.context().traceId, span.context().traceId @@ -204,33 +204,33 @@ describe('NodeTracerRegistry', () => { }); // when span ended. // @todo: below check is not running. - assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), undefined); + assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), undefined); }); it('should find correct scope with promises', done => { registry = new NodeTracerRegistry({}); - const span = registry.getTracer().startSpan('my-span'); - registry.getTracer().withSpan(span, async () => { + const span = registry.getTracer('default').startSpan('my-span'); + registry.getTracer('default').withSpan(span, async () => { for (let i = 0; i < 3; i++) { await sleep(5).then(() => { - assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), span); + assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), span); }); } return done(); }); - assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), undefined); + assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), undefined); }); }); describe('.bind()', () => { it('should bind scope with AsyncHooksScopeManager scope manager', done => { const registry = new NodeTracerRegistry({}); - const span = registry.getTracer().startSpan('my-span'); + const span = registry.getTracer('default').startSpan('my-span'); const fn = () => { - assert.deepStrictEqual(registry.getTracer().getCurrentSpan(), span); + assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), span); return done(); }; - const patchedFn = registry.getTracer().bind(fn, span); + const patchedFn = registry.getTracer('default').bind(fn, span); return patchedFn(); }); }); @@ -239,7 +239,7 @@ describe('NodeTracerRegistry', () => { it('should get default binary formatter', () => { registry = new NodeTracerRegistry({}); assert.ok( - registry.getTracer().getBinaryFormat() instanceof BinaryTraceContext + registry.getTracer('default').getBinaryFormat() instanceof BinaryTraceContext ); }); }); @@ -248,7 +248,7 @@ describe('NodeTracerRegistry', () => { it('should get default HTTP text formatter', () => { registry = new NodeTracerRegistry({}); assert.ok( - registry.getTracer().getHttpTextFormat() instanceof HttpTraceContext + registry.getTracer('default').getHttpTextFormat() instanceof HttpTraceContext ); }); }); diff --git a/packages/opentelemetry-plugin-dns/test/functionals/dns-disable.test.ts b/packages/opentelemetry-plugin-dns/test/functionals/dns-disable.test.ts index 5251829324..8fcfb36f4d 100644 --- a/packages/opentelemetry-plugin-dns/test/functionals/dns-disable.test.ts +++ b/packages/opentelemetry-plugin-dns/test/functionals/dns-disable.test.ts @@ -28,7 +28,7 @@ import * as dns from 'dns'; const memoryExporter = new InMemorySpanExporter(); const logger = new NoopLogger(); const registry = new NodeTracerRegistry({ logger }); -const tracer = registry.getTracer(); +const tracer = registry.getTracer('default'); registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); describe('DnsPlugin', () => { diff --git a/packages/opentelemetry-plugin-dns/test/functionals/utils.test.ts b/packages/opentelemetry-plugin-dns/test/functionals/utils.test.ts index f0b74c17ce..4be83dbed2 100644 --- a/packages/opentelemetry-plugin-dns/test/functionals/utils.test.ts +++ b/packages/opentelemetry-plugin-dns/test/functionals/utils.test.ts @@ -162,7 +162,7 @@ describe('Utility', () => { it('should have error attributes', () => { const errorMessage = 'test error'; const span = new Span( - new BasicTracerRegistry().getTracer(), + new BasicTracerRegistry().getTracer('default'), 'test', { spanId: '', traceId: '' }, SpanKind.INTERNAL diff --git a/packages/opentelemetry-plugin-grpc/test/grpc.test.ts b/packages/opentelemetry-plugin-grpc/test/grpc.test.ts index 46d4c0c97a..a040309a93 100644 --- a/packages/opentelemetry-plugin-grpc/test/grpc.test.ts +++ b/packages/opentelemetry-plugin-grpc/test/grpc.test.ts @@ -382,10 +382,10 @@ describe('GrpcPlugin', () => { assert.strictEqual(expectEmpty.length, 0); const span = registry - .getTracer() + .getTracer('default') .startSpan('TestSpan', { kind: SpanKind.PRODUCER }); - return registry.getTracer().withSpan(span, async () => { - const rootSpan = registry.getTracer().getCurrentSpan(); + return registry.getTracer('default').withSpan(span, async () => { + const rootSpan = registry.getTracer('default').getCurrentSpan(); if (!rootSpan) { assert.ok(false); return; // return so typechecking passes for rootSpan.end() @@ -477,10 +477,10 @@ describe('GrpcPlugin', () => { assert.strictEqual(expectEmpty.length, 0); const span = registry - .getTracer() + .getTracer('default') .startSpan('TestSpan', { kind: SpanKind.PRODUCER }); - return registry.getTracer().withSpan(span, async () => { - const rootSpan = registry.getTracer().getCurrentSpan(); + return registry.getTracer('default').withSpan(span, async () => { + const rootSpan = registry.getTracer('default').getCurrentSpan(); if (!rootSpan) { assert.ok(false); return; // return so typechecking passes for rootSpan.end() diff --git a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts index e2c38772b5..de088ded3c 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts @@ -282,8 +282,8 @@ describe('HttpPlugin', () => { const testPath = '/outgoing/rootSpan/childs/1'; doNock(hostname, testPath, 200, 'Ok'); const name = 'TestRootSpan'; - const span = registry.getTracer().startSpan(name); - return registry.getTracer().withSpan(span, async () => { + const span = registry.getTracer('default').startSpan(name); + return registry.getTracer('default').withSpan(span, async () => { const result = await httpRequest.get( `${protocol}://${hostname}${testPath}` ); @@ -325,8 +325,8 @@ describe('HttpPlugin', () => { httpErrorCodes[i].toString() ); const name = 'TestRootSpan'; - const span = registry.getTracer().startSpan(name); - return registry.getTracer().withSpan(span, async () => { + const span = registry.getTracer('default').startSpan(name); + return registry.getTracer('default').withSpan(span, async () => { const result = await httpRequest.get( `${protocol}://${hostname}${testPath}` ); @@ -364,8 +364,8 @@ describe('HttpPlugin', () => { const num = 5; doNock(hostname, testPath, 200, 'Ok', num); const name = 'TestRootSpan'; - const span = registry.getTracer().startSpan(name); - await registry.getTracer().withSpan(span, async () => { + const span = registry.getTracer('default').startSpan(name); + await registry.getTracer('default').withSpan(span, async () => { for (let i = 0; i < num; i++) { await httpRequest.get(`${protocol}://${hostname}${testPath}`); const spans = memoryExporter.getFinishedSpans(); diff --git a/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts b/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts index a940a0a0f7..32372c8cbe 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts @@ -250,7 +250,7 @@ describe('Utility', () => { const span = new Span( new BasicTracerRegistry({ scopeManager: new NoopScopeManager(), - }).getTracer(), + }).getTracer('default'), 'test', { spanId: '', traceId: '' }, SpanKind.INTERNAL diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts index 049af1be4b..1a6ea75b4d 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts @@ -15,7 +15,6 @@ */ import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; import { Http } from '@opentelemetry/plugin-http'; import * as assert from 'assert'; import * as fs from 'fs'; @@ -26,6 +25,8 @@ import * as sinon from 'sinon'; import { plugin } from '../../src/https'; import { DummyPropagation } from '../utils/DummyPropagation'; import { httpsRequest } from '../utils/httpsRequest'; +import { NodeTracerRegistry } from '@opentelemetry/node'; +import * as types from "@opentelemetry/types" describe('HttpsPlugin', () => { let server: https.Server; @@ -34,15 +35,18 @@ describe('HttpsPlugin', () => { describe('disable()', () => { const httpTextFormat = new DummyPropagation(); const logger = new NoopLogger(); - const tracer = new NodeTracer({ + const registry = new NodeTracerRegistry({ logger, httpTextFormat, }); + // const tracer = registry.getTracer('test-https') + let tracer: types.Tracer; before(() => { nock.cleanAll(); nock.enableNetConnect(); - plugin.enable((https as unknown) as Http, tracer, tracer.logger); + plugin.enable((https as unknown) as Http, registry, registry.logger); + tracer = plugin["_tracer"]; // Ensure that https module is patched. assert.strictEqual(https.Server.prototype.emit.__wrapped, true); server = https.createServer( diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts index cc449ddb4a..2870854494 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts @@ -19,7 +19,6 @@ import { SimpleSpanProcessor, } from '@opentelemetry/tracing'; import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; import { Http, HttpPluginConfig, @@ -35,6 +34,7 @@ import { HttpsPlugin, plugin } from '../../src/https'; import { assertSpan } from '../utils/assertSpan'; import { DummyPropagation } from '../utils/DummyPropagation'; import { httpsRequest } from '../utils/httpsRequest'; +import { NodeTracerRegistry } from '@opentelemetry/node'; let server: https.Server; const serverPort = 32345; @@ -77,11 +77,11 @@ describe('HttpsPlugin', () => { describe('enable()', () => { const httpTextFormat = new DummyPropagation(); const logger = new NoopLogger(); - const tracer = new NodeTracer({ + const registry = new NodeTracerRegistry({ logger, httpTextFormat, }); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); beforeEach(() => { memoryExporter.reset(); }); @@ -100,7 +100,7 @@ describe('HttpsPlugin', () => { ], applyCustomAttributesOnSpan: customAttributeFunction, }; - plugin.enable((https as unknown) as Http, tracer, tracer.logger, config); + plugin.enable((https as unknown) as Http, registry, registry.logger, config); server = https.createServer( { key: fs.readFileSync('test/fixtures/server-key.pem'), @@ -126,8 +126,8 @@ describe('HttpsPlugin', () => { it("should not patch if it's not a http module", () => { const httpNotPatched = new HttpsPlugin(process.versions.node).enable( {} as Http, - tracer, - tracer.logger, + registry, + registry.logger, {} ); assert.strictEqual(Object.keys(httpNotPatched).length, 0); @@ -213,6 +213,7 @@ describe('HttpsPlugin', () => { const testPath = '/outgoing/rootSpan/childs/1'; doNock(hostname, testPath, 200, 'Ok'); const name = 'TestRootSpan'; + const tracer = registry.getTracer("test-https"); const span = tracer.startSpan(name); return tracer.withSpan(span, async () => { const result = await httpsRequest.get( @@ -256,6 +257,7 @@ describe('HttpsPlugin', () => { httpErrorCodes[i].toString() ); const name = 'TestRootSpan'; + const tracer = registry.getTracer("test-https"); const span = tracer.startSpan(name); return tracer.withSpan(span, async () => { const result = await httpsRequest.get( @@ -295,6 +297,7 @@ describe('HttpsPlugin', () => { const num = 5; doNock(hostname, testPath, 200, 'Ok', num); const name = 'TestRootSpan'; + const tracer = registry.getTracer("test-https"); const span = tracer.startSpan(name); await tracer.withSpan(span, async () => { for (let i = 0; i < num; i++) { diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-package.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-package.test.ts index 0604149ff4..66187bd92f 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-package.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-package.test.ts @@ -29,12 +29,12 @@ import * as superagent from 'superagent'; import * as got from 'got'; import * as request from 'request-promise-native'; import * as path from 'path'; -import { NodeTracer } from '@opentelemetry/node'; import { InMemorySpanExporter, SimpleSpanProcessor, } from '@opentelemetry/tracing'; import { Http } from '@opentelemetry/plugin-http'; +import { NodeTracerRegistry } from '@opentelemetry/node'; const memoryExporter = new InMemorySpanExporter(); @@ -47,17 +47,17 @@ describe('Packages', () => { const httpTextFormat = new DummyPropagation(); const logger = new NoopLogger(); - const tracer = new NodeTracer({ + const registry = new NodeTracerRegistry({ logger, httpTextFormat, }); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); beforeEach(() => { memoryExporter.reset(); }); before(() => { - plugin.enable((https as unknown) as Http, tracer, tracer.logger); + plugin.enable((https as unknown) as Http, registry, registry.logger); }); after(() => { @@ -90,10 +90,10 @@ describe('Packages', () => { const urlparsed = url.parse( name === 'got' && process.versions.node.startsWith('12') ? // there is an issue with got 9.6 version and node 12 when redirecting so url above will not work - // https://github.com/nock/nock/pull/1551 - // https://github.com/sindresorhus/got/commit/bf1aa5492ae2bc78cbbec6b7d764906fb156e6c2#diff-707a4781d57c42085155dcb27edb9ccbR258 - // TODO: check if this is still the case when new version - 'https://www.google.com' + // https://github.com/nock/nock/pull/1551 + // https://github.com/sindresorhus/got/commit/bf1aa5492ae2bc78cbbec6b7d764906fb156e6c2#diff-707a4781d57c42085155dcb27edb9ccbR258 + // TODO: check if this is still the case when new version + 'https://www.google.com' : `https://www.google.com/search?q=axios&oq=axios&aqs=chrome.0.69i59l2j0l3j69i60.811j0j7&sourceid=chrome&ie=UTF-8` ); const result = await httpPackage.get(urlparsed.href!); diff --git a/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts index a3ad0e487f..2f35da9178 100644 --- a/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts @@ -19,7 +19,6 @@ import { SimpleSpanProcessor, } from '@opentelemetry/tracing'; import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; import { HttpPluginConfig, Http } from '@opentelemetry/plugin-http'; import { Span, SpanKind } from '@opentelemetry/types'; import * as assert from 'assert'; @@ -31,6 +30,7 @@ import { assertSpan } from '../utils/assertSpan'; import { DummyPropagation } from '../utils/DummyPropagation'; import { httpsRequest } from '../utils/httpsRequest'; import * as utils from '../utils/utils'; +import { NodeTracerRegistry } from '@opentelemetry/node'; const serverPort = 42345; const hostname = 'localhost'; @@ -60,11 +60,11 @@ describe('HttpsPlugin Integration tests', () => { const httpTextFormat = new DummyPropagation(); const logger = new NoopLogger(); - const tracer = new NodeTracer({ + const registry = new NodeTracerRegistry({ logger, httpTextFormat, }); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); beforeEach(() => { memoryExporter.reset(); }); @@ -83,7 +83,7 @@ describe('HttpsPlugin Integration tests', () => { try { plugin.disable(); } catch (e) {} - plugin.enable((https as unknown) as Http, tracer, tracer.logger, config); + plugin.enable((https as unknown) as Http, registry, registry.logger, config); }); after(() => { diff --git a/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts b/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts index f7d9df901a..e3c0e81dbd 100644 --- a/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts +++ b/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts @@ -160,8 +160,8 @@ describe('MongoDBPlugin', () => { it('should create a child span for insert', done => { const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }]; - const span = registry.getTracer().startSpan(`insertRootSpan`); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan(`insertRootSpan`); + registry.getTracer('default').withSpan(span, () => { collection.insertMany(insertData, (err, result) => { span.end(); assert.ifError(err); @@ -176,8 +176,8 @@ describe('MongoDBPlugin', () => { }); it('should create a child span for update', done => { - const span = registry.getTracer().startSpan('updateRootSpan'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('updateRootSpan'); + registry.getTracer('default').withSpan(span, () => { collection.updateOne({ a: 2 }, { $set: { b: 1 } }, (err, result) => { span.end(); assert.ifError(err); @@ -192,8 +192,8 @@ describe('MongoDBPlugin', () => { }); it('should create a child span for remove', done => { - const span = registry.getTracer().startSpan('removeRootSpan'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('removeRootSpan'); + registry.getTracer('default').withSpan(span, () => { collection.deleteOne({ a: 3 }, (err, result) => { span.end(); assert.ifError(err); @@ -211,8 +211,8 @@ describe('MongoDBPlugin', () => { /** Should intercept cursor */ describe('Instrumenting cursor operations', () => { it('should create a child span for find', done => { - const span = registry.getTracer().startSpan('findRootSpan'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('findRootSpan'); + registry.getTracer('default').withSpan(span, () => { collection.find({}).toArray((err, result) => { span.end(); assert.ifError(err); @@ -230,8 +230,8 @@ describe('MongoDBPlugin', () => { /** Should intercept command */ describe('Instrumenting command operations', () => { it('should create a child span for create index', done => { - const span = registry.getTracer().startSpan('indexRootSpan'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('indexRootSpan'); + registry.getTracer('default').withSpan(span, () => { collection.createIndex({ a: 1 }, (err, result) => { span.end(); assert.ifError(err); @@ -257,7 +257,7 @@ describe('MongoDBPlugin', () => { it('should not create a child span for query', done => { const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }]; - const span = registry.getTracer().startSpan('insertRootSpan'); + const span = registry.getTracer('default').startSpan('insertRootSpan'); collection.insertMany(insertData, (err, result) => { span.end(); assert.ifError(err); @@ -267,7 +267,7 @@ describe('MongoDBPlugin', () => { }); it('should not create a child span for cursor', done => { - const span = registry.getTracer().startSpan('findRootSpan'); + const span = registry.getTracer('default').startSpan('findRootSpan'); collection.find({}).toArray((err, result) => { span.end(); assert.ifError(err); @@ -277,7 +277,7 @@ describe('MongoDBPlugin', () => { }); it('should not create a child span for command', done => { - const span = registry.getTracer().startSpan('indexRootSpan'); + const span = registry.getTracer('default').startSpan('indexRootSpan'); collection.createIndex({ a: 1 }, (err, result) => { span.end(); assert.ifError(err); diff --git a/packages/opentelemetry-plugin-mysql/test/mysql.test.ts b/packages/opentelemetry-plugin-mysql/test/mysql.test.ts index 75e35b196b..bd9acf38c1 100644 --- a/packages/opentelemetry-plugin-mysql/test/mysql.test.ts +++ b/packages/opentelemetry-plugin-mysql/test/mysql.test.ts @@ -118,8 +118,8 @@ describe('mysql@2.x', () => { describe('#Connection', () => { it('should intercept connection.query(text: string)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; const query = connection.query(statement); let rows = 0; @@ -140,8 +140,8 @@ describe('mysql@2.x', () => { }); it('should intercept connection.query(text: string, callback)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; connection.query(statement, (err, res) => { assert.ifError(err); @@ -156,8 +156,8 @@ describe('mysql@2.x', () => { }); it('should intercept connection.query(text: options, callback)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+? as solution'; connection.query({ sql: statement, values: [1] }, (err, res) => { assert.ifError(err); @@ -172,8 +172,8 @@ describe('mysql@2.x', () => { }); it('should intercept connection.query(text: options, values: [], callback)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+? as solution'; // @ts-ignore this is documented https://github.com/mysqljs/mysql#performing-queries // but does not match the typings @@ -190,8 +190,8 @@ describe('mysql@2.x', () => { }); it('should intercept connection.query(text: string, values: [], callback)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT ? as solution'; connection.query(statement, [1], (err, res) => { assert.ifError(err); @@ -206,8 +206,8 @@ describe('mysql@2.x', () => { }); it('should intercept connection.query(text: string, value: any, callback)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT ? as solution'; connection.query(statement, 1, (err, res) => { assert.ifError(err); @@ -222,8 +222,8 @@ describe('mysql@2.x', () => { }); it('should attach error messages to spans', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT ? as solution'; connection.query(statement, (err, res) => { assert.ok(err); @@ -238,8 +238,8 @@ describe('mysql@2.x', () => { describe('#Pool', () => { it('should intercept pool.query(text: string)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; const query = pool.query(statement); let rows = 0; @@ -260,8 +260,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.getConnection().query(text: string)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; pool.getConnection((err, conn) => { const query = conn.query(statement); @@ -284,8 +284,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.query(text: string, callback)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; pool.query(statement, (err, res) => { assert.ifError(err); @@ -300,8 +300,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.getConnection().query(text: string, callback)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; pool.getConnection((err, conn) => { conn.query(statement, (err, res) => { @@ -318,8 +318,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.query(text: options, callback)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+? as solution'; pool.query({ sql: statement, values: [1] }, (err, res) => { assert.ifError(err); @@ -334,8 +334,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.query(text: options, values: [], callback)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+? as solution'; // @ts-ignore this is documented https://github.com/mysqljs/mysql#performing-queries // but does not match the typings @@ -352,8 +352,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.query(text: string, values: [], callback)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT ? as solution'; pool.query(statement, [1], (err, res) => { assert.ifError(err); @@ -368,8 +368,8 @@ describe('mysql@2.x', () => { }); it('should intercept pool.query(text: string, value: any, callback)', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT ? as solution'; pool.query(statement, 1, (err, res) => { assert.ifError(err); @@ -384,8 +384,8 @@ describe('mysql@2.x', () => { }); it('should attach error messages to spans', done => { - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT ? as solution'; pool.query(statement, (err, res) => { assert.ok(err); @@ -402,8 +402,8 @@ describe('mysql@2.x', () => { it('should intercept poolClusterConnection.query(text: string)', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; const query = poolClusterConnection.query(statement); let rows = 0; @@ -427,8 +427,8 @@ describe('mysql@2.x', () => { it('should intercept poolClusterConnection.query(text: string, callback)', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+1 as solution'; poolClusterConnection.query(statement, (err, res) => { assert.ifError(err); @@ -446,8 +446,8 @@ describe('mysql@2.x', () => { it('should intercept poolClusterConnection.query(text: options, callback)', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+? as solution'; poolClusterConnection.query( { sql: statement, values: [1] }, @@ -468,8 +468,8 @@ describe('mysql@2.x', () => { it('should intercept poolClusterConnection.query(text: options, values: [], callback)', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1+? as solution'; // @ts-ignore this is documented https://github.com/mysqljs/mysql#performing-queries // but does not match the typings @@ -489,8 +489,8 @@ describe('mysql@2.x', () => { it('should intercept poolClusterConnection.query(text: string, values: [], callback)', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT ? as solution'; poolClusterConnection.query(statement, [1], (err, res) => { assert.ifError(err); @@ -508,8 +508,8 @@ describe('mysql@2.x', () => { it('should intercept poolClusterConnection.query(text: string, value: any, callback)', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT ? as solution'; poolClusterConnection.query(statement, 1, (err, res) => { assert.ifError(err); @@ -527,8 +527,8 @@ describe('mysql@2.x', () => { it('should attach error messages to spans', done => { poolCluster.getConnection((err, poolClusterConnection) => { assert.ifError(err); - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT ? as solution'; poolClusterConnection.query(statement, (err, res) => { assert.ok(err); @@ -544,8 +544,8 @@ describe('mysql@2.x', () => { it('should get connection by name', done => { poolCluster.getConnection('name', (err, poolClusterConnection) => { assert.ifError(err); - const span = registry.getTracer().startSpan('test span'); - registry.getTracer().withSpan(span, () => { + const span = registry.getTracer('default').startSpan('test span'); + registry.getTracer('default').withSpan(span, () => { const statement = 'SELECT 1 as solution'; poolClusterConnection.query(statement, (err, res) => { assert.ifError(err); diff --git a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts index c583811ab7..e7a8edc492 100644 --- a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts +++ b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts @@ -23,7 +23,7 @@ import { performance } from 'perf_hooks'; describe('OpenTracing Shim', () => { const registry = new BasicTracerRegistry(); - const shimTracer: opentracing.Tracer = new TracerShim(registry.getTracer()); + const shimTracer: opentracing.Tracer = new TracerShim(registry.getTracer('default')); opentracing.initGlobalTracer(shimTracer); describe('TracerShim', () => { diff --git a/packages/opentelemetry-tracing/README.md b/packages/opentelemetry-tracing/README.md index 8b29052a43..92bc676af2 100644 --- a/packages/opentelemetry-tracing/README.md +++ b/packages/opentelemetry-tracing/README.md @@ -35,7 +35,7 @@ const tracer = new BasicTracer(); opentelemetry.initGlobalTracer(tracer); // To create a span in a trace, we used the global singleton tracer to start a new span. -const span = opentelemetry.getTracer().startSpan('foo'); +const span = opentelemetry.getTracer('default').startSpan('foo'); // Create an Attributes span.setAttribute('key', 'value'); diff --git a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts index cb41ddf24a..6f8759e171 100644 --- a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts +++ b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts @@ -34,7 +34,7 @@ export class BasicTracerRegistry implements types.TracerRegistry { this.logger = _config.logger || new ConsoleLogger(_config.logLevel); } - getTracer(name = '', version = '*', config?: TracerConfig): Tracer { + getTracer(name: string, version = '*', config?: TracerConfig): Tracer { const key = `${name}@${version}`; if (!this._tracers.has(key)) { this._tracers.set(key, new Tracer(config || this._config, this)); diff --git a/packages/opentelemetry-tracing/test/BasicTracerRegistry.test.ts b/packages/opentelemetry-tracing/test/BasicTracerRegistry.test.ts index a912d94862..020a5a5ea2 100644 --- a/packages/opentelemetry-tracing/test/BasicTracerRegistry.test.ts +++ b/packages/opentelemetry-tracing/test/BasicTracerRegistry.test.ts @@ -69,7 +69,7 @@ describe('BasicTracerRegistry', () => { it('should construct an instance with default trace params', () => { const tracer = new BasicTracerRegistry({ scopeManager: new NoopScopeManager(), - }).getTracer(); + }).getTracer('default'); assert.deepStrictEqual(tracer.getActiveTraceParams(), { numberOfAttributesPerSpan: 32, numberOfEventsPerSpan: 128, @@ -83,7 +83,7 @@ describe('BasicTracerRegistry', () => { traceParams: { numberOfAttributesPerSpan: 100, }, - }).getTracer(); + }).getTracer('default'); assert.deepStrictEqual(tracer.getActiveTraceParams(), { numberOfAttributesPerSpan: 100, numberOfEventsPerSpan: 128, @@ -97,7 +97,7 @@ describe('BasicTracerRegistry', () => { traceParams: { numberOfEventsPerSpan: 300, }, - }).getTracer(); + }).getTracer('default'); assert.deepStrictEqual(tracer.getActiveTraceParams(), { numberOfAttributesPerSpan: 32, numberOfEventsPerSpan: 300, @@ -111,7 +111,7 @@ describe('BasicTracerRegistry', () => { traceParams: { numberOfLinksPerSpan: 10, }, - }).getTracer(); + }).getTracer('default'); assert.deepStrictEqual(tracer.getActiveTraceParams(), { numberOfAttributesPerSpan: 32, numberOfEventsPerSpan: 128, @@ -132,14 +132,14 @@ describe('BasicTracerRegistry', () => { describe('.startSpan()', () => { it('should start a span with name only', () => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); const span = tracer.startSpan('my-span'); assert.ok(span); assert.ok(span instanceof Span); }); it('should start a span with name and options', () => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); const span = tracer.startSpan('my-span', {}); assert.ok(span); assert.ok(span instanceof Span); @@ -154,7 +154,7 @@ describe('BasicTracerRegistry', () => { it('should start a span with defaultAttributes and spanoptions->attributes', () => { const tracer = new BasicTracerRegistry({ defaultAttributes: { foo: 'bar' }, - }).getTracer(); + }).getTracer('default'); const span = tracer.startSpan('my-span', { attributes: { foo: 'foo', bar: 'bar' }, }) as Span; @@ -165,14 +165,14 @@ describe('BasicTracerRegistry', () => { it('should start a span with defaultAttributes and undefined spanoptions->attributes', () => { const tracer = new BasicTracerRegistry({ defaultAttributes: { foo: 'bar' }, - }).getTracer(); + }).getTracer('default'); const span = tracer.startSpan('my-span', {}) as Span; assert.deepStrictEqual(span.attributes, { foo: 'bar' }); span.end(); }); it('should start a span with spanoptions->attributes', () => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); const span = tracer.startSpan('my-span', { attributes: { foo: 'foo', bar: 'bar' }, }) as Span; @@ -181,7 +181,7 @@ describe('BasicTracerRegistry', () => { }); it('should start a span with name and parent spancontext', () => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); const state = new TraceState('a=1,b=2'); const span = tracer.startSpan('my-span', { parent: { @@ -199,7 +199,7 @@ describe('BasicTracerRegistry', () => { }); it('should start a span with name and parent span', () => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); const span = tracer.startSpan('my-span'); const childSpan = tracer.startSpan('child-span', { parent: span, @@ -212,7 +212,7 @@ describe('BasicTracerRegistry', () => { }); it('should start a span with name and with invalid parent span', () => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); const span = tracer.startSpan('my-span', { parent: ('invalid-parent' as unknown) as undefined, }) as Span; @@ -220,7 +220,7 @@ describe('BasicTracerRegistry', () => { }); it('should start a span with name and with invalid spancontext', () => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); const span = tracer.startSpan('my-span', { parent: { traceId: '0', spanId: '0' }, }); @@ -236,7 +236,7 @@ describe('BasicTracerRegistry', () => { const tracer = new BasicTracerRegistry({ sampler: NEVER_SAMPLER, logger: new NoopLogger(), - }).getTracer(); + }).getTracer('default'); const span = tracer.startSpan('my-span'); assert.ok(span instanceof NoRecordingSpan); const context = span.context(); @@ -250,7 +250,7 @@ describe('BasicTracerRegistry', () => { it('should create real span when not sampled but recording events true', () => { const tracer = new BasicTracerRegistry({ sampler: NEVER_SAMPLER, - }).getTracer(); + }).getTracer('default'); const span = tracer.startSpan('my-span', { isRecording: true }); assert.ok(span instanceof Span); assert.strictEqual(span.context().traceFlags, TraceFlags.UNSAMPLED); @@ -261,7 +261,7 @@ describe('BasicTracerRegistry', () => { const tracer = new BasicTracerRegistry({ sampler: NEVER_SAMPLER, logger: new NoopLogger(), - }).getTracer(); + }).getTracer('default'); const span = tracer.startSpan('my-span', { isRecording: false }); assert.ok(span instanceof NoRecordingSpan); assert.strictEqual(span.context().traceFlags, TraceFlags.UNSAMPLED); @@ -272,7 +272,7 @@ describe('BasicTracerRegistry', () => { const tracer = new BasicTracerRegistry({ sampler: NEVER_SAMPLER, logger: new NoopLogger(), - }).getTracer(); + }).getTracer('default'); const span = tracer.startSpan('my-span'); assert.ok(span instanceof NoRecordingSpan); assert.strictEqual(span.context().traceFlags, TraceFlags.UNSAMPLED); @@ -283,7 +283,7 @@ describe('BasicTracerRegistry', () => { const tracer = new BasicTracerRegistry({ sampler: ALWAYS_SAMPLER, scopeManager: new NoopScopeManager(), - }).getTracer(); + }).getTracer('default'); const span = tracer.startSpan('my-span', { isRecording: true }); assert.ok(span instanceof Span); assert.strictEqual(span.context().traceFlags, TraceFlags.SAMPLED); @@ -297,7 +297,7 @@ describe('BasicTracerRegistry', () => { const tracer = new BasicTracerRegistry({ scopeManager: new NoopScopeManager(), defaultAttributes, - }).getTracer(); + }).getTracer('default'); const span = tracer.startSpan('my-span') as Span; assert.ok(span instanceof Span); @@ -307,7 +307,7 @@ describe('BasicTracerRegistry', () => { describe('.getCurrentSpan()', () => { it('should return null with NoopScopeManager', () => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); const currentSpan = tracer.getCurrentSpan(); assert.deepStrictEqual(currentSpan, undefined); }); @@ -317,14 +317,14 @@ describe('BasicTracerRegistry', () => { scopeManager: { active: () => 'foo', } as ScopeManager, - }).getTracer(); + }).getTracer('default'); assert.deepStrictEqual(tracer.getCurrentSpan(), 'foo'); }); }); describe('.withSpan()', () => { it('should run scope with NoopScopeManager scope manager', done => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); const span = tracer.startSpan('my-span'); tracer.withSpan(span, () => { assert.deepStrictEqual(tracer.getCurrentSpan(), undefined); @@ -335,7 +335,7 @@ describe('BasicTracerRegistry', () => { describe('.bind()', () => { it('should bind scope with NoopScopeManager scope manager', done => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); const span = tracer.startSpan('my-span'); const fn = () => { assert.deepStrictEqual(tracer.getCurrentSpan(), undefined); @@ -348,14 +348,14 @@ describe('BasicTracerRegistry', () => { describe('.getBinaryFormat()', () => { it('should get default binary formatter', () => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); assert.ok(tracer.getBinaryFormat() instanceof BinaryTraceContext); }); }); describe('.getHttpTextFormat()', () => { it('should get default HTTP text formatter', () => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); assert.ok(tracer.getHttpTextFormat() instanceof HttpTraceContext); }); }); diff --git a/packages/opentelemetry-tracing/test/MultiSpanProcessor.test.ts b/packages/opentelemetry-tracing/test/MultiSpanProcessor.test.ts index 7a18edfe9e..7464273e8f 100644 --- a/packages/opentelemetry-tracing/test/MultiSpanProcessor.test.ts +++ b/packages/opentelemetry-tracing/test/MultiSpanProcessor.test.ts @@ -30,7 +30,7 @@ class TestProcessor implements SpanProcessor { } describe('MultiSpanProcessor', () => { - const tracer = new BasicTracerRegistry().getTracer(); + const tracer = new BasicTracerRegistry().getTracer('default'); const span = tracer.startSpan('one'); it('should handle empty span processor', () => { diff --git a/packages/opentelemetry-tracing/test/Span.test.ts b/packages/opentelemetry-tracing/test/Span.test.ts index 695f115864..60cbbbfc21 100644 --- a/packages/opentelemetry-tracing/test/Span.test.ts +++ b/packages/opentelemetry-tracing/test/Span.test.ts @@ -35,7 +35,7 @@ const performanceTimeOrigin = hrTime(); describe('Span', () => { const tracer = new BasicTracerRegistry({ logger: new NoopLogger(), - }).getTracer(); + }).getTracer('default'); const name = 'span1'; const spanContext: SpanContext = { traceId: 'd4cda95b652f4a1592b449d5929fda1b', diff --git a/packages/opentelemetry-tracing/test/export/BatchSpanProcessor.test.ts b/packages/opentelemetry-tracing/test/export/BatchSpanProcessor.test.ts index d3a232de19..a12a045392 100644 --- a/packages/opentelemetry-tracing/test/export/BatchSpanProcessor.test.ts +++ b/packages/opentelemetry-tracing/test/export/BatchSpanProcessor.test.ts @@ -27,7 +27,7 @@ import { NEVER_SAMPLER, ALWAYS_SAMPLER, NoopLogger } from '@opentelemetry/core'; function createSampledSpan(spanName: string): Span { const tracer = new BasicTracerRegistry({ sampler: ALWAYS_SAMPLER, - }).getTracer(); + }).getTracer('default'); const span = tracer.startSpan(spanName); span.end(); return span as Span; @@ -37,7 +37,7 @@ function createUnSampledSpan(spanName: string): Span { const tracer = new BasicTracerRegistry({ sampler: NEVER_SAMPLER, logger: new NoopLogger(), - }).getTracer(); + }).getTracer('default'); const span = tracer.startSpan(spanName, { isRecording: false }); span.end(); return span as Span; diff --git a/packages/opentelemetry-tracing/test/export/ConsoleSpanExporter.test.ts b/packages/opentelemetry-tracing/test/export/ConsoleSpanExporter.test.ts index 0bd92c316b..c0224d85ca 100644 --- a/packages/opentelemetry-tracing/test/export/ConsoleSpanExporter.test.ts +++ b/packages/opentelemetry-tracing/test/export/ConsoleSpanExporter.test.ts @@ -49,7 +49,7 @@ describe('ConsoleSpanExporter', () => { new SimpleSpanProcessor(consoleExporter) ); - const span = basicTracerRegistry.getTracer().startSpan('foo'); + const span = basicTracerRegistry.getTracer('default').startSpan('foo'); span.addEvent('foobar'); span.end(); diff --git a/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts b/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts index c04da65db6..b37f18ac25 100644 --- a/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts +++ b/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts @@ -33,10 +33,10 @@ describe('InMemorySpanExporter', () => { }); it('should get finished spans', () => { - const root = registry.getTracer().startSpan('root'); - const child = registry.getTracer().startSpan('child', { parent: root }); + const root = registry.getTracer('default').startSpan('root'); + const child = registry.getTracer('default').startSpan('child', { parent: root }); const grandChild = registry - .getTracer() + .getTracer('default') .startSpan('grand-child', { parent: child }); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); @@ -58,9 +58,9 @@ describe('InMemorySpanExporter', () => { }); it('should shutdown the exorter', () => { - const root = registry.getTracer().startSpan('root'); + const root = registry.getTracer('default').startSpan('root'); registry - .getTracer() + .getTracer('default') .startSpan('child', { parent: root }) .end(); root.end(); @@ -70,7 +70,7 @@ describe('InMemorySpanExporter', () => { // after shutdown no new spans are accepted registry - .getTracer() + .getTracer('default') .startSpan('child1', { parent: root }) .end(); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); diff --git a/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts b/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts index 4ba1f9fc4e..c56d43e870 100644 --- a/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts +++ b/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts @@ -43,7 +43,7 @@ describe('SimpleSpanProcessor', () => { traceFlags: TraceFlags.SAMPLED, }; const span = new Span( - registry.getTracer(), + registry.getTracer('default'), 'span-name', spanContext, SpanKind.CLIENT @@ -66,7 +66,7 @@ describe('SimpleSpanProcessor', () => { traceFlags: TraceFlags.UNSAMPLED, }; const span = new Span( - registry.getTracer(), + registry.getTracer('default'), 'span-name', spanContext, SpanKind.CLIENT diff --git a/packages/opentelemetry-types/src/trace/tracer_registry.ts b/packages/opentelemetry-types/src/trace/tracer_registry.ts index ecd87d148b..ce2c36cdb1 100644 --- a/packages/opentelemetry-types/src/trace/tracer_registry.ts +++ b/packages/opentelemetry-types/src/trace/tracer_registry.ts @@ -27,5 +27,5 @@ export interface TracerRegistry { * * @returns Tracer A Tracer with the given name and version */ - getTracer(name?: string, version?: string): Tracer; + getTracer(name: string, version?: string): Tracer; } diff --git a/packages/opentelemetry-web/test/WebTracer.test.ts b/packages/opentelemetry-web/test/WebTracer.test.ts index 5d242ffd44..140571405c 100644 --- a/packages/opentelemetry-web/test/WebTracer.test.ts +++ b/packages/opentelemetry-web/test/WebTracer.test.ts @@ -44,7 +44,7 @@ describe('WebTracer', () => { it('should construct an instance with required only options', () => { const tracer = new WebTracerRegistry( Object.assign({}, defaultOptions) - ).getTracer(); + ).getTracer('default'); assert.ok(tracer instanceof Tracer); }); @@ -87,7 +87,7 @@ describe('WebTracer', () => { it('should correctly return the scopes for 2 parallel actions', () => { const webTracerWithZone = new WebTracerRegistry({ scopeManager: new ZoneScopeManager(), - }).getTracer(); + }).getTracer('default'); const rootSpan = webTracerWithZone.startSpan('rootSpan'); From 9d95597bf86dc065f9130c275171bbaab4ed376c Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Tue, 17 Dec 2019 10:28:52 -0500 Subject: [PATCH 09/24] chore: lint --- .../test/NodeTracer.test.ts | 51 +++++++++++++++---- .../test/functionals/https-disable.test.ts | 4 +- .../test/functionals/https-enable.test.ts | 13 +++-- .../test/functionals/https-package.test.ts | 8 +-- .../test/integrations/https-enable.test.ts | 7 ++- .../test/Shim.test.ts | 4 +- .../test/export/InMemorySpanExporter.test.ts | 4 +- 7 files changed, 67 insertions(+), 24 deletions(-) diff --git a/packages/opentelemetry-node/test/NodeTracer.test.ts b/packages/opentelemetry-node/test/NodeTracer.test.ts index ec31ef4ed3..757be77348 100644 --- a/packages/opentelemetry-node/test/NodeTracer.test.ts +++ b/packages/opentelemetry-node/test/NodeTracer.test.ts @@ -169,7 +169,10 @@ describe('NodeTracerRegistry', () => { describe('.getCurrentSpan()', () => { it('should return undefined with AsyncHooksScopeManager when no span started', () => { registry = new NodeTracerRegistry({}); - assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), undefined); + assert.deepStrictEqual( + registry.getTracer('default').getCurrentSpan(), + undefined + ); }); }); @@ -178,23 +181,35 @@ describe('NodeTracerRegistry', () => { registry = new NodeTracerRegistry({}); const span = registry.getTracer('default').startSpan('my-span'); registry.getTracer('default').withSpan(span, () => { - assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), span); + assert.deepStrictEqual( + registry.getTracer('default').getCurrentSpan(), + span + ); return done(); }); - assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), undefined); + assert.deepStrictEqual( + registry.getTracer('default').getCurrentSpan(), + undefined + ); }); it('should run scope with AsyncHooksScopeManager scope manager with multiple spans', done => { registry = new NodeTracerRegistry({}); const span = registry.getTracer('default').startSpan('my-span'); registry.getTracer('default').withSpan(span, () => { - assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), span); + assert.deepStrictEqual( + registry.getTracer('default').getCurrentSpan(), + span + ); const span1 = registry .getTracer('default') .startSpan('my-span1', { parent: span }); registry.getTracer('default').withSpan(span1, () => { - assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), span1); + assert.deepStrictEqual( + registry.getTracer('default').getCurrentSpan(), + span1 + ); assert.deepStrictEqual( span1.context().traceId, span.context().traceId @@ -204,7 +219,10 @@ describe('NodeTracerRegistry', () => { }); // when span ended. // @todo: below check is not running. - assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), undefined); + assert.deepStrictEqual( + registry.getTracer('default').getCurrentSpan(), + undefined + ); }); it('should find correct scope with promises', done => { @@ -213,12 +231,18 @@ describe('NodeTracerRegistry', () => { registry.getTracer('default').withSpan(span, async () => { for (let i = 0; i < 3; i++) { await sleep(5).then(() => { - assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), span); + assert.deepStrictEqual( + registry.getTracer('default').getCurrentSpan(), + span + ); }); } return done(); }); - assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), undefined); + assert.deepStrictEqual( + registry.getTracer('default').getCurrentSpan(), + undefined + ); }); }); @@ -227,7 +251,10 @@ describe('NodeTracerRegistry', () => { const registry = new NodeTracerRegistry({}); const span = registry.getTracer('default').startSpan('my-span'); const fn = () => { - assert.deepStrictEqual(registry.getTracer('default').getCurrentSpan(), span); + assert.deepStrictEqual( + registry.getTracer('default').getCurrentSpan(), + span + ); return done(); }; const patchedFn = registry.getTracer('default').bind(fn, span); @@ -239,7 +266,8 @@ describe('NodeTracerRegistry', () => { it('should get default binary formatter', () => { registry = new NodeTracerRegistry({}); assert.ok( - registry.getTracer('default').getBinaryFormat() instanceof BinaryTraceContext + registry.getTracer('default').getBinaryFormat() instanceof + BinaryTraceContext ); }); }); @@ -248,7 +276,8 @@ describe('NodeTracerRegistry', () => { it('should get default HTTP text formatter', () => { registry = new NodeTracerRegistry({}); assert.ok( - registry.getTracer('default').getHttpTextFormat() instanceof HttpTraceContext + registry.getTracer('default').getHttpTextFormat() instanceof + HttpTraceContext ); }); }); diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts index 1a6ea75b4d..826fc5d72c 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-disable.test.ts @@ -26,7 +26,7 @@ import { plugin } from '../../src/https'; import { DummyPropagation } from '../utils/DummyPropagation'; import { httpsRequest } from '../utils/httpsRequest'; import { NodeTracerRegistry } from '@opentelemetry/node'; -import * as types from "@opentelemetry/types" +import * as types from '@opentelemetry/types'; describe('HttpsPlugin', () => { let server: https.Server; @@ -46,7 +46,7 @@ describe('HttpsPlugin', () => { nock.enableNetConnect(); plugin.enable((https as unknown) as Http, registry, registry.logger); - tracer = plugin["_tracer"]; + tracer = plugin['_tracer']; // Ensure that https module is patched. assert.strictEqual(https.Server.prototype.emit.__wrapped, true); server = https.createServer( diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts index 2870854494..246789c8d1 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts @@ -100,7 +100,12 @@ describe('HttpsPlugin', () => { ], applyCustomAttributesOnSpan: customAttributeFunction, }; - plugin.enable((https as unknown) as Http, registry, registry.logger, config); + plugin.enable( + (https as unknown) as Http, + registry, + registry.logger, + config + ); server = https.createServer( { key: fs.readFileSync('test/fixtures/server-key.pem'), @@ -213,7 +218,7 @@ describe('HttpsPlugin', () => { const testPath = '/outgoing/rootSpan/childs/1'; doNock(hostname, testPath, 200, 'Ok'); const name = 'TestRootSpan'; - const tracer = registry.getTracer("test-https"); + const tracer = registry.getTracer('test-https'); const span = tracer.startSpan(name); return tracer.withSpan(span, async () => { const result = await httpsRequest.get( @@ -257,7 +262,7 @@ describe('HttpsPlugin', () => { httpErrorCodes[i].toString() ); const name = 'TestRootSpan'; - const tracer = registry.getTracer("test-https"); + const tracer = registry.getTracer('test-https'); const span = tracer.startSpan(name); return tracer.withSpan(span, async () => { const result = await httpsRequest.get( @@ -297,7 +302,7 @@ describe('HttpsPlugin', () => { const num = 5; doNock(hostname, testPath, 200, 'Ok', num); const name = 'TestRootSpan'; - const tracer = registry.getTracer("test-https"); + const tracer = registry.getTracer('test-https'); const span = tracer.startSpan(name); await tracer.withSpan(span, async () => { for (let i = 0; i < num; i++) { diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-package.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-package.test.ts index 66187bd92f..63769e16f8 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-package.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-package.test.ts @@ -90,10 +90,10 @@ describe('Packages', () => { const urlparsed = url.parse( name === 'got' && process.versions.node.startsWith('12') ? // there is an issue with got 9.6 version and node 12 when redirecting so url above will not work - // https://github.com/nock/nock/pull/1551 - // https://github.com/sindresorhus/got/commit/bf1aa5492ae2bc78cbbec6b7d764906fb156e6c2#diff-707a4781d57c42085155dcb27edb9ccbR258 - // TODO: check if this is still the case when new version - 'https://www.google.com' + // https://github.com/nock/nock/pull/1551 + // https://github.com/sindresorhus/got/commit/bf1aa5492ae2bc78cbbec6b7d764906fb156e6c2#diff-707a4781d57c42085155dcb27edb9ccbR258 + // TODO: check if this is still the case when new version + 'https://www.google.com' : `https://www.google.com/search?q=axios&oq=axios&aqs=chrome.0.69i59l2j0l3j69i60.811j0j7&sourceid=chrome&ie=UTF-8` ); const result = await httpPackage.get(urlparsed.href!); diff --git a/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts index 2f35da9178..d51f3716df 100644 --- a/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts @@ -83,7 +83,12 @@ describe('HttpsPlugin Integration tests', () => { try { plugin.disable(); } catch (e) {} - plugin.enable((https as unknown) as Http, registry, registry.logger, config); + plugin.enable( + (https as unknown) as Http, + registry, + registry.logger, + config + ); }); after(() => { diff --git a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts index e7a8edc492..67434be058 100644 --- a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts +++ b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts @@ -23,7 +23,9 @@ import { performance } from 'perf_hooks'; describe('OpenTracing Shim', () => { const registry = new BasicTracerRegistry(); - const shimTracer: opentracing.Tracer = new TracerShim(registry.getTracer('default')); + const shimTracer: opentracing.Tracer = new TracerShim( + registry.getTracer('default') + ); opentracing.initGlobalTracer(shimTracer); describe('TracerShim', () => { diff --git a/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts b/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts index b37f18ac25..4eca595acd 100644 --- a/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts +++ b/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts @@ -34,7 +34,9 @@ describe('InMemorySpanExporter', () => { it('should get finished spans', () => { const root = registry.getTracer('default').startSpan('root'); - const child = registry.getTracer('default').startSpan('child', { parent: root }); + const child = registry + .getTracer('default') + .startSpan('child', { parent: root }); const grandChild = registry .getTracer('default') .startSpan('grand-child', { parent: child }); From 3237f99a0f8466a077e46b32d508e902c11bbaf2 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Tue, 17 Dec 2019 10:32:58 -0500 Subject: [PATCH 10/24] chore: update examples for required tracer name --- examples/basic-tracer-node/index.js | 5 +++-- examples/basic-tracer-node/multi_exporter.js | 5 +++-- examples/dns/client.js | 2 +- examples/grpc/client.js | 2 +- examples/grpc/server.js | 2 +- examples/grpc_dynamic_codegen/capitalize_client.js | 2 +- examples/grpc_dynamic_codegen/capitalize_server.js | 2 +- examples/http/client.js | 2 +- examples/http/server.js | 2 +- examples/https/client.js | 4 ++-- examples/https/server.js | 2 +- examples/mysql/client.js | 2 +- examples/mysql/server.js | 2 +- examples/redis/client.js | 2 +- examples/redis/server.js | 2 +- examples/tracer-web/index.js | 2 +- 16 files changed, 21 insertions(+), 19 deletions(-) diff --git a/examples/basic-tracer-node/index.js b/examples/basic-tracer-node/index.js index 049d497854..977f36cea2 100644 --- a/examples/basic-tracer-node/index.js +++ b/examples/basic-tracer-node/index.js @@ -27,9 +27,10 @@ registry.addSpanProcessor(new SimpleSpanProcessor(exporter)); // Initialize the OpenTelemetry APIs to use the BasicTracer 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); } @@ -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 }); diff --git a/examples/basic-tracer-node/multi_exporter.js b/examples/basic-tracer-node/multi_exporter.js index 6c12a24c57..c6f5c64f6f 100644 --- a/examples/basic-tracer-node/multi_exporter.js +++ b/examples/basic-tracer-node/multi_exporter.js @@ -26,9 +26,10 @@ tracer.addSpanProcessor(new SimpleSpanProcessor(collectorExporter)); // Initialize the OpenTelemetry APIs to use the BasicTracer bindings opentelemetry.initGlobalTracer(tracer); +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); } @@ -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 }); diff --git a/examples/dns/client.js b/examples/dns/client.js index 83399387ab..317b5b9e46 100644 --- a/examples/dns/client.js +++ b/examples/dns/client.js @@ -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() { diff --git a/examples/grpc/client.js b/examples/grpc/client.js index 585f61873c..4bc65bc976 100644 --- a/examples/grpc/client.js +++ b/examples/grpc/client.js @@ -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() { diff --git a/examples/grpc/server.js b/examples/grpc/server.js index b1e3c407f6..2a411ba40b 100644 --- a/examples/grpc/server.js +++ b/examples/grpc/server.js @@ -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'); diff --git a/examples/grpc_dynamic_codegen/capitalize_client.js b/examples/grpc_dynamic_codegen/capitalize_client.js index 0b7b360f0e..a994307854 100644 --- a/examples/grpc_dynamic_codegen/capitalize_client.js +++ b/examples/grpc_dynamic_codegen/capitalize_client.js @@ -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 }; diff --git a/examples/grpc_dynamic_codegen/capitalize_server.js b/examples/grpc_dynamic_codegen/capitalize_server.js index c18731d4c7..79dcd3c0fe 100644 --- a/examples/grpc_dynamic_codegen/capitalize_server.js +++ b/examples/grpc_dynamic_codegen/capitalize_server.js @@ -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) { diff --git a/examples/http/client.js b/examples/http/client.js index aa812785a1..8b299b98ff 100644 --- a/examples/http/client.js +++ b/examples/http/client.js @@ -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() { diff --git a/examples/http/server.js b/examples/http/server.js index 322a144a65..d3c0046bf9 100644 --- a/examples/http/server.js +++ b/examples/http/server.js @@ -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) { diff --git a/examples/https/client.js b/examples/https/client.js index aef9966d31..40ebc94d3f 100644 --- a/examples/https/client.js +++ b/examples/https/client.js @@ -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() { @@ -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. diff --git a/examples/https/server.js b/examples/https/server.js index 1d6d208860..7280c8f61f 100644 --- a/examples/https/server.js +++ b/examples/https/server.js @@ -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) { diff --git a/examples/mysql/client.js b/examples/mysql/client.js index 8455511268..e080ab994a 100644 --- a/examples/mysql/client.js +++ b/examples/mysql/client.js @@ -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-mysql-http-client'); /** A function which makes requests and handles response. */ function makeRequest() { diff --git a/examples/mysql/server.js b/examples/mysql/server.js index 0dc6c10e9c..1ba4eb7258 100644 --- a/examples/mysql/server.js +++ b/examples/mysql/server.js @@ -11,7 +11,7 @@ config.setupTracerAndExporters('http-mysql-server-service'); const mysql = require('mysql'); const http = require('http'); -const tracer = opentelemetry.getTracer(); +const tracer = opentelemetry.getTracer('example-mysql-http-server'); const pool = mysql.createPool({ host : 'localhost', diff --git a/examples/redis/client.js b/examples/redis/client.js index 8215c8e575..191effe612 100644 --- a/examples/redis/client.js +++ b/examples/redis/client.js @@ -4,7 +4,7 @@ const opentelemetry = require('@opentelemetry/core'); const types = require('@opentelemetry/types'); const config = require('./setup'); config.setupTracerAndExporters('redis-client-service'); -const tracer = opentelemetry.getTracer(); +const tracer = opentelemetry.getTracer('example-redis-client'); const axios = require('axios').default; function makeRequest() { diff --git a/examples/redis/server.js b/examples/redis/server.js index 535df1c014..33744b2f74 100644 --- a/examples/redis/server.js +++ b/examples/redis/server.js @@ -4,7 +4,7 @@ const opentelemetry = require('@opentelemetry/core'); const config = require('./setup'); config.setupTracerAndExporters('redis-server-service'); -const tracer = opentelemetry.getTracer(); +const tracer = opentelemetry.getTracer('example-redis-server'); // Require in rest of modules const express = require('express'); diff --git a/examples/tracer-web/index.js b/examples/tracer-web/index.js index f64e161803..87e3068360 100644 --- a/examples/tracer-web/index.js +++ b/examples/tracer-web/index.js @@ -20,7 +20,7 @@ const registryWithZone = new WebTracerRegistry({ registryWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); registryWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter())); -const tracerWithZone = registryWithZone.getTracer(); +const tracerWithZone = registryWithZone.getTracer('example-tracer-web'); console.log('Current span is window', tracerWithZone.getCurrentSpan() === window); // example of keeping track of scope between async operations From 643e28608e89f68573a626b132dbe286f414e7c8 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Tue, 17 Dec 2019 17:25:06 -0500 Subject: [PATCH 11/24] chore: remove unused tracer delegate --- packages/opentelemetry-core/src/index.ts | 1 - .../src/trace/TracerDelegate.ts | 101 --------------- .../test/trace/TracerDelegate.test.ts | 117 ------------------ 3 files changed, 219 deletions(-) delete mode 100644 packages/opentelemetry-core/src/trace/TracerDelegate.ts delete mode 100644 packages/opentelemetry-core/test/trace/TracerDelegate.test.ts diff --git a/packages/opentelemetry-core/src/index.ts b/packages/opentelemetry-core/src/index.ts index 2c973ede65..b195ea4b11 100644 --- a/packages/opentelemetry-core/src/index.ts +++ b/packages/opentelemetry-core/src/index.ts @@ -31,6 +31,5 @@ export * from './trace/NoopTracerRegistry'; export * from './trace/NoRecordingSpan'; export * from './trace/sampler/ProbabilitySampler'; export * from './trace/spancontext-utils'; -export * from './trace/TracerDelegate'; export * from './trace/TraceState'; export * from './metrics/NoopMeter'; diff --git a/packages/opentelemetry-core/src/trace/TracerDelegate.ts b/packages/opentelemetry-core/src/trace/TracerDelegate.ts deleted file mode 100644 index 529862f98f..0000000000 --- a/packages/opentelemetry-core/src/trace/TracerDelegate.ts +++ /dev/null @@ -1,101 +0,0 @@ -/*! - * 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'; - -// Acts a bridge to the global tracer that can be safely called before the -// global tracer is initialized. The purpose of the delegation is to avoid the -// sometimes nearly intractable initialization order problems that can arise in -// applications with a complex set of dependencies. Also allows for the tracer -// to be changed/disabled during runtime without needing to change reference -// to the global tracer -export class TracerDelegate implements types.Tracer { - private _currentTracer: types.Tracer; - private readonly _tracer: types.Tracer | null; - private readonly _fallbackTracer: types.Tracer; - - // Wrap a tracer with a TracerDelegate. Provided tracer becomes the default - // fallback tracer for when a global tracer has not been initialized - constructor(tracer?: types.Tracer, fallbackTracer?: types.Tracer) { - this._tracer = tracer || null; - this._fallbackTracer = fallbackTracer || new NoopTracer(); - this._currentTracer = this._tracer || this._fallbackTracer; // equivalent to this.start() - } - - // Begin using the user provided tracer. Stop always falling back to fallback tracer - start(): void { - this._currentTracer = this._tracer || this._fallbackTracer; - } - - // Stop the delegate from using the provided tracer. Begin to use the fallback tracer - stop(): void { - this._currentTracer = this._fallbackTracer; - } - - // -- Tracer interface implementation below -- // - - getCurrentSpan(): types.Span | undefined { - return this._currentTracer.getCurrentSpan.apply( - this._currentTracer, - // tslint:disable-next-line:no-any - arguments as any - ); - } - - bind(target: T, span?: types.Span): T { - return (this._currentTracer.bind.apply( - this._currentTracer, - // tslint:disable-next-line:no-any - arguments as any - ) as unknown) as T; - } - - startSpan(name: string, options?: types.SpanOptions): types.Span { - return this._currentTracer.startSpan.apply( - this._currentTracer, - // tslint:disable-next-line:no-any - arguments as any - ); - } - - withSpan ReturnType>( - span: types.Span, - fn: T - ): ReturnType { - return this._currentTracer.withSpan.apply( - this._currentTracer, - // tslint:disable-next-line:no-any - arguments as any - ); - } - - getBinaryFormat(): types.BinaryFormat { - return this._currentTracer.getBinaryFormat.apply( - this._currentTracer, - // tslint:disable-next-line:no-any - arguments as any - ); - } - - getHttpTextFormat(): types.HttpTextFormat { - return this._currentTracer.getHttpTextFormat.apply( - this._currentTracer, - // tslint:disable-next-line:no-any - arguments as any - ); - } -} diff --git a/packages/opentelemetry-core/test/trace/TracerDelegate.test.ts b/packages/opentelemetry-core/test/trace/TracerDelegate.test.ts deleted file mode 100644 index cc8772f263..0000000000 --- a/packages/opentelemetry-core/test/trace/TracerDelegate.test.ts +++ /dev/null @@ -1,117 +0,0 @@ -/*! - * 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 assert from 'assert'; -import * as types from '@opentelemetry/types'; -import { TracerDelegate } from '../../src/trace/TracerDelegate'; -import { NoopTracer, NoopSpan } from '../../src'; -import { TraceFlags } from '@opentelemetry/types'; - -describe('TracerDelegate', () => { - const functions = [ - 'getCurrentSpan', - 'startSpan', - 'withSpan', - 'bind', - 'getBinaryFormat', - 'getHttpTextFormat', - ]; - const spanContext = { - traceId: 'd4cda95b652f4a1592b449d5929fda1b', - spanId: '6e0c63257de34c92', - traceFlags: TraceFlags.UNSAMPLED, - }; - - describe('constructor', () => { - it('should not crash with default constructor', () => { - functions.forEach(fn => { - const tracer = new TracerDelegate(); - try { - ((tracer as unknown) as { [fn: string]: Function })[fn](); // Try to run the function - assert.ok(true, fn); - } catch (err) { - if (err.message !== 'Method not implemented.') { - assert.ok(true, fn); - } - } - }); - }); - - it('should allow fallback tracer to be set', () => { - const dummyTracer = new DummyTracer(); - const tracerDelegate = new TracerDelegate(dummyTracer); - - tracerDelegate.startSpan('foo'); - assert.deepStrictEqual(dummyTracer.spyCounter, 1); - }); - - it('should use user provided tracer if provided', () => { - const dummyTracer = new DummyTracer(); - const tracerDelegate = new TracerDelegate(dummyTracer); - - tracerDelegate.startSpan('foo'); - assert.deepStrictEqual(dummyTracer.spyCounter, 1); - }); - }); - - describe('.start/.stop()', () => { - it('should use the fallback tracer when stop is called', () => { - const dummyTracerUser = new DummyTracer(); - const dummyTracerFallback = new DummyTracer(); - const tracerDelegate = new TracerDelegate( - dummyTracerUser, - dummyTracerFallback - ); - - tracerDelegate.stop(); - tracerDelegate.startSpan('fallback'); - assert.deepStrictEqual(dummyTracerUser.spyCounter, 0); - assert.deepStrictEqual(dummyTracerFallback.spyCounter, 1); - }); - - it('should use the user tracer when start is called', () => { - const dummyTracerUser = new DummyTracer(); - const dummyTracerFallback = new DummyTracer(); - const tracerDelegate = new TracerDelegate( - dummyTracerUser, - dummyTracerFallback - ); - - tracerDelegate.stop(); - tracerDelegate.startSpan('fallback'); - assert.deepStrictEqual(dummyTracerUser.spyCounter, 0); - assert.deepStrictEqual(dummyTracerFallback.spyCounter, 1); - - tracerDelegate.start(); - tracerDelegate.startSpan('user'); - assert.deepStrictEqual(dummyTracerUser.spyCounter, 1); - assert.deepStrictEqual( - dummyTracerFallback.spyCounter, - 1, - 'Only user tracer counter is incremented' - ); - }); - }); - - class DummyTracer extends NoopTracer { - spyCounter = 0; - - startSpan(name: string, options?: types.SpanOptions | undefined) { - this.spyCounter = this.spyCounter + 1; - return new NoopSpan(spanContext); - } - } -}); From 41c1168d99d810a85cb7a4156a97a89de3f3da0b Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 23 Dec 2019 09:23:56 -0500 Subject: [PATCH 12/24] chore: remove references to basic tracer --- benchmark/tracer.js | 18 +++++++++--------- examples/basic-tracer-node/index.js | 2 +- examples/basic-tracer-node/multi_exporter.js | 14 +++++++------- examples/dns/setup.js | 2 +- examples/grpc/setup.js | 2 +- examples/grpc_dynamic_codegen/setup.js | 2 +- examples/http/setup.js | 2 +- examples/https/setup.js | 2 +- examples/mysql/setup.js | 2 +- examples/redis/setup.js | 2 +- .../opentelemetry-exporter-collector/README.md | 8 ++++---- packages/opentelemetry-tracing/README.md | 15 ++++++--------- .../src/BasicTracerRegistry.ts | 3 +++ 13 files changed, 37 insertions(+), 37 deletions(-) diff --git a/benchmark/tracer.js b/benchmark/tracer.js index 2dda2a8b68..83700b0171 100644 --- a/benchmark/tracer.js +++ b/benchmark/tracer.js @@ -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'); @@ -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(); @@ -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(); diff --git a/examples/basic-tracer-node/index.js b/examples/basic-tracer-node/index.js index 977f36cea2..086d1fe158 100644 --- a/examples/basic-tracer-node/index.js +++ b/examples/basic-tracer-node/index.js @@ -25,7 +25,7 @@ const registry = new BasicTracerRegistry(); // Configure span processor to send spans to the provided exporter registry.addSpanProcessor(new SimpleSpanProcessor(exporter)); -// Initialize the OpenTelemetry APIs to use the BasicTracer bindings +// Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); const tracer = opentelemetry.getTracer('example-basic-tracer-node') diff --git a/examples/basic-tracer-node/multi_exporter.js b/examples/basic-tracer-node/multi_exporter.js index c6f5c64f6f..2d7723397e 100644 --- a/examples/basic-tracer-node/multi_exporter.js +++ b/examples/basic-tracer-node/multi_exporter.js @@ -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({ @@ -14,18 +14,18 @@ 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. diff --git a/examples/dns/setup.js b/examples/dns/setup.js index ef5f4bad87..f5ef407f2a 100644 --- a/examples/dns/setup.js +++ b/examples/dns/setup.js @@ -32,7 +32,7 @@ function setupTracerAndExporters(service) { registry.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the BasicTracer bindings + // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); } diff --git a/examples/grpc/setup.js b/examples/grpc/setup.js index 3b3e04273b..7a7fc3eafe 100644 --- a/examples/grpc/setup.js +++ b/examples/grpc/setup.js @@ -31,7 +31,7 @@ function setupTracerAndExporters(service) { registry.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the BasicTracer bindings + // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); } diff --git a/examples/grpc_dynamic_codegen/setup.js b/examples/grpc_dynamic_codegen/setup.js index 940ebba0b4..4fd8b0a8b6 100644 --- a/examples/grpc_dynamic_codegen/setup.js +++ b/examples/grpc_dynamic_codegen/setup.js @@ -33,7 +33,7 @@ function setupTracerAndExporters(service) { // and optimization, especially in production. registry.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the BasicTracer bindings + // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); } diff --git a/examples/http/setup.js b/examples/http/setup.js index 08f02a04fb..770cdd5dfd 100644 --- a/examples/http/setup.js +++ b/examples/http/setup.js @@ -23,7 +23,7 @@ function setupTracerAndExporters(service) { registry.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the BasicTracer bindings + // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); } diff --git a/examples/https/setup.js b/examples/https/setup.js index 4b52347212..ef426a90b5 100644 --- a/examples/https/setup.js +++ b/examples/https/setup.js @@ -23,7 +23,7 @@ function setupTracerAndExporters(service) { registry.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the BasicTracer bindings + // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); } diff --git a/examples/mysql/setup.js b/examples/mysql/setup.js index 0bf941cd68..e3f9ce3f41 100644 --- a/examples/mysql/setup.js +++ b/examples/mysql/setup.js @@ -27,7 +27,7 @@ function setupTracerAndExporters(service) { serviceName: service, }))); - // Initialize the OpenTelemetry APIs to use the BasicTracer bindings + // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); } diff --git a/examples/redis/setup.js b/examples/redis/setup.js index 08f02a04fb..770cdd5dfd 100644 --- a/examples/redis/setup.js +++ b/examples/redis/setup.js @@ -23,7 +23,7 @@ function setupTracerAndExporters(service) { registry.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the BasicTracer bindings + // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); } diff --git a/packages/opentelemetry-exporter-collector/README.md b/packages/opentelemetry-exporter-collector/README.md index 5e1c13f8e4..867b344692 100644 --- a/packages/opentelemetry-exporter-collector/README.md +++ b/packages/opentelemetry-exporter-collector/README.md @@ -35,18 +35,18 @@ opentelemetry.initGlobalTracer(tracer); ## Usage in Node ```js const opentelemetry = require('@opentelemetry/core'); -const { BasicTracer, SimpleSpanProcessor } = require('@opentelemetry/tracing'); +const { BasicTracerRegistry, SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { CollectorExporter } = require('@opentelemetry/exporter-collector'); const collectorOptions = { url: '' // url is optional and can be omitted - default is http://localhost:55678/v1/trace }; -const tracer = new BasicTracer(); +const registry = new BasicTracerRegistry(); const exporter = new CollectorExporter(collectorOptions); -tracer.addSpanProcessor(new SimpleSpanProcessor(exporter)); +registry.addSpanProcessor(new SimpleSpanProcessor(exporter)); -opentelemetry.initGlobalTracer(tracer); +opentelemetry.initGlobalTracerRegistry(registry); ``` diff --git a/packages/opentelemetry-tracing/README.md b/packages/opentelemetry-tracing/README.md index 92bc676af2..796567fb21 100644 --- a/packages/opentelemetry-tracing/README.md +++ b/packages/opentelemetry-tracing/README.md @@ -25,22 +25,19 @@ npm install --save @opentelemetry/tracing ```js const opentelemetry = require('@opentelemetry/core'); -const { BasicTracer } = require('@opentelemetry/tracing'); +const { BasicTracerRegistry } = require('@opentelemetry/tracing'); -// To start a trace, you first need to initialize the Tracer. -// NOTE: the default OpenTelemetry tracer does not record any tracing information. -const tracer = new BasicTracer(); - -// Initialize the OpenTelemetry APIs to use the BasicTracer bindings -opentelemetry.initGlobalTracer(tracer); +// To start a trace, you first need to initialize the Tracer registry. +// NOTE: the default OpenTelemetry tracer registry does not record any tracing information. +opentelemetry.initGlobalTracer(new BasicTracerRegistry()); // To create a span in a trace, we used the global singleton tracer to start a new span. const span = opentelemetry.getTracer('default').startSpan('foo'); -// Create an Attributes +// Set a span attribute span.setAttribute('key', 'value'); -// We must end the spans so they becomes available for exporting. +// We must end the spans so they become available for exporting. span.end(); ``` diff --git a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts index 6f8759e171..b646b4a516 100644 --- a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts +++ b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts @@ -23,6 +23,9 @@ import { MultiSpanProcessor } from './MultiSpanProcessor'; import { NoopSpanProcessor } from './NoopSpanProcessor'; import { TracerConfig } from './types'; +/** + * This class represents a basic tracer registry which platform libraries can extend + */ export class BasicTracerRegistry implements types.TracerRegistry { private readonly _registeredSpanProcessors: SpanProcessor[] = []; private readonly _tracers: Map = new Map(); From 6a94efedc8d22ff27594190952941fb4b58b1a42 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 23 Dec 2019 09:33:07 -0500 Subject: [PATCH 13/24] chore: remove references to NodeTracer --- examples/opentracing-shim/shim.js | 8 ++--- packages/opentelemetry-node/README.md | 32 +++++++++---------- packages/opentelemetry-plugin-dns/README.md | 6 ++-- packages/opentelemetry-plugin-grpc/README.md | 8 ++--- packages/opentelemetry-plugin-http/README.md | 8 ++--- packages/opentelemetry-plugin-https/README.md | 8 ++--- .../README.md | 8 ++--- packages/opentelemetry-plugin-redis/README.md | 8 ++--- 8 files changed, 43 insertions(+), 43 deletions(-) diff --git a/examples/opentracing-shim/shim.js b/examples/opentracing-shim/shim.js index 8579eb73a4..8efb1c2a8b 100644 --- a/examples/opentracing-shim/shim.js +++ b/examples/opentracing-shim/shim.js @@ -1,17 +1,17 @@ "use strict"; -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 { TracerShim } = require("@opentelemetry/shim-opentracing"); function shim(serviceName) { - const tracer = new NodeTracer(); + const registry = new NodeTracerRegistry(); - tracer.addSpanProcessor(new SimpleSpanProcessor(getExporter(serviceName))); + registry.addSpanProcessor(new SimpleSpanProcessor(getExporter(serviceName))); - return new TracerShim(tracer); + return new TracerShim(registry.getTracer("opentracing-shim")); } function getExporter(serviceName) { diff --git a/packages/opentelemetry-node/README.md b/packages/opentelemetry-node/README.md index 8a24c5b0d7..8e6c195c32 100644 --- a/packages/opentelemetry-node/README.md +++ b/packages/opentelemetry-node/README.md @@ -11,14 +11,14 @@ For manual instrumentation see the [@opentelemetry/tracing](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-tracing) package. ## How does automated instrumentation work? -This package exposes a `NodeTracer` that will automatically hook into the module loader of Node.js. +This package exposes a `NodeTracerRegistry` that will automatically hook into the module loader of Node.js. -For this to work, please make sure that `NodeTracer` is initialized before any other module of your application, (like `http` or `express`) is loaded. +For this to work, please make sure that `NodeTracerRegistry` is initialized before any other module of your application, (like `http` or `express`) is loaded. OpenTelemetry comes with a growing number of instrumentation plugins for well know modules (see [supported modules](https://github.com/open-telemetry/opentelemetry-js#plugins)) and an API to create custom plugins (see [the plugin developer guide](https://github.com/open-telemetry/opentelemetry-js/blob/master/doc/plugin-guide.md)). -Whenever a module is loaded `NodeTracer` will check if a matching instrumentation plugin has been installed. +Whenever a module is loaded `NodeTracerRegistry` will check if a matching instrumentation plugin has been installed. > **Please note:** This module does *not* bundle any plugins. They need to be installed separately. @@ -34,7 +34,7 @@ This instrumentation code will automatically In short, this means that this module will use provided plugins to automatically instrument your application to produce spans and provide end-to-end tracing by just adding a few lines of code. ## Creating custom spans on top of auto-instrumentation -Additionally to automated instrumentation, `NodeTracer` exposes the same API as [@opentelemetry/tracing](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-tracing), allowing creating custom spans if needed. +Additionally to automated instrumentation, `NodeTracerRegistry` exposes the same API as [@opentelemetry/tracing](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-tracing), allowing creating custom spans if needed. ## Installation @@ -50,14 +50,14 @@ npm install --save @opentelemetry/plugin-https ## Usage -The following code will configure the `NodeTracer` to instrument `http` using `@opentelemetry/plugin-http`. +The following code will configure the `NodeTracerRegistry` to instrument `http` using `@opentelemetry/plugin-http`. ```js const opentelemetry = require('@opentelemetry/core'); -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -// Create and configure NodeTracer -const tracer = new NodeTracer({ +// Create and configure NodeTracerRegistry +const registry = new NodeTracerRegistry({ plugins: { http: { enabled: true, @@ -68,25 +68,25 @@ const tracer = new NodeTracer({ } }); -// Initialize the tracer -opentelemetry.initGlobalTracer(tracer); +// Initialize the registry +opentelemetry.initGlobalTracerRegistry(registry); // Your application code - http will automatically be instrumented if // @opentelemetry/plugin-http is present const http = require('http'); ``` -To enable instrumentation for all [supported modules](https://github.com/open-telemetry/opentelemetry-js#plugins), create an instance of `NodeTracer` without providing any plugin configuration to the constructor. +To enable instrumentation for all [supported modules](https://github.com/open-telemetry/opentelemetry-js#plugins), create an instance of `NodeTracerRegistry` without providing any plugin configuration to the constructor. ```js const opentelemetry = require('@opentelemetry/core'); -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -// Create and initialize NodeTracer -const tracer = new NodeTracer(); +// Create and initialize NodeTracerRegistry +const registry = new NodeTracerRegistry(); -// Initialize the tracer -opentelemetry.initGlobalTracer(tracer); +// Initialize the registry +opentelemetry.initGlobalTracerRegistry(registry); // Your application code // ... diff --git a/packages/opentelemetry-plugin-dns/README.md b/packages/opentelemetry-plugin-dns/README.md index 50bf77fd7c..3cac446759 100644 --- a/packages/opentelemetry-plugin-dns/README.md +++ b/packages/opentelemetry-plugin-dns/README.md @@ -18,9 +18,9 @@ npm install --save @opentelemetry/plugin-dns ## Usage ```js -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -const tracer = new NodeTracer({ +const registry = new NodeTracerRegistry({ plugins: { dns: { enabled: true, @@ -37,7 +37,7 @@ const tracer = new NodeTracer({ If you use Zipkin, you must use `ignoreHostnames` in order to not trace those calls. If the server is local. You can set : ``` -const tracer = new NodeTracer({ +const registry = new NodeTracerRegistry({ plugins: { dns: { enabled: true, diff --git a/packages/opentelemetry-plugin-grpc/README.md b/packages/opentelemetry-plugin-grpc/README.md index d421029dbd..e728f8e694 100644 --- a/packages/opentelemetry-plugin-grpc/README.md +++ b/packages/opentelemetry-plugin-grpc/README.md @@ -22,9 +22,9 @@ OpenTelemetry gRPC Instrumentation allows the user to automatically collect trac To load a specific plugin (**gRPC** in this case), specify it in the Node Tracer's configuration. ```javascript -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -const tracer = new NodeTracer({ +const registry = new NodeTracerRegistry({ plugins: { grpc: { enabled: true, @@ -37,9 +37,9 @@ const tracer = new NodeTracer({ To load all the [supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. ```javascript -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -const tracer = new NodeTracer(); +const registry = new NodeTracerRegistry(); ``` See [examples/grpc](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/grpc) for a short example. diff --git a/packages/opentelemetry-plugin-http/README.md b/packages/opentelemetry-plugin-http/README.md index 73b5d4bad9..e646c385e7 100644 --- a/packages/opentelemetry-plugin-http/README.md +++ b/packages/opentelemetry-plugin-http/README.md @@ -22,9 +22,9 @@ OpenTelemetry HTTP Instrumentation allows the user to automatically collect trac To load a specific plugin (HTTP in this case), specify it in the Node Tracer's configuration. ```js -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -const tracer = new NodeTracer({ +const registry = new NodeTracerRegistry({ plugins: { http: { enabled: true, @@ -38,9 +38,9 @@ const tracer = new NodeTracer({ To load all the [supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. ```js -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -const tracer = new NodeTracer(); +const registry = new NodeTracerRegistry(); ``` See [examples/http](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/http) for a short example. diff --git a/packages/opentelemetry-plugin-https/README.md b/packages/opentelemetry-plugin-https/README.md index c8aff10265..a47a71a6ca 100644 --- a/packages/opentelemetry-plugin-https/README.md +++ b/packages/opentelemetry-plugin-https/README.md @@ -22,9 +22,9 @@ OpenTelemetry HTTPS Instrumentation allows the user to automatically collect tra To load a specific plugin (HTTPS in this case), specify it in the Node Tracer's configuration. ```js -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -const tracer = new NodeTracer({ +const registry = new NodeTracerRegistry({ plugins: { https: { enabled: true, @@ -38,9 +38,9 @@ const tracer = new NodeTracer({ To load all the [supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. ```js -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -const tracer = new NodeTracer(); +const registry = new NodeTracerRegistry(); ``` See [examples/https](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/https) for a short example. diff --git a/packages/opentelemetry-plugin-mongodb-core/README.md b/packages/opentelemetry-plugin-mongodb-core/README.md index d4da15c5d4..e41885a5e3 100644 --- a/packages/opentelemetry-plugin-mongodb-core/README.md +++ b/packages/opentelemetry-plugin-mongodb-core/README.md @@ -21,9 +21,9 @@ OpenTelemetry Mongodb Instrumentation allows the user to automatically collect t To load a specific plugin (mongodb in this case), specify it in the Node Tracer's configuration. ```js -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -const tracer = new NodeTracer({ +const registry = new NodeTracerRegistry({ plugins: { 'mongodb-core': { enabled: true, @@ -36,9 +36,9 @@ const tracer = new NodeTracer({ To load all the [supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. ```js -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -const tracer = new NodeTracer(); +const registry = new NodeTracerRegistry(); ``` See [examples/mongodb](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/mongodb-core) for a short example. diff --git a/packages/opentelemetry-plugin-redis/README.md b/packages/opentelemetry-plugin-redis/README.md index 9c0a44ef44..a399cc1cc5 100644 --- a/packages/opentelemetry-plugin-redis/README.md +++ b/packages/opentelemetry-plugin-redis/README.md @@ -24,9 +24,9 @@ OpenTelemetry Redis Instrumentation allows the user to automatically collect tra To load a specific plugin (**redis** in this case), specify it in the Node Tracer's configuration ```js -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -const tracer = new NodeTracer({ +const registry = new NodeTracerRegistry({ plugins: { redis: { enabled: true, @@ -39,9 +39,9 @@ const tracer = new NodeTracer({ To load all the [supported plugins](https://github.com/open-telemetry/opentelemetry-js#plugins), use below approach. Each plugin is only loaded when the module that it patches is loaded; in other words, there is no computational overhead for listing plugins for unused modules. ```javascript -const { NodeTracer } = require('@opentelemetry/node'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); -const tracer = new NodeTracer(); +const registry = new NodeTracerRegistry(); ``` From 13f96fd832c10b916cb72fd134e1d22857455a72 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Thu, 26 Dec 2019 14:30:28 -0500 Subject: [PATCH 14/24] chore: update xhr for tracer registry --- .../src/xhr.ts | 9 ++------ .../test/xhr.test.ts | 22 +++++++++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts b/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts index 46a8f61c39..b450841a13 100644 --- a/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts +++ b/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts @@ -66,18 +66,13 @@ export interface XMLHttpRequestPluginConfig extends types.PluginConfig { export class XMLHttpRequestPlugin extends BasePlugin { readonly component: string = 'xml-http-request'; // @TODO align this with all packages #600 - readonly version: string = '0.3.0'; - moduleName = this.component; - - protected _config!: XMLHttpRequestPluginConfig; private _tasksCount = 0; private _xhrMem = new WeakMap(); private _usedResources = new WeakSet(); - constructor(config: XMLHttpRequestPluginConfig = {}) { - super(); - this._config = config; + constructor(protected _config: XMLHttpRequestPluginConfig = {}) { + super('@opentelemetry/plugin-xml-http-request', '0.2.0'); } /** diff --git a/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts b/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts index 2d920b0bfb..931e31756d 100644 --- a/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts +++ b/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts @@ -27,10 +27,14 @@ import { import { ZoneScopeManager } from '@opentelemetry/scope-zone'; import * as tracing from '@opentelemetry/tracing'; import * as types from '@opentelemetry/types'; -import { PerformanceTimingNames as PTN, WebTracer } from '@opentelemetry/web'; +import { + PerformanceTimingNames as PTN, + WebTracerRegistry, +} from '@opentelemetry/web'; import { AttributeNames } from '../src/enums/AttributeNames'; import { EventNames } from '../src/enums/EventNames'; import { XMLHttpRequestPlugin } from '../src/xhr'; +import { Tracer } from '@opentelemetry/types'; class DummySpanExporter implements tracing.SpanExporter { export(spans: any) {} @@ -97,7 +101,8 @@ describe('xhr', () => { let clearData: any; describe('when request is successful', () => { - let webTracerWithZone: WebTracer; + let webTracerWithZone: Tracer; + let webTracerRegistryWithZone: WebTracerRegistry; let dummySpanExporter: DummySpanExporter; let exportSpy: any; let rootSpan: types.Span; @@ -136,7 +141,7 @@ describe('xhr', () => { spyEntries = sandbox.stub(performance, 'getEntriesByType'); spyEntries.withArgs('resource').returns(resources); - webTracerWithZone = new WebTracer({ + webTracerRegistryWithZone = new WebTracerRegistry({ logLevel: LogLevel.ERROR, httpTextFormat: new B3Format(), scopeManager: new ZoneScopeManager(), @@ -146,9 +151,10 @@ describe('xhr', () => { }), ], }); + webTracerWithZone = webTracerRegistryWithZone.getTracer('xhr-test'); dummySpanExporter = new DummySpanExporter(); exportSpy = sinon.stub(dummySpanExporter, 'export'); - webTracerWithZone.addSpanProcessor( + webTracerRegistryWithZone.addSpanProcessor( new tracing.SimpleSpanProcessor(dummySpanExporter) ); @@ -403,7 +409,8 @@ describe('xhr', () => { }); describe('when request is NOT successful', () => { - let webTracerWithZone: WebTracer; + let webTracerWithZoneRegistry: WebTracerRegistry; + let webTracerWithZone: Tracer; let dummySpanExporter: DummySpanExporter; let exportSpy: any; let rootSpan: types.Span; @@ -434,16 +441,17 @@ describe('xhr', () => { spyEntries = sandbox.stub(performance, 'getEntriesByType'); spyEntries.withArgs('resource').returns(resources); - webTracerWithZone = new WebTracer({ + webTracerWithZoneRegistry = new WebTracerRegistry({ logLevel: LogLevel.ERROR, scopeManager: new ZoneScopeManager(), plugins: [new XMLHttpRequestPlugin()], }); dummySpanExporter = new DummySpanExporter(); exportSpy = sinon.stub(dummySpanExporter, 'export'); - webTracerWithZone.addSpanProcessor( + webTracerWithZoneRegistry.addSpanProcessor( new tracing.SimpleSpanProcessor(dummySpanExporter) ); + webTracerWithZone = webTracerWithZoneRegistry.getTracer('xhr-test'); rootSpan = webTracerWithZone.startSpan('root'); From 38ffef8ce2406b843c060c7925e6b7c80e43bb57 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Thu, 26 Dec 2019 14:43:44 -0500 Subject: [PATCH 15/24] chore: update tracer names to match package names --- packages/opentelemetry-plugin-dns/src/dns.ts | 2 +- packages/opentelemetry-plugin-document-load/src/documentLoad.ts | 2 +- packages/opentelemetry-plugin-grpc/src/grpc.ts | 2 +- packages/opentelemetry-plugin-http/src/http.ts | 2 +- packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts | 2 +- packages/opentelemetry-plugin-mysql/src/mysql.ts | 2 +- .../opentelemetry-plugin-pg/src/pg.ts | 2 +- packages/opentelemetry-plugin-redis/src/redis.ts | 2 +- packages/opentelemetry-plugin-xml-http-request/src/xhr.ts | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/opentelemetry-plugin-dns/src/dns.ts b/packages/opentelemetry-plugin-dns/src/dns.ts index d6ab4edf1e..e1d8cf29df 100644 --- a/packages/opentelemetry-plugin-dns/src/dns.ts +++ b/packages/opentelemetry-plugin-dns/src/dns.ts @@ -39,7 +39,7 @@ export class DnsPlugin extends BasePlugin { protected _config!: DnsPluginConfig; constructor(readonly moduleName: string, readonly version: string) { - super(`opentelemetry.${moduleName}`, '0.2.0'); + super('@opentelemetry/plugin-dns', '0.3.1'); // For now component is equal to moduleName but it can change in the future. this.component = this.moduleName; this._config = {}; diff --git a/packages/opentelemetry-plugin-document-load/src/documentLoad.ts b/packages/opentelemetry-plugin-document-load/src/documentLoad.ts index 28ddd5d7f8..de354dbedd 100644 --- a/packages/opentelemetry-plugin-document-load/src/documentLoad.ts +++ b/packages/opentelemetry-plugin-document-load/src/documentLoad.ts @@ -44,7 +44,7 @@ export class DocumentLoad extends BasePlugin { * @param config */ constructor(config: PluginConfig = {}) { - super('opentelemetry.document-load', '0.2.0'); + super('@opentelemetry/plugin-document-load', '0.3.1'); this._onDocumentLoaded = this._onDocumentLoaded.bind(this); this._config = config; } diff --git a/packages/opentelemetry-plugin-grpc/src/grpc.ts b/packages/opentelemetry-plugin-grpc/src/grpc.ts index a5e6639120..8e5eb902eb 100644 --- a/packages/opentelemetry-plugin-grpc/src/grpc.ts +++ b/packages/opentelemetry-plugin-grpc/src/grpc.ts @@ -56,7 +56,7 @@ export class GrpcPlugin extends BasePlugin { protected _config!: GrpcPluginOptions; constructor(readonly moduleName: string, readonly version: string) { - super(`opentelemetry.${moduleName}`, '0.2.0'); + super('@opentelemetry/plugin-grpc', '0.3.1'); this._config = {}; } diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index 7f2341421d..0536a8b309 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -56,7 +56,7 @@ export class HttpPlugin extends BasePlugin { private readonly _spanNotEnded: WeakSet; constructor(readonly moduleName: string, readonly version: string) { - super(`opentelemetry.${moduleName}`, '0.2.0'); + super(`@opentelemetry/plugin-${moduleName}`, '0.3.1'); // For now component is equal to moduleName but it can change in the future. this.component = this.moduleName; this._spanNotEnded = new WeakSet(); diff --git a/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts b/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts index d6c0635df9..0ae091d5af 100644 --- a/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts +++ b/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts @@ -40,7 +40,7 @@ export class MongoDBCorePlugin extends BasePlugin { readonly supportedVersions = ['>=2 <3']; constructor(readonly moduleName: string) { - super(`opentelemetry.${moduleName}`, '0.2.0'); + super('@opentelemetry/plugin-mongodb-core', '0.3.1'); } /** diff --git a/packages/opentelemetry-plugin-mysql/src/mysql.ts b/packages/opentelemetry-plugin-mysql/src/mysql.ts index fb5834027b..50d45e9202 100644 --- a/packages/opentelemetry-plugin-mysql/src/mysql.ts +++ b/packages/opentelemetry-plugin-mysql/src/mysql.ts @@ -36,7 +36,7 @@ export class MysqlPlugin extends BasePlugin { private _enabled = false; constructor(readonly moduleName: string) { - super(`opentelemetry.${moduleName}`, '0.2.0'); + super('@opentelemetry/plugin-mysql', '0.3.1'); } protected patch(): typeof mysqlTypes { diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts index c23c5735b8..534ce1418c 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts @@ -37,7 +37,7 @@ export class PostgresPlugin extends BasePlugin { readonly supportedVersions = ['7.*']; constructor(readonly moduleName: string) { - super(`opentelemetry.${moduleName}`, '0.2.0'); + super('@opentelemetry/plugin-pg', '0.3.1'); this._config = {}; } diff --git a/packages/opentelemetry-plugin-redis/src/redis.ts b/packages/opentelemetry-plugin-redis/src/redis.ts index 3ce225c9fa..4039942ee9 100644 --- a/packages/opentelemetry-plugin-redis/src/redis.ts +++ b/packages/opentelemetry-plugin-redis/src/redis.ts @@ -28,7 +28,7 @@ export class RedisPlugin extends BasePlugin { readonly supportedVersions = ['^2.6.0']; // equivalent to >= 2.6.0 <3 constructor(readonly moduleName: string) { - super(`opentelemetry.${moduleName}`, '0.2.0'); + super("@opentelemetry/plugin-redis", "0.3.1"); } protected patch() { diff --git a/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts b/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts index b450841a13..b23958b9d6 100644 --- a/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts +++ b/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts @@ -72,7 +72,7 @@ export class XMLHttpRequestPlugin extends BasePlugin { private _usedResources = new WeakSet(); constructor(protected _config: XMLHttpRequestPluginConfig = {}) { - super('@opentelemetry/plugin-xml-http-request', '0.2.0'); + super('@opentelemetry/plugin-xml-http-request', '0.3.1'); } /** From 9915a2cd8ee375f57396610558e5a2f919d921b2 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Thu, 26 Dec 2019 15:14:26 -0500 Subject: [PATCH 16/24] chore: add version script to all packages --- packages/opentelemetry-base/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../src}/version.ts | 0 .../scripts/version-update.js | 2 +- packages/opentelemetry-core/src/index.ts | 2 +- packages/opentelemetry-core/src/version.ts | 18 +++++++ .../package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../src/version.ts | 18 +++++++ .../package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../src/version.ts | 18 +++++++ .../package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../src/version.ts | 18 +++++++ packages/opentelemetry-metrics/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ packages/opentelemetry-metrics/src/version.ts | 18 +++++++ packages/opentelemetry-node/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ packages/opentelemetry-node/src/version.ts | 18 +++++++ .../opentelemetry-plugin-dns/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../opentelemetry-plugin-dns/src/version.ts | 18 +++++++ .../package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../src/version.ts | 18 +++++++ .../opentelemetry-plugin-grpc/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../opentelemetry-plugin-grpc/src/version.ts | 18 +++++++ .../opentelemetry-plugin-http/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../opentelemetry-plugin-http/src/version.ts | 18 +++++++ .../opentelemetry-plugin-http2/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../opentelemetry-plugin-http2/src/version.ts | 18 +++++++ .../opentelemetry-plugin-https/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../opentelemetry-plugin-https/src/version.ts | 18 +++++++ .../package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../src/version.ts | 18 +++++++ .../opentelemetry-plugin-mysql/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../opentelemetry-plugin-mysql/src/version.ts | 18 +++++++ .../opentelemetry-plugin-pg-pool/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../src/version.ts | 18 +++++++ .../opentelemetry-plugin-pg/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../opentelemetry-plugin-pg/src/version.ts | 18 +++++++ .../opentelemetry-plugin-redis/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../opentelemetry-plugin-redis/src/version.ts | 18 +++++++ .../package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../src/version.ts | 18 +++++++ .../package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../src/version.ts | 18 +++++++ .../opentelemetry-scope-base/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../opentelemetry-scope-base/src/version.ts | 18 +++++++ .../package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../src/version.ts | 18 +++++++ .../opentelemetry-scope-zone/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../opentelemetry-scope-zone/src/version.ts | 18 +++++++ .../package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ .../src/version.ts | 18 +++++++ packages/opentelemetry-tracing/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ packages/opentelemetry-tracing/src/version.ts | 18 +++++++ packages/opentelemetry-types/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ packages/opentelemetry-types/src/version.ts | 18 +++++++ packages/opentelemetry-web/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++++++ packages/opentelemetry-web/src/version.ts | 18 +++++++ 81 files changed, 1744 insertions(+), 28 deletions(-) create mode 100644 packages/opentelemetry-base/scripts/version-update.js rename packages/{opentelemetry-core/src/common => opentelemetry-base/src}/version.ts (100%) create mode 100644 packages/opentelemetry-core/src/version.ts create mode 100644 packages/opentelemetry-exporter-jaeger/scripts/version-update.js create mode 100644 packages/opentelemetry-exporter-jaeger/src/version.ts create mode 100644 packages/opentelemetry-exporter-prometheus/scripts/version-update.js create mode 100644 packages/opentelemetry-exporter-prometheus/src/version.ts create mode 100644 packages/opentelemetry-exporter-zipkin/scripts/version-update.js create mode 100644 packages/opentelemetry-exporter-zipkin/src/version.ts create mode 100644 packages/opentelemetry-metrics/scripts/version-update.js create mode 100644 packages/opentelemetry-metrics/src/version.ts create mode 100644 packages/opentelemetry-node/scripts/version-update.js create mode 100644 packages/opentelemetry-node/src/version.ts create mode 100644 packages/opentelemetry-plugin-dns/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-dns/src/version.ts create mode 100644 packages/opentelemetry-plugin-document-load/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-document-load/src/version.ts create mode 100644 packages/opentelemetry-plugin-grpc/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-grpc/src/version.ts create mode 100644 packages/opentelemetry-plugin-http/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-http/src/version.ts create mode 100644 packages/opentelemetry-plugin-http2/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-http2/src/version.ts create mode 100644 packages/opentelemetry-plugin-https/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-https/src/version.ts create mode 100644 packages/opentelemetry-plugin-mongodb-core/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-mongodb-core/src/version.ts create mode 100644 packages/opentelemetry-plugin-mysql/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-mysql/src/version.ts create mode 100644 packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/version.ts create mode 100644 packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/version.ts create mode 100644 packages/opentelemetry-plugin-redis/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-redis/src/version.ts create mode 100644 packages/opentelemetry-plugin-xml-http-request/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-xml-http-request/src/version.ts create mode 100644 packages/opentelemetry-scope-async-hooks/scripts/version-update.js create mode 100644 packages/opentelemetry-scope-async-hooks/src/version.ts create mode 100644 packages/opentelemetry-scope-base/scripts/version-update.js create mode 100644 packages/opentelemetry-scope-base/src/version.ts create mode 100644 packages/opentelemetry-scope-zone-peer-dep/scripts/version-update.js create mode 100644 packages/opentelemetry-scope-zone-peer-dep/src/version.ts create mode 100644 packages/opentelemetry-scope-zone/scripts/version-update.js create mode 100644 packages/opentelemetry-scope-zone/src/version.ts create mode 100644 packages/opentelemetry-shim-opentracing/scripts/version-update.js create mode 100644 packages/opentelemetry-shim-opentracing/src/version.ts create mode 100644 packages/opentelemetry-tracing/scripts/version-update.js create mode 100644 packages/opentelemetry-tracing/src/version.ts create mode 100644 packages/opentelemetry-types/scripts/version-update.js create mode 100644 packages/opentelemetry-types/src/version.ts create mode 100644 packages/opentelemetry-web/scripts/version-update.js create mode 100644 packages/opentelemetry-web/src/version.ts diff --git a/packages/opentelemetry-base/package.json b/packages/opentelemetry-base/package.json index 25b83464ee..1d864143df 100644 --- a/packages/opentelemetry-base/package.json +++ b/packages/opentelemetry-base/package.json @@ -13,7 +13,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-base/scripts/version-update.js b/packages/opentelemetry-base/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-base/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-core/src/common/version.ts b/packages/opentelemetry-base/src/version.ts similarity index 100% rename from packages/opentelemetry-core/src/common/version.ts rename to packages/opentelemetry-base/src/version.ts diff --git a/packages/opentelemetry-core/scripts/version-update.js b/packages/opentelemetry-core/scripts/version-update.js index 3240a96b4b..2bb382ce6d 100644 --- a/packages/opentelemetry-core/scripts/version-update.js +++ b/packages/opentelemetry-core/scripts/version-update.js @@ -36,7 +36,7 @@ const fs = require('fs'); const path = require('path'); const appRoot = path.resolve(__dirname); -const fileUrl = path.resolve(`${appRoot}/../src/common/version.ts`); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); const pjson = require(packageJsonUrl); const content = ` diff --git a/packages/opentelemetry-core/src/index.ts b/packages/opentelemetry-core/src/index.ts index c4ca2ccb84..582101ab1e 100644 --- a/packages/opentelemetry-core/src/index.ts +++ b/packages/opentelemetry-core/src/index.ts @@ -18,7 +18,7 @@ export * from './common/ConsoleLogger'; export * from './common/NoopLogger'; export * from './common/time'; export * from './common/types'; -export * from './common/version'; +export * from './version'; export * from './context/propagation/B3Format'; export * from './context/propagation/BinaryTraceContext'; export * from './context/propagation/HttpTraceContext'; diff --git a/packages/opentelemetry-core/src/version.ts b/packages/opentelemetry-core/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-core/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-exporter-jaeger/package.json b/packages/opentelemetry-exporter-jaeger/package.json index ea59f4bd5d..9a8981e3ec 100644 --- a/packages/opentelemetry-exporter-jaeger/package.json +++ b/packages/opentelemetry-exporter-jaeger/package.json @@ -12,7 +12,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-exporter-jaeger/scripts/version-update.js b/packages/opentelemetry-exporter-jaeger/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-exporter-jaeger/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-exporter-jaeger/src/version.ts b/packages/opentelemetry-exporter-jaeger/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-exporter-jaeger/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-exporter-prometheus/package.json b/packages/opentelemetry-exporter-prometheus/package.json index 5af9c6c474..0e19896545 100644 --- a/packages/opentelemetry-exporter-prometheus/package.json +++ b/packages/opentelemetry-exporter-prometheus/package.json @@ -12,7 +12,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-exporter-prometheus/scripts/version-update.js b/packages/opentelemetry-exporter-prometheus/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-exporter-prometheus/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-exporter-prometheus/src/version.ts b/packages/opentelemetry-exporter-prometheus/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-exporter-prometheus/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-exporter-zipkin/package.json b/packages/opentelemetry-exporter-zipkin/package.json index 1f9a7c40b1..4125d4b951 100644 --- a/packages/opentelemetry-exporter-zipkin/package.json +++ b/packages/opentelemetry-exporter-zipkin/package.json @@ -12,7 +12,8 @@ "check": "gts check", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-exporter-zipkin/scripts/version-update.js b/packages/opentelemetry-exporter-zipkin/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-exporter-zipkin/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-exporter-zipkin/src/version.ts b/packages/opentelemetry-exporter-zipkin/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-exporter-zipkin/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-metrics/package.json b/packages/opentelemetry-metrics/package.json index f6079197fd..64c88c6ff0 100644 --- a/packages/opentelemetry-metrics/package.json +++ b/packages/opentelemetry-metrics/package.json @@ -12,7 +12,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-metrics/scripts/version-update.js b/packages/opentelemetry-metrics/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-metrics/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-metrics/src/version.ts b/packages/opentelemetry-metrics/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-metrics/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-node/package.json b/packages/opentelemetry-node/package.json index bc66d9291e..c515e5fd14 100644 --- a/packages/opentelemetry-node/package.json +++ b/packages/opentelemetry-node/package.json @@ -12,7 +12,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-node/scripts/version-update.js b/packages/opentelemetry-node/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-node/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-node/src/version.ts b/packages/opentelemetry-node/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-node/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-dns/package.json b/packages/opentelemetry-plugin-dns/package.json index 45cdf94bd1..8ce01bde0f 100644 --- a/packages/opentelemetry-plugin-dns/package.json +++ b/packages/opentelemetry-plugin-dns/package.json @@ -12,7 +12,8 @@ "check": "gts check", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix" }, "keywords": [ diff --git a/packages/opentelemetry-plugin-dns/scripts/version-update.js b/packages/opentelemetry-plugin-dns/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-dns/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-dns/src/version.ts b/packages/opentelemetry-plugin-dns/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-dns/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-document-load/package.json b/packages/opentelemetry-plugin-document-load/package.json index c409f4fd03..c803bb4167 100644 --- a/packages/opentelemetry-plugin-document-load/package.json +++ b/packages/opentelemetry-plugin-document-load/package.json @@ -10,7 +10,8 @@ "check": "gts check", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile", "tdd": "karma start", diff --git a/packages/opentelemetry-plugin-document-load/scripts/version-update.js b/packages/opentelemetry-plugin-document-load/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-document-load/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-document-load/src/version.ts b/packages/opentelemetry-plugin-document-load/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-document-load/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-grpc/package.json b/packages/opentelemetry-plugin-grpc/package.json index 80cf08e205..bca86cc811 100644 --- a/packages/opentelemetry-plugin-grpc/package.json +++ b/packages/opentelemetry-plugin-grpc/package.json @@ -12,7 +12,8 @@ "check": "gts check", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-plugin-grpc/scripts/version-update.js b/packages/opentelemetry-plugin-grpc/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-grpc/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-grpc/src/version.ts b/packages/opentelemetry-plugin-grpc/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-grpc/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-http/package.json b/packages/opentelemetry-plugin-http/package.json index 7628f8c627..951e39555b 100644 --- a/packages/opentelemetry-plugin-http/package.json +++ b/packages/opentelemetry-plugin-http/package.json @@ -12,7 +12,8 @@ "check": "gts check", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-plugin-http/scripts/version-update.js b/packages/opentelemetry-plugin-http/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-http/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-http/src/version.ts b/packages/opentelemetry-plugin-http/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-http/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-http2/package.json b/packages/opentelemetry-plugin-http2/package.json index d7bf80ea3c..162c5088fd 100644 --- a/packages/opentelemetry-plugin-http2/package.json +++ b/packages/opentelemetry-plugin-http2/package.json @@ -12,7 +12,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-plugin-http2/scripts/version-update.js b/packages/opentelemetry-plugin-http2/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-http2/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-http2/src/version.ts b/packages/opentelemetry-plugin-http2/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-http2/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-https/package.json b/packages/opentelemetry-plugin-https/package.json index fac3f84c76..d975d0f100 100644 --- a/packages/opentelemetry-plugin-https/package.json +++ b/packages/opentelemetry-plugin-https/package.json @@ -12,7 +12,8 @@ "check": "gts check", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-plugin-https/scripts/version-update.js b/packages/opentelemetry-plugin-https/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-https/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-https/src/version.ts b/packages/opentelemetry-plugin-https/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-https/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-mongodb-core/package.json b/packages/opentelemetry-plugin-mongodb-core/package.json index 1bd5421efc..91d9df1012 100644 --- a/packages/opentelemetry-plugin-mongodb-core/package.json +++ b/packages/opentelemetry-plugin-mongodb-core/package.json @@ -12,7 +12,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-plugin-mongodb-core/scripts/version-update.js b/packages/opentelemetry-plugin-mongodb-core/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-mongodb-core/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-mongodb-core/src/version.ts b/packages/opentelemetry-plugin-mongodb-core/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-mongodb-core/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-mysql/package.json b/packages/opentelemetry-plugin-mysql/package.json index 9d02fd7377..01edf455e7 100644 --- a/packages/opentelemetry-plugin-mysql/package.json +++ b/packages/opentelemetry-plugin-mysql/package.json @@ -12,7 +12,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-plugin-mysql/scripts/version-update.js b/packages/opentelemetry-plugin-mysql/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-mysql/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-mysql/src/version.ts b/packages/opentelemetry-plugin-mysql/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-mysql/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json index 4697636985..efc83d0c90 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json @@ -15,7 +15,8 @@ "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/scripts/version-update.js b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/version.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json index 2e722b3096..419195ebbb 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json @@ -14,7 +14,8 @@ "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/scripts/version-update.js b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/version.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-redis/package.json b/packages/opentelemetry-plugin-redis/package.json index 1c1f7226c0..0358232346 100644 --- a/packages/opentelemetry-plugin-redis/package.json +++ b/packages/opentelemetry-plugin-redis/package.json @@ -13,7 +13,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "fix": "gts fix", "prepare": "npm run compile" diff --git a/packages/opentelemetry-plugin-redis/scripts/version-update.js b/packages/opentelemetry-plugin-redis/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-redis/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-redis/src/version.ts b/packages/opentelemetry-plugin-redis/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-redis/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-xml-http-request/package.json b/packages/opentelemetry-plugin-xml-http-request/package.json index 1ae4c8398b..8807e9a56f 100644 --- a/packages/opentelemetry-plugin-xml-http-request/package.json +++ b/packages/opentelemetry-plugin-xml-http-request/package.json @@ -10,7 +10,8 @@ "clean": "rimraf build/*", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile", "tdd": "karma start", diff --git a/packages/opentelemetry-plugin-xml-http-request/scripts/version-update.js b/packages/opentelemetry-plugin-xml-http-request/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-xml-http-request/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-xml-http-request/src/version.ts b/packages/opentelemetry-plugin-xml-http-request/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-xml-http-request/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-scope-async-hooks/package.json b/packages/opentelemetry-scope-async-hooks/package.json index dce4cb3f3f..3846ffd724 100644 --- a/packages/opentelemetry-scope-async-hooks/package.json +++ b/packages/opentelemetry-scope-async-hooks/package.json @@ -12,7 +12,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-scope-async-hooks/scripts/version-update.js b/packages/opentelemetry-scope-async-hooks/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-scope-async-hooks/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-scope-async-hooks/src/version.ts b/packages/opentelemetry-scope-async-hooks/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-scope-async-hooks/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-scope-base/package.json b/packages/opentelemetry-scope-base/package.json index 53015dc39f..49fe620d56 100644 --- a/packages/opentelemetry-scope-base/package.json +++ b/packages/opentelemetry-scope-base/package.json @@ -12,7 +12,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-scope-base/scripts/version-update.js b/packages/opentelemetry-scope-base/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-scope-base/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-scope-base/src/version.ts b/packages/opentelemetry-scope-base/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-scope-base/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-scope-zone-peer-dep/package.json b/packages/opentelemetry-scope-zone-peer-dep/package.json index a00529e497..68e61d6125 100644 --- a/packages/opentelemetry-scope-zone-peer-dep/package.json +++ b/packages/opentelemetry-scope-zone-peer-dep/package.json @@ -9,7 +9,8 @@ "check": "gts check", "clean": "rimraf build/*", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile", "tdd": "karma start", diff --git a/packages/opentelemetry-scope-zone-peer-dep/scripts/version-update.js b/packages/opentelemetry-scope-zone-peer-dep/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-scope-zone-peer-dep/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-scope-zone-peer-dep/src/version.ts b/packages/opentelemetry-scope-zone-peer-dep/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-scope-zone-peer-dep/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-scope-zone/package.json b/packages/opentelemetry-scope-zone/package.json index 6c8d5e96cd..0575214139 100644 --- a/packages/opentelemetry-scope-zone/package.json +++ b/packages/opentelemetry-scope-zone/package.json @@ -8,7 +8,8 @@ "scripts": { "check": "gts check", "clean": "rimraf build/*", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile", "watch": "tsc -w" diff --git a/packages/opentelemetry-scope-zone/scripts/version-update.js b/packages/opentelemetry-scope-zone/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-scope-zone/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-scope-zone/src/version.ts b/packages/opentelemetry-scope-zone/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-scope-zone/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-shim-opentracing/package.json b/packages/opentelemetry-shim-opentracing/package.json index 29de4aa842..7471ac4a09 100644 --- a/packages/opentelemetry-shim-opentracing/package.json +++ b/packages/opentelemetry-shim-opentracing/package.json @@ -12,7 +12,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile" }, diff --git a/packages/opentelemetry-shim-opentracing/scripts/version-update.js b/packages/opentelemetry-shim-opentracing/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-shim-opentracing/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-shim-opentracing/src/version.ts b/packages/opentelemetry-shim-opentracing/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-shim-opentracing/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-tracing/package.json b/packages/opentelemetry-tracing/package.json index 10b6383700..a50f768507 100644 --- a/packages/opentelemetry-tracing/package.json +++ b/packages/opentelemetry-tracing/package.json @@ -14,7 +14,8 @@ "clean": "rimraf build/*", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile", "tdd": "yarn test -- --watch-extensions ts --watch", diff --git a/packages/opentelemetry-tracing/scripts/version-update.js b/packages/opentelemetry-tracing/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-tracing/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-tracing/src/version.ts b/packages/opentelemetry-tracing/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-tracing/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-types/package.json b/packages/opentelemetry-types/package.json index 54e2b1dd7e..3b4f2224b9 100644 --- a/packages/opentelemetry-types/package.json +++ b/packages/opentelemetry-types/package.json @@ -9,7 +9,8 @@ "build": "npm run compile", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "docs-test": "linkinator docs/out", "docs": "typedoc --tsconfig tsconfig.json", diff --git a/packages/opentelemetry-types/scripts/version-update.js b/packages/opentelemetry-types/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-types/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-types/src/version.ts b/packages/opentelemetry-types/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-types/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-web/package.json b/packages/opentelemetry-web/package.json index 46f490d2d1..20beb086bf 100644 --- a/packages/opentelemetry-web/package.json +++ b/packages/opentelemetry-web/package.json @@ -10,7 +10,8 @@ "clean": "rimraf build/*", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "fix": "gts fix", "prepare": "npm run compile", "tdd": "karma start", diff --git a/packages/opentelemetry-web/scripts/version-update.js b/packages/opentelemetry-web/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-web/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-web/src/version.ts b/packages/opentelemetry-web/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-web/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; From 69ff01f06ee594d474676fface055c418ca85f1e Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Thu, 26 Dec 2019 15:14:36 -0500 Subject: [PATCH 17/24] chore: update plugins to use version script --- packages/opentelemetry-plugin-dns/src/dns.ts | 23 ++++++++-------- .../src/documentLoad.ts | 5 ++-- .../opentelemetry-plugin-grpc/src/grpc.ts | 26 +++++++++---------- .../opentelemetry-plugin-http/src/http.ts | 21 ++++++++------- .../src/mongodb.ts | 13 +++++----- .../opentelemetry-plugin-mysql/src/mysql.ts | 3 ++- .../opentelemetry-plugin-pg/src/pg.ts | 9 ++++--- .../opentelemetry-plugin-redis/src/redis.ts | 3 ++- .../src/xhr.ts | 3 ++- 9 files changed, 57 insertions(+), 49 deletions(-) diff --git a/packages/opentelemetry-plugin-dns/src/dns.ts b/packages/opentelemetry-plugin-dns/src/dns.ts index e1d8cf29df..f7c3eb651b 100644 --- a/packages/opentelemetry-plugin-dns/src/dns.ts +++ b/packages/opentelemetry-plugin-dns/src/dns.ts @@ -14,22 +14,23 @@ * limitations under the License. */ -import * as shimmer from 'shimmer'; -import * as semver from 'semver'; -import * as utils from './utils'; import { BasePlugin } from '@opentelemetry/core'; -import { SpanOptions, SpanKind, Span } from '@opentelemetry/types'; +import { Span, SpanKind, SpanOptions } from '@opentelemetry/types'; +import { LookupAddress } from 'dns'; +import * as semver from 'semver'; +import * as shimmer from 'shimmer'; +import { AddressFamily } from './enums/AddressFamily'; +import { AttributeNames } from './enums/AttributeNames'; import { Dns, - LookupPromiseSignature, + DnsPluginConfig, + LookupCallbackSignature, LookupFunction, LookupFunctionSignature, - LookupCallbackSignature, - DnsPluginConfig, + LookupPromiseSignature, } from './types'; -import { AttributeNames } from './enums/AttributeNames'; -import { AddressFamily } from './enums/AddressFamily'; -import { LookupAddress } from 'dns'; +import * as utils from './utils'; +import { VERSION } from './version'; /** * Dns instrumentation plugin for Opentelemetry @@ -39,7 +40,7 @@ export class DnsPlugin extends BasePlugin { protected _config!: DnsPluginConfig; constructor(readonly moduleName: string, readonly version: string) { - super('@opentelemetry/plugin-dns', '0.3.1'); + super('@opentelemetry/plugin-dns', VERSION); // For now component is equal to moduleName but it can change in the future. this.component = this.moduleName; this._config = {}; diff --git a/packages/opentelemetry-plugin-document-load/src/documentLoad.ts b/packages/opentelemetry-plugin-document-load/src/documentLoad.ts index de354dbedd..2d14055cd8 100644 --- a/packages/opentelemetry-plugin-document-load/src/documentLoad.ts +++ b/packages/opentelemetry-plugin-document-load/src/documentLoad.ts @@ -21,7 +21,6 @@ import { TRACE_PARENT_HEADER, } from '@opentelemetry/core'; import { PluginConfig, Span, SpanOptions } from '@opentelemetry/types'; -import { AttributeNames } from './enums/AttributeNames'; import { addSpanNetworkEvent, hasKey, @@ -29,6 +28,8 @@ import { PerformanceLegacy, PerformanceTimingNames as PTN, } from '@opentelemetry/web'; +import { AttributeNames } from './enums/AttributeNames'; +import { VERSION } from './version'; /** * This class represents a document load plugin @@ -44,7 +45,7 @@ export class DocumentLoad extends BasePlugin { * @param config */ constructor(config: PluginConfig = {}) { - super('@opentelemetry/plugin-document-load', '0.3.1'); + super('@opentelemetry/plugin-document-load', VERSION); this._onDocumentLoaded = this._onDocumentLoaded.bind(this); this._config = config; } diff --git a/packages/opentelemetry-plugin-grpc/src/grpc.ts b/packages/opentelemetry-plugin-grpc/src/grpc.ts index 8e5eb902eb..901eba22fe 100644 --- a/packages/opentelemetry-plugin-grpc/src/grpc.ts +++ b/packages/opentelemetry-plugin-grpc/src/grpc.ts @@ -16,33 +16,33 @@ import { BasePlugin } from '@opentelemetry/core'; import { + CanonicalCode, + Span, + SpanContext, SpanKind, SpanOptions, - Span, Status, - CanonicalCode, - SpanContext, } from '@opentelemetry/types'; +import * as events from 'events'; +import * as grpcTypes from 'grpc'; +import * as path from 'path'; +import * as shimmer from 'shimmer'; import { AttributeNames } from './enums/AttributeNames'; import { grpc, - ModuleExportsMapping, - GrpcPluginOptions, - ServerCallWithMeta, - SendUnaryDataCallback, GrpcClientFunc, GrpcInternalClientTypes, + GrpcPluginOptions, + ModuleExportsMapping, + SendUnaryDataCallback, + ServerCallWithMeta, } from './types'; import { findIndex, _grpcStatusCodeToCanonicalCode, _grpcStatusCodeToSpanStatus, } from './utils'; - -import * as events from 'events'; -import * as grpcTypes from 'grpc'; -import * as shimmer from 'shimmer'; -import * as path from 'path'; +import { VERSION } from './version'; /** The metadata key under which span context is stored as a binary value. */ export const GRPC_TRACE_KEY = 'grpc-trace-bin'; @@ -56,7 +56,7 @@ export class GrpcPlugin extends BasePlugin { protected _config!: GrpcPluginOptions; constructor(readonly moduleName: string, readonly version: string) { - super('@opentelemetry/plugin-grpc', '0.3.1'); + super('@opentelemetry/plugin-grpc', VERSION); this._config = {}; } diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index 0536a8b309..d0bceb298a 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -16,11 +16,11 @@ import { BasePlugin, isValid } from '@opentelemetry/core'; import { + Attributes, + CanonicalCode, Span, SpanKind, SpanOptions, - Attributes, - CanonicalCode, Status, } from '@opentelemetry/types'; import { @@ -33,18 +33,19 @@ import { import * as semver from 'semver'; import * as shimmer from 'shimmer'; import * as url from 'url'; +import { AttributeNames } from './enums/AttributeNames'; +import { Format } from './enums/Format'; import { - HttpPluginConfig, - Http, + Err, Func, - ResponseEndArgs, - ParsedRequestOptions, + Http, + HttpPluginConfig, HttpRequestArgs, - Err, + ParsedRequestOptions, + ResponseEndArgs, } from './types'; -import { Format } from './enums/Format'; -import { AttributeNames } from './enums/AttributeNames'; import * as utils from './utils'; +import { VERSION } from './version'; /** * Http instrumentation plugin for Opentelemetry @@ -56,7 +57,7 @@ export class HttpPlugin extends BasePlugin { private readonly _spanNotEnded: WeakSet; constructor(readonly moduleName: string, readonly version: string) { - super(`@opentelemetry/plugin-${moduleName}`, '0.3.1'); + super(`@opentelemetry/plugin-${moduleName}`, VERSION); // For now component is equal to moduleName but it can change in the future. this.component = this.moduleName; this._spanNotEnded = new WeakSet(); diff --git a/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts b/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts index 0ae091d5af..d5a577a45f 100644 --- a/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts +++ b/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts @@ -18,16 +18,17 @@ /* tslint:disable:deprecation */ import { BasePlugin } from '@opentelemetry/core'; -import { Span, SpanKind, CanonicalCode } from '@opentelemetry/types'; +import { CanonicalCode, Span, SpanKind } from '@opentelemetry/types'; +import * as mongodb from 'mongodb'; +import * as shimmer from 'shimmer'; import { + AttributeNames, Func, + MongodbCommandType, MongoInternalCommand, MongoInternalTopology, - AttributeNames, - MongodbCommandType, } from './types'; -import * as mongodb from 'mongodb'; -import * as shimmer from 'shimmer'; +import { VERSION } from './version'; /** MongoDBCore instrumentation plugin for OpenTelemetry */ export class MongoDBCorePlugin extends BasePlugin { @@ -40,7 +41,7 @@ export class MongoDBCorePlugin extends BasePlugin { readonly supportedVersions = ['>=2 <3']; constructor(readonly moduleName: string) { - super('@opentelemetry/plugin-mongodb-core', '0.3.1'); + super('@opentelemetry/plugin-mongodb-core', VERSION); } /** diff --git a/packages/opentelemetry-plugin-mysql/src/mysql.ts b/packages/opentelemetry-plugin-mysql/src/mysql.ts index 50d45e9202..9fcd6e64b6 100644 --- a/packages/opentelemetry-plugin-mysql/src/mysql.ts +++ b/packages/opentelemetry-plugin-mysql/src/mysql.ts @@ -20,6 +20,7 @@ import * as mysqlTypes from 'mysql'; import * as shimmer from 'shimmer'; import { AttributeNames } from './enums'; import { getConnectionAttributes, getSpanName } from './utils'; +import { VERSION } from './version'; export class MysqlPlugin extends BasePlugin { readonly supportedVersions = ['2.*']; @@ -36,7 +37,7 @@ export class MysqlPlugin extends BasePlugin { private _enabled = false; constructor(readonly moduleName: string) { - super('@opentelemetry/plugin-mysql', '0.3.1'); + super('@opentelemetry/plugin-mysql', VERSION); } protected patch(): typeof mysqlTypes { diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts index 534ce1418c..02902df2db 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/pg.ts @@ -16,15 +16,16 @@ import { BasePlugin } from '@opentelemetry/core'; import { CanonicalCode, Span } from '@opentelemetry/types'; +import * as pgTypes from 'pg'; +import * as shimmer from 'shimmer'; import { - PostgresPluginOptions, PgClientExtended, PgPluginQueryConfig, PostgresCallback, + PostgresPluginOptions, } from './types'; -import * as pgTypes from 'pg'; -import * as shimmer from 'shimmer'; import * as utils from './utils'; +import { VERSION } from './version'; export class PostgresPlugin extends BasePlugin { protected _config: PostgresPluginOptions; @@ -37,7 +38,7 @@ export class PostgresPlugin extends BasePlugin { readonly supportedVersions = ['7.*']; constructor(readonly moduleName: string) { - super('@opentelemetry/plugin-pg', '0.3.1'); + super('@opentelemetry/plugin-pg', VERSION); this._config = {}; } diff --git a/packages/opentelemetry-plugin-redis/src/redis.ts b/packages/opentelemetry-plugin-redis/src/redis.ts index 4039942ee9..0973e52c05 100644 --- a/packages/opentelemetry-plugin-redis/src/redis.ts +++ b/packages/opentelemetry-plugin-redis/src/redis.ts @@ -22,13 +22,14 @@ import { getTracedCreateStreamTrace, getTracedInternalSendCommand, } from './utils'; +import { VERSION } from './version'; export class RedisPlugin extends BasePlugin { static readonly COMPONENT = 'redis'; readonly supportedVersions = ['^2.6.0']; // equivalent to >= 2.6.0 <3 constructor(readonly moduleName: string) { - super("@opentelemetry/plugin-redis", "0.3.1"); + super('@opentelemetry/plugin-redis', VERSION); } protected patch() { diff --git a/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts b/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts index b23958b9d6..f01ac6ffe9 100644 --- a/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts +++ b/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts @@ -39,6 +39,7 @@ import { SendFunction, XhrMem, } from './types'; +import { VERSION } from './version'; // how long to wait for observer to collect information about resources // this is needed as event "load" is called before observer @@ -72,7 +73,7 @@ export class XMLHttpRequestPlugin extends BasePlugin { private _usedResources = new WeakSet(); constructor(protected _config: XMLHttpRequestPluginConfig = {}) { - super('@opentelemetry/plugin-xml-http-request', '0.3.1'); + super('@opentelemetry/plugin-xml-http-request', VERSION); } /** From 40c43010bd1c53238e437595994d7ef14e250f49 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Fri, 27 Dec 2019 09:13:51 -0500 Subject: [PATCH 18/24] chore: add jsdoc to noop tracer registry --- packages/opentelemetry-core/src/trace/NoopTracerRegistry.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/opentelemetry-core/src/trace/NoopTracerRegistry.ts b/packages/opentelemetry-core/src/trace/NoopTracerRegistry.ts index 3283627921..701dd9d3bf 100644 --- a/packages/opentelemetry-core/src/trace/NoopTracerRegistry.ts +++ b/packages/opentelemetry-core/src/trace/NoopTracerRegistry.ts @@ -17,6 +17,10 @@ import * as types from '@opentelemetry/types'; import { noopTracer } from './NoopTracer'; +/** + * An implementation of the {@link TracerRegistry} which returns an impotent Tracer + * for all calls to `getTracer` + */ export class NoopTracerRegistry implements types.TracerRegistry { getTracer(_name?: string, _version?: string): types.Tracer { return noopTracer; From 660f41f9f56dae1e688501f391a047954f824517 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Fri, 27 Dec 2019 09:39:55 -0500 Subject: [PATCH 19/24] chore: update ioredis for tracer registry --- .../opentelemetry-plugin-ioredis/package.json | 3 +- .../scripts/version-update.js | 47 +++++++++++++++ .../src/ioredis.ts | 3 +- .../src/version.ts | 18 ++++++ .../test/ioredis.test.ts | 58 +++++++++---------- 5 files changed, 98 insertions(+), 31 deletions(-) create mode 100644 packages/opentelemetry-plugin-ioredis/scripts/version-update.js create mode 100644 packages/opentelemetry-plugin-ioredis/src/version.ts diff --git a/packages/opentelemetry-plugin-ioredis/package.json b/packages/opentelemetry-plugin-ioredis/package.json index f95400abf5..968036068e 100644 --- a/packages/opentelemetry-plugin-ioredis/package.json +++ b/packages/opentelemetry-plugin-ioredis/package.json @@ -13,7 +13,8 @@ "clean": "rimraf build/*", "check": "gts check", "precompile": "tsc --version", - "compile": "tsc -p .", + "version:update": "node scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "fix": "gts fix", "prepare": "npm run compile" diff --git a/packages/opentelemetry-plugin-ioredis/scripts/version-update.js b/packages/opentelemetry-plugin-ioredis/scripts/version-update.js new file mode 100644 index 0000000000..2bb382ce6d --- /dev/null +++ b/packages/opentelemetry-plugin-ioredis/scripts/version-update.js @@ -0,0 +1,47 @@ +/*! + * 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. + */ + +const license = +`/*! + * 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. + */ +`; + +const fs = require('fs'); +const path = require('path'); + +const appRoot = path.resolve(__dirname); +const fileUrl = path.resolve(`${appRoot}/../src/version.ts`); +const packageJsonUrl = path.resolve(`${appRoot}/../package.json`); +const pjson = require(packageJsonUrl); +const content = ` +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '${pjson.version}'; +`; + +fs.writeFileSync(fileUrl, `${license}${content}`); diff --git a/packages/opentelemetry-plugin-ioredis/src/ioredis.ts b/packages/opentelemetry-plugin-ioredis/src/ioredis.ts index 4fedf82c53..428e174057 100644 --- a/packages/opentelemetry-plugin-ioredis/src/ioredis.ts +++ b/packages/opentelemetry-plugin-ioredis/src/ioredis.ts @@ -18,6 +18,7 @@ import { BasePlugin } from '@opentelemetry/core'; import * as ioredisTypes from 'ioredis'; import * as shimmer from 'shimmer'; import { traceConnection, traceSendCommand } from './utils'; +import { VERSION } from './version'; export class IORedisPlugin extends BasePlugin { static readonly COMPONENT = 'ioredis'; @@ -25,7 +26,7 @@ export class IORedisPlugin extends BasePlugin { readonly supportedVersions = ['^2.0.0']; constructor(readonly moduleName: string) { - super(); + super('@opentelemetry/plugin-ioredis', VERSION); } protected patch(): typeof ioredisTypes { diff --git a/packages/opentelemetry-plugin-ioredis/src/version.ts b/packages/opentelemetry-plugin-ioredis/src/version.ts new file mode 100644 index 0000000000..60ca3ab548 --- /dev/null +++ b/packages/opentelemetry-plugin-ioredis/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-ioredis/test/ioredis.test.ts b/packages/opentelemetry-plugin-ioredis/test/ioredis.test.ts index ba68af4dd4..f0bd1a1551 100644 --- a/packages/opentelemetry-plugin-ioredis/test/ioredis.test.ts +++ b/packages/opentelemetry-plugin-ioredis/test/ioredis.test.ts @@ -19,7 +19,7 @@ import { InMemorySpanExporter, SimpleSpanProcessor, } from '@opentelemetry/tracing'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { plugin, IORedisPlugin } from '../src'; import * as ioredisTypes from 'ioredis'; import { NoopLogger } from '@opentelemetry/core'; @@ -49,7 +49,7 @@ const okStatus: Status = { }; describe('ioredis', () => { - const tracer = new NodeTracer(); + const registry = new NodeTracerRegistry(); let ioredis: typeof ioredisTypes; const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL; const shouldTest = process.env.RUN_REDIS_TESTS || shouldTestLocal; @@ -68,8 +68,8 @@ describe('ioredis', () => { } ioredis = require('ioredis'); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); - plugin.enable(ioredis, tracer, new NoopLogger()); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + plugin.enable(ioredis, registry, new NoopLogger()); }); after(() => { @@ -84,7 +84,7 @@ describe('ioredis', () => { describe('#createClient()', () => { it('should propagate the current span to event handlers', done => { - const span = tracer.startSpan('test span'); + const span = registry.getTracer("ioredis-test").startSpan('test span'); let client: ioredisTypes.Redis; const attributes = { ...DEFAULT_ATTRIBUTES, @@ -93,7 +93,7 @@ describe('ioredis', () => { const readyHandler = () => { const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(tracer.getCurrentSpan(), span); + assert.strictEqual(registry.getTracer("ioredis-test").getCurrentSpan(), span); assert.strictEqual(endedSpans.length, 2); assert.strictEqual(endedSpans[0].name, `connect`); assert.strictEqual(endedSpans[1].name, `info`); @@ -119,7 +119,7 @@ describe('ioredis', () => { client.quit(done); }; - tracer.withSpan(span, () => { + registry.getTracer("ioredis-test").withSpan(span, () => { client = new ioredis(URL); client.on('ready', readyHandler); client.on('error', errorHandler); @@ -183,8 +183,8 @@ describe('ioredis', () => { ' ' )}`, }; - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer("ioredis-test").startSpan('test span'); + registry.getTracer("ioredis-test").withSpan(span, () => { command.method((err, _result) => { assert.ifError(err); assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); @@ -211,8 +211,8 @@ describe('ioredis', () => { ...DEFAULT_ATTRIBUTES, [AttributeNames.DB_STATEMENT]: 'hset hash random random', }; - const span = tracer.startSpan('test span'); - await tracer.withSpan(span, async () => { + const span = registry.getTracer("ioredis-test").startSpan('test span'); + await registry.getTracer("ioredis-test").withSpan(span, async () => { try { await client.hset('hash', 'random', 'random'); assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); @@ -239,8 +239,8 @@ describe('ioredis', () => { ...DEFAULT_ATTRIBUTES, [AttributeNames.DB_STATEMENT]: 'scan 0', }; - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer("ioredis-test").startSpan('test span'); + registry.getTracer("ioredis-test").withSpan(span, () => { const stream = client.scanStream(); stream .on('data', resultKeys => { @@ -275,8 +275,8 @@ describe('ioredis', () => { }); it('should create a child span for pubsub', async () => { - const span = tracer.startSpan('test span'); - await tracer.withSpan(span, async () => { + const span = registry.getTracer("ioredis-test").startSpan('test span'); + await registry.getTracer("ioredis-test").withSpan(span, async () => { try { const pub = new ioredis(URL); const sub = new ioredis(URL); @@ -334,8 +334,8 @@ describe('ioredis', () => { [AttributeNames.DB_STATEMENT]: 'eval return {KEYS[1],ARGV[1]} 1 test', }; - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer("ioredis-test").startSpan('test span'); + registry.getTracer("ioredis-test").withSpan(span, () => { // This will define a command echo: client.defineCommand('echo', { numberOfKeys: 1, @@ -372,8 +372,8 @@ describe('ioredis', () => { [AttributeNames.DB_STATEMENT]: 'multi', }; - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer("ioredis-test").startSpan('test span'); + registry.getTracer("ioredis-test").withSpan(span, () => { client .multi() .set('foo', 'bar') @@ -408,8 +408,8 @@ describe('ioredis', () => { [AttributeNames.DB_STATEMENT]: 'set foo bar', }; - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer("ioredis-test").startSpan('test span'); + registry.getTracer("ioredis-test").withSpan(span, () => { const pipeline = client.pipeline(); pipeline.set('foo', 'bar'); pipeline.del('cc'); @@ -441,8 +441,8 @@ describe('ioredis', () => { ...DEFAULT_ATTRIBUTES, [AttributeNames.DB_STATEMENT]: 'get test', }; - const span = tracer.startSpan('test span'); - await tracer.withSpan(span, async () => { + const span = registry.getTracer("ioredis-test").startSpan('test span'); + await registry.getTracer("ioredis-test").withSpan(span, async () => { try { const value = await client.get('test'); assert.strictEqual(value, 'data'); @@ -470,8 +470,8 @@ describe('ioredis', () => { ...DEFAULT_ATTRIBUTES, [AttributeNames.DB_STATEMENT]: 'del test', }; - const span = tracer.startSpan('test span'); - await tracer.withSpan(span, async () => { + const span = registry.getTracer("ioredis-test").startSpan('test span'); + await registry.getTracer("ioredis-test").withSpan(span, async () => { try { const result = await client.del('test'); assert.strictEqual(result, 1); @@ -502,8 +502,8 @@ describe('ioredis', () => { IOREDIS_CALLBACK_OPERATIONS.forEach(operation => { it(`should not create a child span for cb style ${operation.description}`, done => { - const span = tracer.startSpan('test span'); - tracer.withSpan(span, () => { + const span = registry.getTracer("ioredis-test").startSpan('test span'); + registry.getTracer("ioredis-test").withSpan(span, () => { operation.method((err, _) => { assert.ifError(err); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); @@ -518,8 +518,8 @@ describe('ioredis', () => { }); it('should not create a child span for hset promise upon error', async () => { - const span = tracer.startSpan('test span'); - await tracer.withSpan(span, async () => { + const span = registry.getTracer("ioredis-test").startSpan('test span'); + await registry.getTracer("ioredis-test").withSpan(span, async () => { try { await client.hset('hash', 'random', 'random'); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); From 8e6399e3b3d31162aab219430d1571603eb63260 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Fri, 27 Dec 2019 09:43:41 -0500 Subject: [PATCH 20/24] chore: update pg pool for tracer registry --- .../src/pg-pool.ts | 3 ++- .../test/pg-pool.test.ts | 26 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/pg-pool.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/pg-pool.ts index be335c1203..ad97527bd5 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/pg-pool.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/pg-pool.ts @@ -25,6 +25,7 @@ import { PgPoolExtended, } from './types'; import * as utils from './utils'; +import { VERSION } from './version'; export class PostgresPoolPlugin extends BasePlugin { protected _config: PostgresPoolPluginOptions; @@ -35,7 +36,7 @@ export class PostgresPoolPlugin extends BasePlugin { readonly supportedVersions = ['2.*']; constructor(readonly moduleName: string) { - super(); + super("@opentelemetry/plugin-pg-pool", VERSION); this._config = {}; } diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts index 28ad86113a..aa549b279d 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts @@ -15,7 +15,7 @@ */ import { NoopLogger } from '@opentelemetry/core'; -import { NodeTracer } from '@opentelemetry/node'; +import { NodeTracerRegistry } from '@opentelemetry/node'; import { InMemorySpanExporter, SimpleSpanProcessor, @@ -92,7 +92,7 @@ const runCallbackTest = ( describe('pg-pool@2.x', () => { let pool: pgPool; - const tracer = new NodeTracer(); + const registry = new NodeTracerRegistry(); const logger = new NoopLogger(); const testPostgres = process.env.TEST_POSTGRES; // For CI: assumes local postgres db is already available const testPostgresLocally = process.env.TEST_POSTGRES_LOCAL; // For local: spins up local postgres db via docker @@ -106,7 +106,7 @@ describe('pg-pool@2.x', () => { this.skip(); } pool = new pgPool(CONFIG); - tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); + registry.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); if (testPostgresLocally) { testUtils.startDocker('postgres'); } @@ -123,8 +123,8 @@ describe('pg-pool@2.x', () => { }); beforeEach(function() { - plugin.enable(pgPool, tracer, logger); - pgPlugin.enable(pg, tracer, logger); + plugin.enable(pgPool, registry, logger); + pgPlugin.enable(pg, registry, logger); }); afterEach(() => { @@ -152,8 +152,8 @@ describe('pg-pool@2.x', () => { [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - await tracer.withSpan(span, async () => { + const span = registry.getTracer("test-pg-pool").startSpan('test span'); + await registry.getTracer("test-pg-pool").withSpan(span, async () => { const client = await pool.connect(); runCallbackTest(span, pgPoolattributes, events, okStatus, 1, 0); assert.ok(client, 'pool.connect() returns a promise'); @@ -178,8 +178,8 @@ describe('pg-pool@2.x', () => { [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; - const parentSpan = tracer.startSpan('test span'); - tracer.withSpan(parentSpan, () => { + const parentSpan = registry.getTracer("test-pg-pool").startSpan('test span'); + registry.getTracer("test-pg-pool").withSpan(parentSpan, () => { const resNoPromise = pool.connect((err, client, release) => { if (err) { return done(err); @@ -212,8 +212,8 @@ describe('pg-pool@2.x', () => { [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; - const span = tracer.startSpan('test span'); - await tracer.withSpan(span, async () => { + const span = registry.getTracer("test-pg-pool").startSpan('test span'); + await registry.getTracer("test-pg-pool").withSpan(span, async () => { try { const result = await pool.query('SELECT NOW()'); runCallbackTest(span, pgPoolattributes, events, okStatus, 2, 0); @@ -235,8 +235,8 @@ describe('pg-pool@2.x', () => { [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; - const parentSpan = tracer.startSpan('test span'); - tracer.withSpan(parentSpan, () => { + const parentSpan = registry.getTracer("test-pg-pool").startSpan('test span'); + registry.getTracer("test-pg-pool").withSpan(parentSpan, () => { const resNoPromise = pool.query('SELECT NOW()', (err, result) => { if (err) { return done(err); From bd0be2c2ecd39f3c6d60af09def785afa3a428bb Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 30 Dec 2019 11:54:42 -0500 Subject: [PATCH 21/24] fix: lint --- .../test/ioredis.test.ts | 57 +++++++++++-------- .../src/pg-pool.ts | 2 +- .../test/pg-pool.test.ts | 20 ++++--- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/packages/opentelemetry-plugin-ioredis/test/ioredis.test.ts b/packages/opentelemetry-plugin-ioredis/test/ioredis.test.ts index f0bd1a1551..3f99e22216 100644 --- a/packages/opentelemetry-plugin-ioredis/test/ioredis.test.ts +++ b/packages/opentelemetry-plugin-ioredis/test/ioredis.test.ts @@ -84,7 +84,7 @@ describe('ioredis', () => { describe('#createClient()', () => { it('should propagate the current span to event handlers', done => { - const span = registry.getTracer("ioredis-test").startSpan('test span'); + const span = registry.getTracer('ioredis-test').startSpan('test span'); let client: ioredisTypes.Redis; const attributes = { ...DEFAULT_ATTRIBUTES, @@ -93,7 +93,10 @@ describe('ioredis', () => { const readyHandler = () => { const endedSpans = memoryExporter.getFinishedSpans(); - assert.strictEqual(registry.getTracer("ioredis-test").getCurrentSpan(), span); + assert.strictEqual( + registry.getTracer('ioredis-test').getCurrentSpan(), + span + ); assert.strictEqual(endedSpans.length, 2); assert.strictEqual(endedSpans[0].name, `connect`); assert.strictEqual(endedSpans[1].name, `info`); @@ -119,7 +122,7 @@ describe('ioredis', () => { client.quit(done); }; - registry.getTracer("ioredis-test").withSpan(span, () => { + registry.getTracer('ioredis-test').withSpan(span, () => { client = new ioredis(URL); client.on('ready', readyHandler); client.on('error', errorHandler); @@ -183,8 +186,10 @@ describe('ioredis', () => { ' ' )}`, }; - const span = registry.getTracer("ioredis-test").startSpan('test span'); - registry.getTracer("ioredis-test").withSpan(span, () => { + const span = registry + .getTracer('ioredis-test') + .startSpan('test span'); + registry.getTracer('ioredis-test').withSpan(span, () => { command.method((err, _result) => { assert.ifError(err); assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); @@ -211,8 +216,8 @@ describe('ioredis', () => { ...DEFAULT_ATTRIBUTES, [AttributeNames.DB_STATEMENT]: 'hset hash random random', }; - const span = registry.getTracer("ioredis-test").startSpan('test span'); - await registry.getTracer("ioredis-test").withSpan(span, async () => { + const span = registry.getTracer('ioredis-test').startSpan('test span'); + await registry.getTracer('ioredis-test').withSpan(span, async () => { try { await client.hset('hash', 'random', 'random'); assert.strictEqual(memoryExporter.getFinishedSpans().length, 1); @@ -239,8 +244,8 @@ describe('ioredis', () => { ...DEFAULT_ATTRIBUTES, [AttributeNames.DB_STATEMENT]: 'scan 0', }; - const span = registry.getTracer("ioredis-test").startSpan('test span'); - registry.getTracer("ioredis-test").withSpan(span, () => { + const span = registry.getTracer('ioredis-test').startSpan('test span'); + registry.getTracer('ioredis-test').withSpan(span, () => { const stream = client.scanStream(); stream .on('data', resultKeys => { @@ -275,8 +280,8 @@ describe('ioredis', () => { }); it('should create a child span for pubsub', async () => { - const span = registry.getTracer("ioredis-test").startSpan('test span'); - await registry.getTracer("ioredis-test").withSpan(span, async () => { + const span = registry.getTracer('ioredis-test').startSpan('test span'); + await registry.getTracer('ioredis-test').withSpan(span, async () => { try { const pub = new ioredis(URL); const sub = new ioredis(URL); @@ -334,8 +339,8 @@ describe('ioredis', () => { [AttributeNames.DB_STATEMENT]: 'eval return {KEYS[1],ARGV[1]} 1 test', }; - const span = registry.getTracer("ioredis-test").startSpan('test span'); - registry.getTracer("ioredis-test").withSpan(span, () => { + const span = registry.getTracer('ioredis-test').startSpan('test span'); + registry.getTracer('ioredis-test').withSpan(span, () => { // This will define a command echo: client.defineCommand('echo', { numberOfKeys: 1, @@ -372,8 +377,8 @@ describe('ioredis', () => { [AttributeNames.DB_STATEMENT]: 'multi', }; - const span = registry.getTracer("ioredis-test").startSpan('test span'); - registry.getTracer("ioredis-test").withSpan(span, () => { + const span = registry.getTracer('ioredis-test').startSpan('test span'); + registry.getTracer('ioredis-test').withSpan(span, () => { client .multi() .set('foo', 'bar') @@ -408,8 +413,8 @@ describe('ioredis', () => { [AttributeNames.DB_STATEMENT]: 'set foo bar', }; - const span = registry.getTracer("ioredis-test").startSpan('test span'); - registry.getTracer("ioredis-test").withSpan(span, () => { + const span = registry.getTracer('ioredis-test').startSpan('test span'); + registry.getTracer('ioredis-test').withSpan(span, () => { const pipeline = client.pipeline(); pipeline.set('foo', 'bar'); pipeline.del('cc'); @@ -441,8 +446,8 @@ describe('ioredis', () => { ...DEFAULT_ATTRIBUTES, [AttributeNames.DB_STATEMENT]: 'get test', }; - const span = registry.getTracer("ioredis-test").startSpan('test span'); - await registry.getTracer("ioredis-test").withSpan(span, async () => { + const span = registry.getTracer('ioredis-test').startSpan('test span'); + await registry.getTracer('ioredis-test').withSpan(span, async () => { try { const value = await client.get('test'); assert.strictEqual(value, 'data'); @@ -470,8 +475,8 @@ describe('ioredis', () => { ...DEFAULT_ATTRIBUTES, [AttributeNames.DB_STATEMENT]: 'del test', }; - const span = registry.getTracer("ioredis-test").startSpan('test span'); - await registry.getTracer("ioredis-test").withSpan(span, async () => { + const span = registry.getTracer('ioredis-test').startSpan('test span'); + await registry.getTracer('ioredis-test').withSpan(span, async () => { try { const result = await client.del('test'); assert.strictEqual(result, 1); @@ -502,8 +507,10 @@ describe('ioredis', () => { IOREDIS_CALLBACK_OPERATIONS.forEach(operation => { it(`should not create a child span for cb style ${operation.description}`, done => { - const span = registry.getTracer("ioredis-test").startSpan('test span'); - registry.getTracer("ioredis-test").withSpan(span, () => { + const span = registry + .getTracer('ioredis-test') + .startSpan('test span'); + registry.getTracer('ioredis-test').withSpan(span, () => { operation.method((err, _) => { assert.ifError(err); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); @@ -518,8 +525,8 @@ describe('ioredis', () => { }); it('should not create a child span for hset promise upon error', async () => { - const span = registry.getTracer("ioredis-test").startSpan('test span'); - await registry.getTracer("ioredis-test").withSpan(span, async () => { + const span = registry.getTracer('ioredis-test').startSpan('test span'); + await registry.getTracer('ioredis-test').withSpan(span, async () => { try { await client.hset('hash', 'random', 'random'); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/pg-pool.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/pg-pool.ts index ad97527bd5..0584e29f83 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/pg-pool.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/pg-pool.ts @@ -36,7 +36,7 @@ export class PostgresPoolPlugin extends BasePlugin { readonly supportedVersions = ['2.*']; constructor(readonly moduleName: string) { - super("@opentelemetry/plugin-pg-pool", VERSION); + super('@opentelemetry/plugin-pg-pool', VERSION); this._config = {}; } diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts index aa549b279d..f2f3ebb862 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts @@ -152,8 +152,8 @@ describe('pg-pool@2.x', () => { [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; - const span = registry.getTracer("test-pg-pool").startSpan('test span'); - await registry.getTracer("test-pg-pool").withSpan(span, async () => { + const span = registry.getTracer('test-pg-pool').startSpan('test span'); + await registry.getTracer('test-pg-pool').withSpan(span, async () => { const client = await pool.connect(); runCallbackTest(span, pgPoolattributes, events, okStatus, 1, 0); assert.ok(client, 'pool.connect() returns a promise'); @@ -178,8 +178,10 @@ describe('pg-pool@2.x', () => { [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; - const parentSpan = registry.getTracer("test-pg-pool").startSpan('test span'); - registry.getTracer("test-pg-pool").withSpan(parentSpan, () => { + const parentSpan = registry + .getTracer('test-pg-pool') + .startSpan('test span'); + registry.getTracer('test-pg-pool').withSpan(parentSpan, () => { const resNoPromise = pool.connect((err, client, release) => { if (err) { return done(err); @@ -212,8 +214,8 @@ describe('pg-pool@2.x', () => { [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; - const span = registry.getTracer("test-pg-pool").startSpan('test span'); - await registry.getTracer("test-pg-pool").withSpan(span, async () => { + const span = registry.getTracer('test-pg-pool').startSpan('test span'); + await registry.getTracer('test-pg-pool').withSpan(span, async () => { try { const result = await pool.query('SELECT NOW()'); runCallbackTest(span, pgPoolattributes, events, okStatus, 2, 0); @@ -235,8 +237,10 @@ describe('pg-pool@2.x', () => { [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; - const parentSpan = registry.getTracer("test-pg-pool").startSpan('test span'); - registry.getTracer("test-pg-pool").withSpan(parentSpan, () => { + const parentSpan = registry + .getTracer('test-pg-pool') + .startSpan('test span'); + registry.getTracer('test-pg-pool').withSpan(parentSpan, () => { const resNoPromise = pool.query('SELECT NOW()', (err, result) => { if (err) { return done(err); From 7c39151c8f1dc0aa5ec6baf04fd5f9dc40ef25ca Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Fri, 3 Jan 2020 09:37:20 -0500 Subject: [PATCH 22/24] chore: fix tests --- .../test/utils/httpsRequest.ts | 93 +++++++++---------- 1 file changed, 45 insertions(+), 48 deletions(-) diff --git a/packages/opentelemetry-plugin-https/test/utils/httpsRequest.ts b/packages/opentelemetry-plugin-https/test/utils/httpsRequest.ts index c5436be763..dfef6da4c8 100644 --- a/packages/opentelemetry-plugin-https/test/utils/httpsRequest.ts +++ b/packages/opentelemetry-plugin-https/test/utils/httpsRequest.ts @@ -16,59 +16,56 @@ import * as http from 'http'; import * as https from 'https'; -import { RequestOptions } from 'https'; -import * as url from 'url'; +import { URL } from 'url'; process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; -export const httpsRequest = { - get: ( - options: string | RequestOptions - ): Promise<{ - data: string; - statusCode: number | undefined; - resHeaders: http.IncomingHttpHeaders; - reqHeaders: http.OutgoingHttpHeaders; - method: string | undefined; - }> => { - const _options = - typeof options === 'string' - ? Object.assign(url.parse(options), { - headers: { - 'user-agent': 'https-plugin-test', - }, - }) - : options; - return new Promise((resolve, reject) => { - const req = https.get(_options, (resp: http.IncomingMessage) => { - const res = (resp as unknown) as http.IncomingMessage & { - req: http.IncomingMessage; - }; - let data = ''; - resp.on('data', chunk => { - data += chunk; - }); - resp.on('end', () => { - resolve({ - data, - statusCode: res.statusCode, - /* tslint:disable:no-any */ - reqHeaders: (res.req as any).getHeaders - ? (res.req as any).getHeaders() - : (res.req as any)._headers, - /* tslint:enable:no-any */ - resHeaders: res.headers, - method: res.req.method, - }); - }); - resp.on('error', err => { - reject(err); +type GetResult = Promise<{ + data: string; + statusCode: number | undefined; + resHeaders: http.IncomingHttpHeaders; + reqHeaders: http.OutgoingHttpHeaders; + method: string | undefined; +}>; + +function get(input: string | URL, options?: https.RequestOptions): GetResult; +function get(input: https.RequestOptions): GetResult; +function get(input: any, options?: any): GetResult { + return new Promise((resolve, reject) => { + let req: http.ClientRequest; + + function onGetResponseCb(resp: http.IncomingMessage): void { + const res = (resp as unknown) as http.IncomingMessage & { + req: http.IncomingMessage; + }; + let data = ''; + resp.on('data', chunk => { + data += chunk; + }); + resp.on('end', () => { + resolve({ + data, + statusCode: res.statusCode, + reqHeaders: req.getHeaders ? req.getHeaders() : (req as any)._headers, + resHeaders: res.headers, + method: res.req.method, }); }); - req.on('error', err => { + resp.on('error', err => { reject(err); }); - return req; + } + req = + options != null + ? https.get(input, options, onGetResponseCb) + : https.get(input, onGetResponseCb); + req.on('error', err => { + reject(err); }); - }, -}; + return req; + }); +} + +export const httpsRequest = { + get, +}; \ No newline at end of file From e814df6a49651a71bdbf1c84098a2c2bbbb80315 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Fri, 3 Jan 2020 09:45:12 -0500 Subject: [PATCH 23/24] chore: lint --- .../opentelemetry-plugin-http/src/http.ts | 26 ++++++++++++++++--- .../test/functionals/https-enable.test.ts | 2 +- .../test/integrations/https-enable.test.ts | 9 +++++-- .../test/utils/httpsRequest.ts | 2 +- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index f1e809a444..f45fb6ac56 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -15,15 +15,35 @@ */ import { BasePlugin, isValid } from '@opentelemetry/core'; -import { CanonicalCode, Span, SpanKind, SpanOptions, Status } from '@opentelemetry/types'; -import { ClientRequest, IncomingMessage, request, RequestOptions, ServerResponse } from 'http'; +import { + CanonicalCode, + Span, + SpanKind, + SpanOptions, + Status, +} from '@opentelemetry/types'; +import { + ClientRequest, + IncomingMessage, + request, + RequestOptions, + ServerResponse, +} from 'http'; import { Socket } from 'net'; import * as semver from 'semver'; import * as shimmer from 'shimmer'; import * as url from 'url'; import { AttributeNames } from './enums/AttributeNames'; import { Format } from './enums/Format'; -import { Err, Func, Http, HttpPluginConfig, HttpRequestArgs, ParsedRequestOptions, ResponseEndArgs } from './types'; +import { + Err, + Func, + Http, + HttpPluginConfig, + HttpRequestArgs, + ParsedRequestOptions, + ResponseEndArgs, +} from './types'; import * as utils from './utils'; import { VERSION } from './version'; diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts index 9e4e30eb97..477b2b906c 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts @@ -681,4 +681,4 @@ describe('HttpsPlugin', () => { }); }); }); -}); \ No newline at end of file +}); diff --git a/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts index ef34ed8f08..2f7192fdf3 100644 --- a/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts @@ -88,7 +88,12 @@ describe('HttpsPlugin Integration tests', () => { try { plugin.disable(); } catch (e) {} - plugin.enable((https as unknown) as Http, registry, registry.logger, config); + plugin.enable( + (https as unknown) as Http, + registry, + registry.logger, + config + ); }); after(() => { @@ -291,4 +296,4 @@ describe('HttpsPlugin Integration tests', () => { }); } }); -}); \ No newline at end of file +}); diff --git a/packages/opentelemetry-plugin-https/test/utils/httpsRequest.ts b/packages/opentelemetry-plugin-https/test/utils/httpsRequest.ts index dfef6da4c8..e96a12fce5 100644 --- a/packages/opentelemetry-plugin-https/test/utils/httpsRequest.ts +++ b/packages/opentelemetry-plugin-https/test/utils/httpsRequest.ts @@ -68,4 +68,4 @@ function get(input: any, options?: any): GetResult { export const httpsRequest = { get, -}; \ No newline at end of file +}; From cd47354292bc699df1401fad0da393309fdc4e5f Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 6 Jan 2020 12:34:55 -0500 Subject: [PATCH 24/24] chore: lint --- packages/opentelemetry-plugin-mongodb/test/mongodb.test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/opentelemetry-plugin-mongodb/test/mongodb.test.ts b/packages/opentelemetry-plugin-mongodb/test/mongodb.test.ts index beddd735cb..099a6a21a1 100644 --- a/packages/opentelemetry-plugin-mongodb/test/mongodb.test.ts +++ b/packages/opentelemetry-plugin-mongodb/test/mongodb.test.ts @@ -79,10 +79,7 @@ function assertSpans( const [mongoSpan] = spans; assert.strictEqual(mongoSpan.name, expectedName); assert.strictEqual(mongoSpan.kind, expectedKind); - assert.strictEqual( - mongoSpan.attributes[AttributeNames.COMPONENT], - 'mongodb' - ); + assert.strictEqual(mongoSpan.attributes[AttributeNames.COMPONENT], 'mongodb'); assert.strictEqual( mongoSpan.attributes[AttributeNames.PEER_HOSTNAME], process.env.MONGODB_HOST || 'localhost'