Skip to content

Commit

Permalink
docs: use specific view for histogram buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieDanielson committed Jun 2, 2023
1 parent fefedbd commit 8ba4dfe
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions examples/otlp-exporter-node/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-htt
// const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-proto');
// const { ConsoleMetricExporter } = require('@opentelemetry/sdk-metrics');
const {
ExplicitBucketHistogramAggregation,
ExponentialHistogramAggregation,
MeterProvider,
PeriodicExportingMetricReader,
Expand All @@ -25,20 +26,25 @@ const metricExporter = new OTLPMetricExporter({
// },
});

// Define view for the bucket sizes for the histogram metric
const histogramView = new View({
aggregation: new ExplicitBucketHistogramAggregation([0, 10, 100, 1000]),
instrumentName: 'test_histogram',
});
// Define view for the exponential histogram metric
const expHistogramView = new View({
aggregation: new ExponentialHistogramAggregation(),
instrumentName: 'test_exponential_histogram',
});
// Note, the instrumentName is the same as the name that has been passed for
// the Meter#createHistogram function for exponentialHistogram.
// the Meter#createHistogram functions.

// Create an instance of the metric provider
const meterProvider = new MeterProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'basic-metric-service',
}),
views: [expHistogramView],
views: [histogramView, expHistogramView],
});

meterProvider.addMetricReader(
Expand All @@ -61,7 +67,6 @@ const upDownCounter = meter.createUpDownCounter('test_up_down_counter', {

const histogram = meter.createHistogram('test_histogram', {
description: 'Example of a Histogram',
boundaries: [0, 10, 100, 1000],
});

const exponentialHistogram = meter.createHistogram('test_exp_histogram', {
Expand Down

0 comments on commit 8ba4dfe

Please sign in to comment.