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 (#5331)
  • Loading branch information
trentm authored Jan 13, 2025
1 parent 6864c2f commit cb88833
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 1 deletion.
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ All notable changes to experimental packages in this project will be documented

### :bug: (Bug Fix)

* fix(exporter-metrics-otlp-http): browser OTLPMetricExporter was not passing config to OTLPMetricExporterBase super class [#5331](https://github.com/open-telemetry/opentelemetry-js/pull/5331) @trentm

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
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 cb88833

Please sign in to comment.