Skip to content

Commit

Permalink
Remove coersion of blank string to '1'
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored May 27, 2022
1 parent 42a753a commit b8c50e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function createInstrumentDescriptor(name: string, type: InstrumentType, o
name,
type,
description: options?.description ?? '',
unit: options?.unit === '' ? '1' : options?.unit ?? '',
unit: options?.unit ?? '',
valueType: options?.valueType ?? ValueType.DOUBLE,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,15 @@ import * as assert from 'assert';
import {createInstrumentDescriptor, InstrumentType} from '../src/InstrumentDescriptor';

describe('InstrumentDescriptor', () => {

describe('createInstrumentDescriptor', () => {

// Spec compliance: https://github.com/open-telemetry/opentelemetry-js/issues/2910
it('should interpret a null unit value as a blank string', () => {
const result = createInstrumentDescriptor('example', InstrumentType.COUNTER, {
unit: null as any,
});

assert.strictEqual(result.unit, '');
});

// Spec compliance: https://github.com/open-telemetry/opentelemetry-js/issues/2910
it('should interpret an undefined unit value as a blank string', () => {
const result = createInstrumentDescriptor('example', InstrumentType.COUNTER, {
unit: undefined,
});

assert.strictEqual(result.unit, '');
});

// Spec compliance: https://github.com/open-telemetry/opentelemetry-js/issues/2910
it('should interpret a null unit value as a blank string', () => {
const result = createInstrumentDescriptor('example', InstrumentType.COUNTER, {
unit: '',
});

assert.strictEqual(result.unit, '1');
});

for (const val of [null, undefined]) {
it(`should interpret an empty unit value as a blank string (${val})`, () => {
const result = createInstrumentDescriptor('example', InstrumentType.COUNTER, {
unit: val as any,
});

assert.strictEqual(result.unit, '');
})
}
});

});

0 comments on commit b8c50e8

Please sign in to comment.