Skip to content

Commit

Permalink
fix(exporter-metrics-otlp-http): browser OTLPMetricExporter was not p…
Browse files Browse the repository at this point in the history
…assing config to OTLPMetricExporterBase super class

Refs: #5031
  • Loading branch information
trentm committed Jan 10, 2025
1 parent 6864c2f commit 8cd59b3
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class OTLPMetricExporter extends OTLPMetricExporterBase {
JsonMetricsSerializer,
'v1/metrics',
{ 'Content-Type': 'application/json' }
)
),
config
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
* limitations under the License.
*/

import { AggregationTemporalityPreference } from '../../src';
import {
AggregationOption,
AggregationTemporality,
AggregationType,
InstrumentType,
MeterProvider,
PeriodicExportingMetricReader,
} from '@opentelemetry/sdk-metrics';
Expand Down Expand Up @@ -105,4 +110,146 @@ describe('OTLPMetricExporter', function () {
});
});
});

describe('temporality', () => {
it('should use the right temporality when Cumulative preference is selected', () => {
const exporter = new OTLPMetricExporter({
temporalityPreference: AggregationTemporalityPreference.CUMULATIVE,
});

assert.equal(
exporter.selectAggregationTemporality(InstrumentType.COUNTER),
AggregationTemporality.CUMULATIVE,
'Counter'
);
assert.equal(
exporter.selectAggregationTemporality(InstrumentType.HISTOGRAM),
AggregationTemporality.CUMULATIVE,
'Histogram'
);
assert.equal(
exporter.selectAggregationTemporality(InstrumentType.UP_DOWN_COUNTER),
AggregationTemporality.CUMULATIVE,
'UpDownCounter'
);
assert.equal(
exporter.selectAggregationTemporality(
InstrumentType.OBSERVABLE_COUNTER
),
AggregationTemporality.CUMULATIVE,
'Asynchronous Counter'
);
assert.equal(
exporter.selectAggregationTemporality(
InstrumentType.OBSERVABLE_UP_DOWN_COUNTER
),
AggregationTemporality.CUMULATIVE,
'Asynchronous UpDownCounter'
);
});

it('should use the right temporality when Delta preference is selected', () => {
const exporter = new OTLPMetricExporter({
temporalityPreference: AggregationTemporalityPreference.DELTA,
});

assert.equal(
exporter.selectAggregationTemporality(InstrumentType.COUNTER),
AggregationTemporality.DELTA,
'Counter'
);
assert.equal(
exporter.selectAggregationTemporality(InstrumentType.HISTOGRAM),
AggregationTemporality.DELTA,
'Histogram'
);
assert.equal(
exporter.selectAggregationTemporality(InstrumentType.UP_DOWN_COUNTER),
AggregationTemporality.CUMULATIVE,
'UpDownCounter'
);
assert.equal(
exporter.selectAggregationTemporality(
InstrumentType.OBSERVABLE_COUNTER
),
AggregationTemporality.DELTA,
'Asynchronous Counter'
);
assert.equal(
exporter.selectAggregationTemporality(
InstrumentType.OBSERVABLE_UP_DOWN_COUNTER
),
AggregationTemporality.CUMULATIVE,
'Asynchronous UpDownCounter'
);
});

it('should use the right temporality when LowMemory preference is selected', () => {
const exporter = new OTLPMetricExporter({
temporalityPreference: AggregationTemporalityPreference.LOWMEMORY,
});

assert.equal(
exporter.selectAggregationTemporality(InstrumentType.COUNTER),
AggregationTemporality.DELTA,
'Counter'
);
assert.equal(
exporter.selectAggregationTemporality(InstrumentType.HISTOGRAM),
AggregationTemporality.DELTA,
'Histogram'
);
assert.equal(
exporter.selectAggregationTemporality(InstrumentType.UP_DOWN_COUNTER),
AggregationTemporality.CUMULATIVE,
'UpDownCounter'
);
assert.equal(
exporter.selectAggregationTemporality(
InstrumentType.OBSERVABLE_COUNTER
),
AggregationTemporality.CUMULATIVE,
'Asynchronous Counter'
);
assert.equal(
exporter.selectAggregationTemporality(
InstrumentType.OBSERVABLE_UP_DOWN_COUNTER
),
AggregationTemporality.CUMULATIVE,
'Asynchronous UpDownCounter'
);
});
});

describe('aggregation', () => {
it('aggregationSelector calls the selector supplied to the constructor', () => {
const aggregation: AggregationOption = {
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
options: {
boundaries: [0, 100, 100000],
},
};
const exporter = new OTLPMetricExporter({
aggregationPreference: _instrumentType => aggregation,
});
assert.equal(
exporter.selectAggregation(InstrumentType.COUNTER),
aggregation
);
});

it('aggregationSelector returns the default aggregation preference when nothing is supplied', () => {
const exporter = new OTLPMetricExporter({
aggregationPreference: _instrumentType => ({
type: AggregationType.DEFAULT,
}),
});
assert.deepStrictEqual(
exporter.selectAggregation(InstrumentType.COUNTER),
{
type: AggregationType.DEFAULT,
}
);
});
});
});

0 comments on commit 8cd59b3

Please sign in to comment.