Skip to content

Commit

Permalink
fix: remove default version from Tracer/Meter (#1828)
Browse files Browse the repository at this point in the history
According to spec the version is optional for Tracer and Meter.

TracerProvider/MeterProvider should not add a default to ensure that exporters
only export a version if supplied during creation.
  • Loading branch information
Flarna authored Jan 18, 2021
1 parent 471306f commit 1a3f3f8
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions packages/opentelemetry-core/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ export interface ShimWrapped {
}

/**
* An instrumentation library consists of the name and version used to
* obtain a tracer or meter from a provider. This metadata is made available
* on ReadableSpan and MetricRecord for use by the export pipeline.
* An instrumentation library consists of the name and and optional version
* used to obtain a tracer or meter from a provider. This metadata is made
* available on ReadableSpan and MetricRecord for use by the export pipeline.
*/
export interface InstrumentationLibrary {
readonly name: string;
readonly version: string;
readonly version?: string;
}

/** Defines an error handler function */
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-exporter-collector/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export namespace opentelemetryProto {

export interface InstrumentationLibrary {
name: string;
version: string;
version?: string;
}

export interface StringKeyValue {
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-metrics/src/MeterProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export class MeterProvider implements api.MeterProvider {
*
* @returns Meter A Meter with the given name and version
*/
getMeter(name: string, version = '*', config?: MeterConfig): Meter {
const key = `${name}@${version}`;
getMeter(name: string, version?: string, config?: MeterConfig): Meter {
const key = `${name}@${version || ''}`;
if (!this._meters.has(key)) {
this._meters.set(
key,
Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-metrics/test/Meter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('Meter', () => {
const [record] = await counter.getMetricRecord();
const { name, version } = record.instrumentationLibrary;
assert.strictEqual(name, 'test-meter');
assert.strictEqual(version, '*');
assert.strictEqual(version, undefined);
});

describe('.bind()', () => {
Expand Down Expand Up @@ -607,7 +607,7 @@ describe('Meter', () => {
const [record] = await valueRecorder.getMetricRecord();
const { name, version } = record.instrumentationLibrary;
assert.strictEqual(name, 'test-meter');
assert.strictEqual(version, '*');
assert.strictEqual(version, undefined);
});

describe('names', () => {
Expand Down Expand Up @@ -1297,7 +1297,7 @@ describe('Meter', () => {
const [record] = await observer.getMetricRecord();
const { name, version } = record.instrumentationLibrary;
assert.strictEqual(name, 'test-meter');
assert.strictEqual(version, '*');
assert.strictEqual(version, undefined);
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-metrics/test/MeterProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('MeterProvider', () => {
it('should return the meter with default version without a version option', () => {
const provider = new MeterProvider();
const meter1 = provider.getMeter('default');
const meter2 = provider.getMeter('default', '*');
const meter2 = provider.getMeter('default', undefined);
assert.deepEqual(meter1, meter2);
});

Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-tracing/src/BasicTracerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export class BasicTracerProvider implements api.TracerProvider {
});
}

getTracer(name: string, version = '*', config?: TracerConfig): Tracer {
const key = `${name}@${version}`;
getTracer(name: string, version?: string, config?: TracerConfig): Tracer {
const key = `${name}@${version || ''}`;
if (!this._tracers.has(key)) {
this._tracers.set(
key,
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-tracing/test/Span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ describe('Span', () => {
assert.ok(span.instrumentationLibrary);
const { name, version } = span.instrumentationLibrary;
assert.strictEqual(name, 'default');
assert.strictEqual(version, '*');
assert.strictEqual(version, undefined);
});

it('should return ReadableSpan with attributes', () => {
Expand Down

0 comments on commit 1a3f3f8

Please sign in to comment.