Skip to content

Commit

Permalink
[backport/v1.x] fix(exporter-metrics-otlp-http): browser OTLPMetricEx…
Browse files Browse the repository at this point in the history
…porter was not passing config to OTLPMetricExporterBase super class [#5331] (#5337)

Co-authored-by: Trent Mick <trentm@gmail.com>
  • Loading branch information
pichlermarc and trentm authored Jan 13, 2025
1 parent 18b33a0 commit 1fa5492
Show file tree
Hide file tree
Showing 3 changed files with 144 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 @@ -11,6 +11,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 {
Aggregation,
AggregationTemporality,
ExplicitBucketHistogramAggregation,
InstrumentType,
MeterProvider,
PeriodicExportingMetricReader,
} from '@opentelemetry/sdk-metrics';
Expand Down Expand Up @@ -105,4 +110,139 @@ 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: Aggregation = new ExplicitBucketHistogramAggregation([
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 => Aggregation.Default(),
});
assert.deepStrictEqual(
exporter.selectAggregation(InstrumentType.COUNTER),
Aggregation.Default()
);
});
});
});

0 comments on commit 1fa5492

Please sign in to comment.