diff --git a/examples/prometheus/index.js b/examples/prometheus/index.js index 166dff8e94..fea1d1c9d8 100644 --- a/examples/prometheus/index.js +++ b/examples/prometheus/index.js @@ -1,9 +1,9 @@ "use strict"; -const { Meter } = require("@opentelemetry/metrics"); -const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus"); +const { MeterRegistry } = require('@opentelemetry/metrics'); +const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('example-prometheus'); const exporter = new PrometheusExporter( { diff --git a/getting-started/README.md b/getting-started/README.md index ae6bb5a15b..61ae41d7e8 100644 --- a/getting-started/README.md +++ b/getting-started/README.md @@ -238,9 +238,9 @@ Create a file named `monitoring.js` and add the following code: ```javascript 'use strict'; -const { Meter } = require("@opentelemetry/metrics"); +const { MeterRegistry } = require('@opentelemetry/metrics'); -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); ``` Now, you can require this file from your application code and use the `Meter` to create and manage metrics. The simplest of these metrics is a counter. Let's create and export from our `monitoring.js` file a middleware function that express can use to count all requests by route. Modify the `monitoring.js` file so that it looks like this: @@ -248,9 +248,9 @@ Now, you can require this file from your application code and use the `Meter` to ```javascript 'use strict'; -const { Meter } = require("@opentelemetry/metrics"); +const { MeterRegistry } = require('@opentelemetry/metrics'); -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); const requestCount = meter.createCounter("requests", { monotonic: true, @@ -301,10 +301,10 @@ Next, modify your `monitoring.js` file to look like this: ```javascript "use strict"; -const { Meter } = require("@opentelemetry/metrics"); -const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus"); +const { MeterRegistry } = require('@opentelemetry/metrics'); +const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); meter.addExporter( new PrometheusExporter( diff --git a/getting-started/monitored-example/monitoring.js b/getting-started/monitored-example/monitoring.js index 8eb1984f68..4567c158d1 100644 --- a/getting-started/monitored-example/monitoring.js +++ b/getting-started/monitored-example/monitoring.js @@ -1,9 +1,9 @@ "use strict"; -const { Meter } = require("@opentelemetry/metrics"); -const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus"); +const { MeterRegistry } = require('@opentelemetry/metrics'); +const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('example-monitored'); meter.addExporter( new PrometheusExporter( diff --git a/getting-started/ts-example/README.md b/getting-started/ts-example/README.md index 0a76f4a658..ac188fcfb4 100644 --- a/getting-started/ts-example/README.md +++ b/getting-started/ts-example/README.md @@ -72,8 +72,8 @@ All tracing initialization should happen before your application’s code runs. Create a file named `tracing.ts` and add the following code: ```typescript -import * as opentelemetry from "@opentelemetry/core"; -import { NodeTracer } from "@opentelemetry/node"; +import * as opentelemetry from '@opentelemetry/core'; +import { NodeTracer } from '@opentelemetry/node'; const tracer: NodeTracer = new NodeTracer({ logLevel: opentelemetry.LogLevel.ERROR @@ -106,13 +106,13 @@ $ # npm install @opentelemetry/exporter-jaeger After these dependencies are installed, we will need to initialize and register them. Modify `tracing.ts` so that it matches the following code snippet, replacing the service name `"getting-started"` with your own service name if you wish. ```typescript -import * as opentelemetry from "@opentelemetry/core"; -import { NodeTracer } from "@opentelemetry/node"; +import * as opentelemetry from '@opentelemetry/core'; +import { NodeTracer } from '@opentelemetry/node'; -import { SimpleSpanProcessor } from "@opentelemetry/tracing"; -import { ZipkinExporter } from "@opentelemetry/exporter-zipkin"; +import { SimpleSpanProcessor } from '@opentelemetry/tracing'; +import { ZipkinExporter } from '@opentelemetry/exporter-zipkin'; // For Jaeger, use the following line instead: -// import { JaegerExporter } from "@opentelemetry/exporter-jaeger"; +// import { JaegerExporter } from '@opentelemetry/exporter-jaeger'; const tracer: NodeTracer = new NodeTracer({ logLevel: opentelemetry.LogLevel.ERROR @@ -236,18 +236,18 @@ In order to create and monitor metrics, we will need a `Meter`. In OpenTelemetry Create a file named `monitoring.ts` and add the following code: ```typescript -import { Meter } from "@opentelemetry/metrics"; +import { MeterRegistry } from '@opentelemetry/metrics'; -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); ``` Now, you can require this file from your application code and use the `Meter` to create and manage metrics. The simplest of these metrics is a counter. Let's create and export from our `monitoring.ts` file a middleware function that express can use to count all requests by route. Modify the `monitoring.ts` file so that it looks like this: ```typescript -import { Meter } from "@opentelemetry/metrics"; -import { Metric, BoundCounter } from "@opentelemetry/types"; +import { MeterRegistry } from '@opentelemetry/metrics'; +import { Metric, BoundCounter } from '@opentelemetry/types'; -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); const requestCount: Metric = meter.createCounter("requests", { monotonic: true, @@ -296,11 +296,11 @@ $ npm install @opentelemetry/exporter-prometheus Next, modify your `monitoring.ts` file to look like this: ```typescript -import { Meter } from "@opentelemetry/metrics"; -import { Metric, BoundCounter } from "@opentelemetry/types"; -import { PrometheusExporter } from "@opentelemetry/exporter-prometheus"; +import { MeterRegistry } from '@opentelemetry/metrics'; +import { Metric, BoundCounter } from '@opentelemetry/types'; +import { PrometheusExporter } from '@opentelemetry/exporter-prometheus'; -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); meter.addExporter( new PrometheusExporter({ startServer: true }, () => { diff --git a/getting-started/ts-example/monitoring.ts b/getting-started/ts-example/monitoring.ts index e510eccdde..1dd3b57037 100644 --- a/getting-started/ts-example/monitoring.ts +++ b/getting-started/ts-example/monitoring.ts @@ -1,8 +1,8 @@ -import { Meter } from "@opentelemetry/metrics"; -import { Metric, BoundCounter } from "@opentelemetry/types"; -import { PrometheusExporter } from "@opentelemetry/exporter-prometheus"; +import { MeterRegistry } from '@opentelemetry/metrics'; +import { Metric, BoundCounter } from '@opentelemetry/types'; +import { PrometheusExporter } from '@opentelemetry/exporter-prometheus'; -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('example-ts'); meter.addExporter( new PrometheusExporter({ startServer: true }, () => { diff --git a/packages/opentelemetry-core/src/metrics/NoopMeter.ts b/packages/opentelemetry-core/src/metrics/NoopMeter.ts index 4f67d4c2d6..5e63905ae5 100644 --- a/packages/opentelemetry-core/src/metrics/NoopMeter.ts +++ b/packages/opentelemetry-core/src/metrics/NoopMeter.ts @@ -165,6 +165,8 @@ export class NoopBoundMeasure implements BoundMeasure { } } +export const noopMeter = new NoopMeter(); + export const NOOP_BOUND_GAUGE = new NoopBoundGauge(); export const NOOP_GAUGE_METRIC = new NoopGaugeMetric(NOOP_BOUND_GAUGE); diff --git a/packages/opentelemetry-core/src/metrics/NoopMeterRegistry.ts b/packages/opentelemetry-core/src/metrics/NoopMeterRegistry.ts new file mode 100644 index 0000000000..ab2a28e0ec --- /dev/null +++ b/packages/opentelemetry-core/src/metrics/NoopMeterRegistry.ts @@ -0,0 +1,28 @@ +/*! + * 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 { noopMeter } from './NoopMeter'; + +/** + * An implementation of the {@link MeterRegistry} which returns an impotent Meter + * for all calls to `getMeter` + */ +export class NoopMeterRegistry implements types.MeterRegistry { + getMeter(_name?: string, _version?: string): types.Meter { + return noopMeter; + } +} diff --git a/packages/opentelemetry-core/src/trace/NoopSpan.ts b/packages/opentelemetry-core/src/trace/NoopSpan.ts index 84a5cf4241..a6fb36da30 100644 --- a/packages/opentelemetry-core/src/trace/NoopSpan.ts +++ b/packages/opentelemetry-core/src/trace/NoopSpan.ts @@ -15,7 +15,6 @@ */ import * as types from '@opentelemetry/types'; -import { SpanContext } from '@opentelemetry/types'; import { INVALID_SPAN_CONTEXT } from '../trace/spancontext-utils'; /** @@ -25,7 +24,7 @@ import { INVALID_SPAN_CONTEXT } from '../trace/spancontext-utils'; */ export class NoopSpan implements types.Span { constructor( - private readonly _spanContext: SpanContext = INVALID_SPAN_CONTEXT + private readonly _spanContext: types.SpanContext = INVALID_SPAN_CONTEXT ) {} // Returns a SpanContext. diff --git a/packages/opentelemetry-core/test/metrics/NoopMeter.test.ts b/packages/opentelemetry-core/test/metrics/NoopMeter.test.ts index ade4d93025..1e15fdb6b5 100644 --- a/packages/opentelemetry-core/test/metrics/NoopMeter.test.ts +++ b/packages/opentelemetry-core/test/metrics/NoopMeter.test.ts @@ -16,7 +16,6 @@ import * as assert from 'assert'; import { - NoopMeter, NOOP_BOUND_GAUGE, NOOP_GAUGE_METRIC, NOOP_BOUND_COUNTER, @@ -25,10 +24,11 @@ import { NOOP_MEASURE_METRIC, } from '../../src/metrics/NoopMeter'; import { Labels } from '@opentelemetry/types'; +import { NoopMeterRegistry } from '../../src/metrics/NoopMeterRegistry'; describe('NoopMeter', () => { it('should not crash', () => { - const meter = new NoopMeter(); + const meter = new NoopMeterRegistry().getMeter('test-noop'); const counter = meter.createCounter('some-name'); const labels = {} as Labels; const labelSet = meter.labels(labels); diff --git a/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts b/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts index 4fc5ae0c05..71f1051eba 100644 --- a/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts +++ b/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts @@ -21,7 +21,6 @@ import { 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', () => { @@ -43,7 +42,7 @@ describe('globaltracer-utils', () => { const spanContext = { traceId: 'd4cda95b652f4a1592b449d5929fda1b', spanId: '6e0c63257de34c92', - traceFlags: TraceFlags.UNSAMPLED, + traceFlags: types.TraceFlags.UNSAMPLED, }; const dummySpan = new NoopSpan(spanContext); diff --git a/packages/opentelemetry-exporter-prometheus/README.md b/packages/opentelemetry-exporter-prometheus/README.md index 67cb64ba4d..0fddcd8bfc 100644 --- a/packages/opentelemetry-exporter-prometheus/README.md +++ b/packages/opentelemetry-exporter-prometheus/README.md @@ -22,14 +22,14 @@ Create & register the exporter on your application. ```js const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); -const { Meter } = require('@opentelemetry/metrics'); +const { MeterRegistry } = require('@opentelemetry/metrics'); // Add your port and startServer to the Prometheus options const options = {port: 9464, startServer: true}; const exporter = new PrometheusExporter(options); // Register the exporter -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('exporter-prometheus'); meter.addExporter(exporter); // Now, start recording data diff --git a/packages/opentelemetry-exporter-prometheus/test/prometheus.test.ts b/packages/opentelemetry-exporter-prometheus/test/prometheus.test.ts index 16cec53885..a019dc8420 100644 --- a/packages/opentelemetry-exporter-prometheus/test/prometheus.test.ts +++ b/packages/opentelemetry-exporter-prometheus/test/prometheus.test.ts @@ -14,7 +14,12 @@ * limitations under the License. */ -import { CounterMetric, GaugeMetric, Meter } from '@opentelemetry/metrics'; +import { + CounterMetric, + GaugeMetric, + Meter, + MeterRegistry, +} from '@opentelemetry/metrics'; import * as assert from 'assert'; import * as http from 'http'; import { PrometheusExporter } from '../src'; @@ -166,7 +171,7 @@ describe('PrometheusExporter', () => { beforeEach(done => { exporter = new PrometheusExporter(); - meter = new Meter(); + meter = new MeterRegistry().getMeter('test-prometheus'); exporter.startServer(done); }); @@ -382,7 +387,7 @@ describe('PrometheusExporter', () => { let exporter: PrometheusExporter | undefined; beforeEach(() => { - meter = new Meter(); + meter = new MeterRegistry().getMeter('test-prometheus'); gauge = meter.createGauge('gauge') as GaugeMetric; gauge.bind(meter.labels({ key1: 'labelValue1' })).set(10); }); diff --git a/packages/opentelemetry-metrics/README.md b/packages/opentelemetry-metrics/README.md index a1c3b7a11b..c48868ced6 100644 --- a/packages/opentelemetry-metrics/README.md +++ b/packages/opentelemetry-metrics/README.md @@ -19,10 +19,10 @@ npm install --save @opentelemetry/metrics Choose this kind of metric when the value is a quantity, the sum is of primary interest, and the event count and value distribution are not of primary interest. Counters are defined as `Monotonic = true` by default, meaning that positive values are expected. ```js -const { Meter } = require('@opentelemetry/metrics'); +const { MeterRegistry } = require('@opentelemetry/metrics'); // Initialize the Meter to capture measurements in various ways. -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); const counter = meter.createCounter('metric_name', { labelKeys: ["pid"], @@ -40,10 +40,10 @@ boundCounter.add(10); Gauge metrics express a pre-calculated value. Generally, this kind of metric should be used when the metric cannot be expressed as a sum or because the measurement interval is arbitrary. Use this kind of metric when the measurement is not a quantity, and the sum and event count are not of interest. Gauges are defined as `Monotonic = false` by default, meaning that new values are permitted to make positive or negative changes to the gauge. There is no restriction on the sign of the input for gauges. ```js -const { Meter } = require('@opentelemetry/metrics'); +const { MeterRegistry } = require('@opentelemetry/metrics'); // Initialize the Meter to capture measurements in various ways. -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); const gauge = meter.createGauge('metric_name', { labelKeys: ["pid"], diff --git a/packages/opentelemetry-metrics/src/MeterRegistry.ts b/packages/opentelemetry-metrics/src/MeterRegistry.ts new file mode 100644 index 0000000000..c9eb683663 --- /dev/null +++ b/packages/opentelemetry-metrics/src/MeterRegistry.ts @@ -0,0 +1,46 @@ +/*! + * 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 { Meter } from '.'; +import { DEFAULT_CONFIG, MeterConfig } from './types'; + +/** + * This class represents a meter registry which platform libraries can extend + */ +export class MeterRegistry implements types.MeterRegistry { + private readonly _meters: Map = new Map(); + readonly logger: types.Logger; + + constructor(private _config: MeterConfig = DEFAULT_CONFIG) { + this.logger = _config.logger || new ConsoleLogger(_config.logLevel); + } + + /** + * Returns a Meter, creating one if one with the given name and version is not already created + * + * @returns Meter A Meter with the given name and version + */ + getMeter(name: string, version = '*', config?: MeterConfig): Meter { + const key = `${name}@${version}`; + if (!this._meters.has(key)) { + this._meters.set(key, new Meter(config || this._config)); + } + + return this._meters.get(key)!; + } +} diff --git a/packages/opentelemetry-metrics/src/index.ts b/packages/opentelemetry-metrics/src/index.ts index 0cd212f0b5..9a8b7f26d2 100644 --- a/packages/opentelemetry-metrics/src/index.ts +++ b/packages/opentelemetry-metrics/src/index.ts @@ -17,5 +17,6 @@ export * from './BoundInstrument'; export * from './Meter'; export * from './Metric'; +export * from './MeterRegistry'; export * from './export/ConsoleMetricExporter'; export * from './export/types'; diff --git a/packages/opentelemetry-metrics/test/Meter.test.ts b/packages/opentelemetry-metrics/test/Meter.test.ts index 57e19ceffe..f0269a5b24 100644 --- a/packages/opentelemetry-metrics/test/Meter.test.ts +++ b/packages/opentelemetry-metrics/test/Meter.test.ts @@ -31,6 +31,7 @@ import { hrTimeToMilliseconds, } from '@opentelemetry/core'; import { NoopExporter } from './mocks/Exporter'; +import { MeterRegistry } from '../src/MeterRegistry'; const performanceTimeOrigin = hrTime(); @@ -43,9 +44,9 @@ describe('Meter', () => { const hrTime: types.HrTime = [22, 400000000]; beforeEach(() => { - meter = new Meter({ + meter = new MeterRegistry({ logger: new NoopLogger(), - }); + }).getMeter('test-meter'); labelSet = meter.labels(labels); }); diff --git a/packages/opentelemetry-metrics/test/MeterRegistry.test.ts b/packages/opentelemetry-metrics/test/MeterRegistry.test.ts new file mode 100644 index 0000000000..e90b6c9baa --- /dev/null +++ b/packages/opentelemetry-metrics/test/MeterRegistry.test.ts @@ -0,0 +1,68 @@ +/*! + * 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 { NoopLogger } from '@opentelemetry/core'; +import * as assert from 'assert'; +import { MeterRegistry, Meter } from '../src'; + +describe('MeterRegistry', () => { + describe('constructor', () => { + it('should construct an instance without any options', () => { + const registry = new MeterRegistry(); + assert.ok(registry instanceof MeterRegistry); + }); + + it('should construct an instance with logger', () => { + const registry = new MeterRegistry({ + logger: new NoopLogger(), + }); + assert.ok(registry instanceof MeterRegistry); + }); + }); + + describe('getMeter', () => { + it('should return an instance of Meter', () => { + const meter = new MeterRegistry().getMeter('test-meter-registry'); + assert.ok(meter instanceof Meter); + }); + + it('should return the meter with default version without a version option', () => { + const registry = new MeterRegistry(); + const meter1 = registry.getMeter('default'); + const meter2 = registry.getMeter('default', '*'); + assert.deepEqual(meter1, meter2); + }); + + it('should return the same Meter instance with same name & version', () => { + const registry = new MeterRegistry(); + const meter1 = registry.getMeter('meter1', 'ver1'); + const meter2 = registry.getMeter('meter1', 'ver1'); + assert.deepEqual(meter1, meter2); + }); + + it('should return different Meter instance with different name or version', () => { + const registry = new MeterRegistry(); + + const meter1 = registry.getMeter('meter1', 'ver1'); + const meter2 = registry.getMeter('meter1'); + assert.notEqual(meter1, meter2); + + const meter3 = registry.getMeter('meter2', 'ver2'); + const meter4 = registry.getMeter('meter3', 'ver2'); + assert.notEqual(meter3, meter4); + }); + }); +}); diff --git a/packages/opentelemetry-metrics/test/export/ConsoleMetricExporter.test.ts b/packages/opentelemetry-metrics/test/export/ConsoleMetricExporter.test.ts index 996b423853..4c9e17e001 100644 --- a/packages/opentelemetry-metrics/test/export/ConsoleMetricExporter.test.ts +++ b/packages/opentelemetry-metrics/test/export/ConsoleMetricExporter.test.ts @@ -16,7 +16,8 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; -import { ConsoleMetricExporter, Meter } from '../../src'; +import { ConsoleMetricExporter } from '../../src'; +import { MeterRegistry } from '../../src/MeterRegistry'; describe('ConsoleMetricExporter', () => { let consoleExporter: ConsoleMetricExporter; @@ -36,7 +37,9 @@ describe('ConsoleMetricExporter', () => { it('should export information about metrics', () => { const spyConsole = sinon.spy(console, 'log'); - const meter = new Meter(); + const meter = new MeterRegistry().getMeter( + 'test-console-metric-exporter' + ); meter.addExporter(consoleExporter); const gauge = meter.createGauge('gauge', { description: 'a test description', 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 931e31756d..d21736db08 100644 --- a/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts +++ b/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts @@ -34,7 +34,6 @@ import { 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) {} @@ -101,7 +100,7 @@ describe('xhr', () => { let clearData: any; describe('when request is successful', () => { - let webTracerWithZone: Tracer; + let webTracerWithZone: types.Tracer; let webTracerRegistryWithZone: WebTracerRegistry; let dummySpanExporter: DummySpanExporter; let exportSpy: any; @@ -410,7 +409,7 @@ describe('xhr', () => { describe('when request is NOT successful', () => { let webTracerWithZoneRegistry: WebTracerRegistry; - let webTracerWithZone: Tracer; + let webTracerWithZone: types.Tracer; let dummySpanExporter: DummySpanExporter; let exportSpy: any; let rootSpan: types.Span; diff --git a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts index b646b4a516..64b0984304 100644 --- a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts +++ b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts @@ -16,7 +16,6 @@ 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'; @@ -31,7 +30,7 @@ export class BasicTracerRegistry implements types.TracerRegistry { private readonly _tracers: Map = new Map(); activeSpanProcessor = new NoopSpanProcessor(); - readonly logger: Logger; + readonly logger: types.Logger; constructor(private _config: TracerConfig = DEFAULT_CONFIG) { this.logger = _config.logger || new ConsoleLogger(_config.logLevel); diff --git a/packages/opentelemetry-tracing/src/Tracer.ts b/packages/opentelemetry-tracing/src/Tracer.ts index 504df8b588..00debfb803 100644 --- a/packages/opentelemetry-tracing/src/Tracer.ts +++ b/packages/opentelemetry-tracing/src/Tracer.ts @@ -22,12 +22,6 @@ import { NoRecordingSpan, ConsoleLogger, } from '@opentelemetry/core'; -import { - BinaryFormat, - HttpTextFormat, - TraceFlags, - Logger, -} from '@opentelemetry/types'; import { TracerConfig, TraceParams } from './types'; import { ScopeManager } from '@opentelemetry/scope-base'; import { Span } from './Span'; @@ -45,7 +39,7 @@ export class Tracer implements types.Tracer { private readonly _sampler: types.Sampler; private readonly _scopeManager: ScopeManager; private readonly _traceParams: TraceParams; - readonly logger: Logger; + readonly logger: types.Logger; /** * Constructs a new Tracer instance. @@ -84,8 +78,8 @@ export class Tracer implements types.Tracer { traceState = parentContext.traceState; } const traceFlags = samplingDecision - ? TraceFlags.SAMPLED - : TraceFlags.UNSAMPLED; + ? types.TraceFlags.SAMPLED + : types.TraceFlags.UNSAMPLED; const spanContext = { traceId, spanId, traceFlags, traceState }; const recordEvents = options.isRecording || false; if (!recordEvents && !samplingDecision) { @@ -145,14 +139,14 @@ export class Tracer implements types.Tracer { /** * Returns the binary format interface which can serialize/deserialize Spans. */ - getBinaryFormat(): BinaryFormat { + getBinaryFormat(): types.BinaryFormat { return this._binaryFormat; } /** * Returns the HTTP text format interface which can inject/extract Spans. */ - getHttpTextFormat(): HttpTextFormat { + getHttpTextFormat(): types.HttpTextFormat { return this._httpTextFormat; } diff --git a/packages/opentelemetry-types/src/index.ts b/packages/opentelemetry-types/src/index.ts index e73c896f2e..e8f77714d3 100644 --- a/packages/opentelemetry-types/src/index.ts +++ b/packages/opentelemetry-types/src/index.ts @@ -22,6 +22,7 @@ export * from './distributed_context/DistributedContext'; export * from './distributed_context/EntryValue'; export * from './metrics/BoundInstrument'; export * from './metrics/Meter'; +export * from './metrics/MeterRegistry'; export * from './metrics/Metric'; export * from './trace/attributes'; export * from './trace/Event'; diff --git a/packages/opentelemetry-types/src/metrics/MeterRegistry.ts b/packages/opentelemetry-types/src/metrics/MeterRegistry.ts new file mode 100644 index 0000000000..75a36272da --- /dev/null +++ b/packages/opentelemetry-types/src/metrics/MeterRegistry.ts @@ -0,0 +1,29 @@ +/*! + * 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 { Meter } from './Meter'; + +/** + * MeterRegistry provides an interface for creating {@link Meter}s + */ +export interface MeterRegistry { + /** + * Returns a Meter, creating one if one with the given name and version is not already created + * + * @returns Meter A Meter with the given name and version + */ + getMeter(name: string, version?: string): Meter; +}