Skip to content

Commit

Permalink
fixup! add a new positional parameter options
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Oct 29, 2021
1 parent acb658e commit 2f442c8
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { NOOP_METER } from './NoopMeter';
* for all calls to `getMeter`
*/
export class NoopMeterProvider implements MeterProvider {
getMeter(_name?: string, _options?: MeterOptions): Meter {
getMeter(_name: string, _version?: string, _options?: MeterOptions): Meter {
return NOOP_METER;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export class MetricsAPI {
/**
* Returns a meter from the global meter provider.
*/
public getMeter(name: string, options?: MeterOptions): Meter {
return this.getMeterProvider().getMeter(name, options);
public getMeter(name: string, version?: string, options?: MeterOptions): Meter {
return this.getMeterProvider().getMeter(name, version, options);
}

/** Remove the global meter provider */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ import { ObservableResult } from './ObservableResult';
* An interface describes additional metadata of a meter.
*/
export interface MeterOptions {
/**
* The version of the meter or instrumentation library
*/
version?: string;
/**
* The schemaUrl of the meter or instrumentation library
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ export interface MeterProvider {
* schemaUrl pair is not already created.
*
* @param name The name of the meter or instrumentation library.
* @param version The version of the meter or instrumentation library.
* @param options The options of the meter or instrumentation library.
* @returns Meter A Meter with the given name and version
*/
getMeter(name: string, options?: MeterOptions): Meter;
getMeter(name: string, version?: string, options?: MeterOptions): Meter;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const meterProvider = new metrics.MeterProvider({
}),
});

const meter = meterProvider.getMeter('default', { version: '0.0.1' });
const meter = meterProvider.getMeter('default', '0.0.1');

const traceIdArr = [
31,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const meterProvider = new metrics.MeterProvider({
}),
});

const meter = meterProvider.getMeter('default', { version: '0.0.1' });
const meter = meterProvider.getMeter('default', '0.0.1');

if (typeof Buffer === 'undefined') {
(window as any).Buffer = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const meterProvider = new metrics.MeterProvider({
}),
});

const meter = meterProvider.getMeter('default', { version: '0.0.1' });
const meter = meterProvider.getMeter('default', '0.0.1');

export function mockCounter(): metrics.Metric<metrics.BoundCounter> & Counter {
const name = 'int-counter';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ describe('PrometheusExporter', () => {
meterProvider = new MeterProvider({
interval: Math.pow(2, 31) - 1,
});
meter = meterProvider.getMeter('test-prometheus', {
version: '1',
meter = meterProvider.getMeter('test-prometheus', '1', {
exporter,
});
done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ export abstract class InstrumentationAbstract<T = any>

this._tracer = trace.getTracer(instrumentationName, instrumentationVersion);

this._meter = metrics.getMeter(instrumentationName, {
version: instrumentationVersion,
});
this._meter = metrics.getMeter(instrumentationName, instrumentationVersion);
}

/* Api to wrap instrumented method */
Expand All @@ -79,9 +77,7 @@ export abstract class InstrumentationAbstract<T = any>
public setMeterProvider(meterProvider: MeterProvider) {
this._meter = meterProvider.getMeter(
this.instrumentationName,
{
version: this.instrumentationVersion,
}
this.instrumentationVersion
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export class MeterProvider implements api.MeterProvider {
*
* @returns Meter A Meter with the given name and version
*/
getMeter(name: string, config?: MeterConfig): Meter {
const key = `${name}@${config?.version ?? ''}:${config?.schemaUrl ?? ''}`;
getMeter(name: string, version?: string, config?: MeterConfig): Meter {
const key = `${name}@${version ?? ''}:${config?.schemaUrl ?? ''}`;
if (!this._meters.has(key)) {
this._meters.set(
key,
new Meter({
name,
version: config?.version,
// @ts-expect-error ts(2345) TODO: upgrade @opentelemetry/core
version,
// @ts-expect-error ts(2345) TODO: upgrade @opentelemetry/core InstrumentationLibrary definition
schemaUrl: config?.schemaUrl
}, Object.assign({}, this._config, config))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1366,8 +1366,7 @@ describe('Meter', () => {
});

it('should allow custom processor', () => {
const customMeter = new MeterProvider().getMeter('custom-processor', {
version: '*',
const customMeter = new MeterProvider().getMeter('custom-processor', '*', {
processor: new CustomProcessor(),
});
assert.throws(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ describe('MeterProvider', () => {

it('should return the same Meter instance with same name & version', () => {
const provider = new MeterProvider();
const meter1 = provider.getMeter('meter1', { version: 'ver1' });
const meter2 = provider.getMeter('meter1', { version: 'ver1' });
const meter1 = provider.getMeter('meter1', 'ver1');
const meter2 = provider.getMeter('meter1', 'ver1');
assert.deepEqual(meter1, meter2);
});

it('should return different Meter instance with different name or version', () => {
const provider = new MeterProvider();

const meter1 = provider.getMeter('meter1', { version: 'ver1' });
const meter1 = provider.getMeter('meter1', 'ver1');
const meter2 = provider.getMeter('meter1');
assert.notEqual(meter1, meter2);

const meter3 = provider.getMeter('meter2', { version: 'ver2' });
const meter4 = provider.getMeter('meter3', { version: 'ver2' });
const meter3 = provider.getMeter('meter2', 'ver2');
const meter4 = provider.getMeter('meter3', 'ver2');
assert.notEqual(meter3, meter4);
});
});
Expand Down

0 comments on commit 2f442c8

Please sign in to comment.