OpenTelemetry Google Cloud Monitoring Exporter
OpenTelemetry Google Cloud Monitoring Exporter allows the user to send collected metrics to Google Cloud Monitoring.
Cloud Monitoring provides visibility into the performance, uptime, and overall health of cloud-powered applications. It collects metrics, events, and metadata from Google Cloud, Amazon Web Services, hosted uptime probes, application instrumentation, and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch, and many others. Operations ingests that data and generates insights via dashboards, charts, and alerts. Cloud Monitoring alerting helps you collaborate by integrating with Slack, PagerDuty, and more.
Installation
npm install --save @opentelemetry/sdk-metrics
npm install --save @google-cloud/opentelemetry-cloud-monitoring-exporter
Usage
const { MeterProvider, PeriodicExportingMetricReader } = require("@opentelemetry/sdk-metrics");
const { Resource } = require("@opentelemetry/resources");
const { MetricExporter } = require("@google-cloud/opentelemetry-cloud-monitoring-exporter");
const { GcpDetectorSync } = require("@google-cloud/opentelemetry-resource-util");
const meterProvider = new MeterProvider({
resource: new Resource({
"service.name": "example-metric-service",
"service.namespace": "samples",
"service.instance.id": "12345",
}).merge(new GcpDetectorSync().detect()),
});
meterProvider.addMetricReader(
new PeriodicExportingMetricReader({
exportIntervalMillis: 10_000,
exporter: new MetricExporter(),
})
);
const meter = meterProvider.getMeter("metrics-sample");
const counter = meter.createCounter("metric_name");
counter.add(10, { key: "value" });
new Promise((resolve) => {
setTimeout(resolve, 11_000);
});
Enabling Exponential Histograms
This exporter can send OpenTelemetry Exponential Histograms to Google Cloud Monitoring. To use
this feature, add a metric View to configure Histogram
instruments to use the
ExponentialHistogram
aggregation:
const {
Aggregation,
InstrumentType,
MeterProvider,
View
} = require("@opentelemetry/sdk-metrics");
const meterProvider = new MeterProvider({
views: [
new View({
aggregation: Aggregation.ExponentialHistogram(),
instrumentType: InstrumentType.HISTOGRAM,
}),
new View({
aggregation: Aggregation.ExponentialHistogram(),
instrumentType: InstrumentType.HISTOGRAM,
instrumentName: "http.client.duration",
}),
],
});
For more information on metric Views, see Configure Metric Views.
Viewing your metrics:
With the above you should now be able to navigate to the Google Cloud Monitoring UI at: https://console.cloud.google.com/monitoring
Useful links