Skip to content

Commit

Permalink
chore: rename registry to provider (open-telemetry#749)
Browse files Browse the repository at this point in the history
* chore: rename registry to provider

* chore: revert changelog modification

* chore: remove examples and getting started from rename
  • Loading branch information
dyladan committed Feb 18, 2021
1 parent 5d2b028 commit 9469ef7
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 71 deletions.
32 changes: 16 additions & 16 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ API entry points are defined as global singleton objects `trace` and `metrics` w
```javascript
const api = require("@opentelemetry/api")

/* Initialize TraceRegistry */
api.trace.initGlobalTracerRegistry(traceRegistry);
/* returns traceRegistry (no-op if a working registry has not been initialized) */
api.trace.getTracerRegistry();
/* returns a tracer from the registered global tracer registry (no-op if a working registry has not been initialized); */
/* Initialize TraceProvider */
api.trace.initGlobalTracerProvider(traceProvider);
/* returns traceProvider (no-op if a working provider has not been initialized) */
api.trace.getTracerProvider();
/* returns a tracer from the registered global tracer provider (no-op if a working provider has not been initialized); */
api.trace.getTracer(name, version);

/* Initialize MeterRegistry */
api.metrics.initGlobalMeterRegistry(meterRegistry);
/* returns meterRegistry (no-op if a working registry has not been initialized) */
api.metrics.getMeterRegistry();
/* returns a meter from the registered global meter registry (no-op if a working registry has not been initialized); */
/* Initialize MeterProvider */
api.metrics.initGlobalMeterProvider(meterProvider);
/* returns meterProvider (no-op if a working provider has not been initialized) */
api.metrics.getMeterProvider();
/* returns a meter from the registered global meter provider (no-op if a working provider has not been initialized); */
api.metrics.getMeter(name, version);
```

Expand All @@ -40,7 +40,7 @@ Application owners will also need a working OpenTelemetry SDK implementation. Op

#### Simple NodeJS Example

Before any other module in your application is loaded, you must initialize the global tracer and meter registries. If you fail to initialize a registry, no-op implementations will be provided to any library which acquires them from the API.
Before any other module in your application is loaded, you must initialize the global tracer and meter registries. If you fail to initialize a provider, no-op implementations will be provided to any library which acquires them from the API.

```javascript
const api = require("@opentelemetry/api");
Expand All @@ -54,14 +54,14 @@ const exporter = new JaegerExporter({
serviceName: 'basic-service'
});

// Create a registry which we will configure as the global tracer registry
const registry = new sdk.NodeTracerRegistry();
// Create a provider which we will configure as the global tracer provider
const provider = new sdk.NodeTracerProvider();

// Configure span processor to send spans to the exporter
registry.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the NodeTracerRegistry bindings
api.trace.initGlobalTracerRegistry(registry);
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
api.trace.initGlobalTracerProvider(provider);

// your application code below this line
```
Expand Down
24 changes: 12 additions & 12 deletions api/src/api/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/

import { Meter } from '../metrics/Meter';
import { MeterRegistry } from '../metrics/MeterRegistry';
import { NOOP_METER_REGISTRY } from '../metrics/NoopMeterRegistry';
import { MeterProvider } from '../metrics/MeterProvider';
import { NOOP_METER_PROVIDER } from '../metrics/NoopMeterProvider';

/**
* Singleton object which represents the entry point to the OpenTelemetry Metrics API
*/
export class MetricsAPI {
private static _instance?: MetricsAPI;
private _meterRegistry: MeterRegistry = NOOP_METER_REGISTRY;
private _meterProvider: MeterProvider = NOOP_METER_PROVIDER;

/** Empty private constructor prevents end users from constructing a new instance of the API */
private constructor() {}
Expand All @@ -38,24 +38,24 @@ export class MetricsAPI {
}

/**
* Set the current global meter. Returns the initialized global meter registry.
* Set the current global meter. Returns the initialized global meter provider.
*/
public initGlobalMeterRegistry(registry: MeterRegistry): MeterRegistry {
this._meterRegistry = registry;
return registry;
public initGlobalMeterProvider(provider: MeterProvider): MeterProvider {
this._meterProvider = provider;
return provider;
}

/**
* Returns the global meter registry.
* Returns the global meter provider.
*/
public getMeterRegistry(): MeterRegistry {
return this._meterRegistry;
public getMeterProvider(): MeterProvider {
return this._meterProvider;
}

/**
* Returns a meter from the global meter registry.
* Returns a meter from the global meter provider.
*/
public getMeter(name: string, version?: string): Meter {
return this.getMeterRegistry().getMeter(name, version);
return this.getMeterProvider().getMeter(name, version);
}
}
24 changes: 12 additions & 12 deletions api/src/api/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* limitations under the License.
*/

import { NOOP_TRACER_REGISTRY } from '../trace/NoopTracerRegistry';
import { TracerRegistry } from '../trace/tracer_registry';
import { NOOP_TRACER_PROVIDER } from '../trace/NoopTracerProvider';
import { TracerProvider } from '../trace/tracer_provider';
import { Tracer } from '../trace/tracer';

/**
* Singleton object which represents the entry point to the OpenTelemetry Tracing API
*/
export class TraceAPI {
private static _instance?: TraceAPI;
private _tracerRegistry: TracerRegistry = NOOP_TRACER_REGISTRY;
private _tracerProvider: TracerProvider = NOOP_TRACER_PROVIDER;

/** Empty private constructor prevents end users from constructing a new instance of the API */
private constructor() {}
Expand All @@ -38,24 +38,24 @@ export class TraceAPI {
}

/**
* Set the current global tracer. Returns the initialized global tracer registry
* Set the current global tracer. Returns the initialized global tracer provider
*/
public initGlobalTracerRegistry(registry: TracerRegistry): TracerRegistry {
this._tracerRegistry = registry;
return registry;
public initGlobalTracerProvider(provider: TracerProvider): TracerProvider {
this._tracerProvider = provider;
return provider;
}

/**
* Returns the global tracer registry.
* Returns the global tracer provider.
*/
public getTracerRegistry(): TracerRegistry {
return this._tracerRegistry;
public getTracerProvider(): TracerProvider {
return this._tracerProvider;
}

/**
* Returns a tracer from the global tracer registry.
* Returns a tracer from the global tracer provider.
*/
public getTracer(name: string, version?: string): Tracer {
return this.getTracerRegistry().getTracer(name, version);
return this.getTracerProvider().getTracer(name, version);
}
}
8 changes: 4 additions & 4 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +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/MeterProvider';
export * from './metrics/Metric';
export * from './trace/attributes';
export * from './trace/Event';
Expand All @@ -36,13 +36,13 @@ 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/tracer_provider';
export * from './trace/trace_flags';
export * from './trace/trace_state';
export * from './trace/NoopSpan';
export * from './trace/NoopTracer';
export * from './trace/NoopTracerRegistry';
export * from './metrics/NoopMeterRegistry';
export * from './trace/NoopTracerProvider';
export * from './metrics/NoopMeterProvider';
export * from './metrics/NoopMeter';

import { TraceAPI } from './api/trace';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import { Meter } from './Meter';

/**
* MeterRegistry provides an interface for creating {@link Meter}s
* MeterProvider provides an interface for creating {@link Meter}s
*/
export interface MeterRegistry {
export interface MeterProvider {
/**
* Returns a Meter, creating one if one with the given name and version is not already created
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
*/

import { Meter } from './Meter';
import { MeterRegistry } from './MeterRegistry';
import { MeterProvider } from './MeterProvider';
import { NOOP_METER } from './NoopMeter';

/**
* An implementation of the {@link MeterRegistry} which returns an impotent Meter
* An implementation of the {@link MeterProvider} which returns an impotent Meter
* for all calls to `getMeter`
*/
export class NoopMeterRegistry implements MeterRegistry {
export class NoopMeterProvider implements MeterProvider {
getMeter(_name?: string, _version?: string): Meter {
return NOOP_METER;
}
}

export const NOOP_METER_REGISTRY = new NoopMeterRegistry();
export const NOOP_METER_PROVIDER = new NoopMeterProvider();
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

import { NOOP_TRACER } from './NoopTracer';
import { Tracer } from './tracer';
import { TracerRegistry } from './tracer_registry';
import { TracerProvider } from './tracer_provider';

/**
* An implementation of the {@link TracerRegistry} which returns an impotent Tracer
* An implementation of the {@link TracerProvider} which returns an impotent Tracer
* for all calls to `getTracer`
*/
export class NoopTracerRegistry implements TracerRegistry {
export class NoopTracerProvider implements TracerProvider {
getTracer(_name?: string, _version?: string): Tracer {
return NOOP_TRACER;
}
}

export const NOOP_TRACER_REGISTRY = new NoopTracerRegistry();
export const NOOP_TRACER_PROVIDER = new NoopTracerProvider();
6 changes: 3 additions & 3 deletions api/src/trace/instrumentation/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { Logger } from '../../common/Logger';
import { TracerRegistry } from '../tracer_registry';
import { TracerProvider } from '../tracer_provider';

/** Interface Plugin to apply patch. */
// tslint:disable-next-line:no-any
Expand All @@ -32,13 +32,13 @@ export interface Plugin<T = any> {
* 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 TracerRegistry a tracer registry.
* @param TracerProvider a tracer provider.
* @param logger a logger instance.
* @param [config] an object to configure the plugin.
*/
enable(
moduleExports: T,
TracerRegistry: TracerRegistry,
TracerProvider: TracerProvider,
logger: Logger,
config?: PluginConfig
): T;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import { Tracer } from './tracer';

/**
* TracerRegistry provides an interface for creating {@link Tracer}s
* TracerProvider provides an interface for creating {@link Tracer}s
*/
export interface TracerRegistry {
export interface TracerProvider {
/**
* Returns a Tracer, creating one if one with the given name and version is not already created
*
Expand Down
20 changes: 10 additions & 10 deletions api/test/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import * as assert from 'assert';
import api, { TraceFlags, NoopSpan, NoopTracerRegistry, NoopTracer, SpanOptions, Span } from '../../src';
import api, { TraceFlags, NoopSpan, NoopTracerProvider, NoopTracer, SpanOptions, Span } from '../../src';

describe('API', () => {
const functions = [
Expand All @@ -26,13 +26,13 @@ describe('API', () => {
'getHttpTextFormat',
];

it('should expose a tracer registry via getTracerRegistry', () => {
const tracer = api.trace.getTracerRegistry();
it('should expose a tracer provider via getTracerProvider', () => {
const tracer = api.trace.getTracerProvider();
assert.ok(tracer);
assert.strictEqual(typeof tracer, 'object');
});

describe('GlobalTracerRegistry', () => {
describe('GlobalTracerProvider', () => {
const spanContext = {
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
spanId: '6e0c63257de34c92',
Expand All @@ -41,12 +41,12 @@ describe('API', () => {
const dummySpan = new NoopSpan(spanContext);

afterEach(() => {
api.trace.initGlobalTracerRegistry(new NoopTracerRegistry());
api.trace.initGlobalTracerProvider(new NoopTracerProvider());
});

it('should not crash', () => {
functions.forEach(fn => {
const tracer = api.trace.getTracerRegistry();
const tracer = api.trace.getTracerProvider();
try {
((tracer as unknown) as { [fn: string]: Function })[fn](); // Try to run the function
assert.ok(true, fn);
Expand All @@ -58,9 +58,9 @@ describe('API', () => {
});
});

it('should use the global tracer registry', () => {
api.trace.initGlobalTracerRegistry(new TestTracerRegistry());
const tracer = api.trace.getTracerRegistry().getTracer('name');
it('should use the global tracer provider', () => {
api.trace.initGlobalTracerProvider(new TestTracerProvider());
const tracer = api.trace.getTracerProvider().getTracer('name');
const span = tracer.startSpan('test');
assert.deepStrictEqual(span, dummySpan);
});
Expand All @@ -74,7 +74,7 @@ describe('API', () => {
}
}

class TestTracerRegistry extends NoopTracerRegistry {
class TestTracerProvider extends NoopTracerProvider {
getTracer(_name: string, version?: string) {
return new TestTracer();
}
Expand Down
4 changes: 2 additions & 2 deletions api/test/noop-implementations/noop-meter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as assert from 'assert';
import {
Labels,
NoopMeterRegistry,
NoopMeterProvider,
NOOP_BOUND_COUNTER,
NOOP_BOUND_GAUGE,
NOOP_BOUND_MEASURE,
Expand All @@ -29,7 +29,7 @@ import {

describe('NoopMeter', () => {
it('should not crash', () => {
const meter = new NoopMeterRegistry().getMeter('test-noop');
const meter = new NoopMeterProvider().getMeter('test-noop');
const counter = meter.createCounter('some-name');
const labels = {} as Labels;
const labelSet = meter.labels(labels);
Expand Down

0 comments on commit 9469ef7

Please sign in to comment.