@google-cloud/opentelemetry-cloud-monitoring-exporter
OpenTelemetry Google Cloud Monitoring Exporter allows the user to send collected metrics to Google Cloud Monitoring.
Last updated 7 months ago by google-wombot .
Apache-2.0 · Repository · Original npm · Tarball · package.json
$ cnpm install @google-cloud/opentelemetry-cloud-monitoring-exporter 
SYNC missed versions from official npm registry.

OpenTelemetry Google Cloud Monitoring Exporter

NPM Published Version Apache License

OpenTelemetry Google Cloud Monitoring Exporter allows the user to send collected metrics to Google Cloud Monitoring.

To get started with instrumentation in Google Cloud, see Generate traces and metrics with Node.js.

To learn more about instrumentation and observability, including opinionated recommendations for Google Cloud Observability, visit Instrumentation and observability.

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 { resourceFromAttributes } = require("@opentelemetry/resources");
const { MetricExporter } = require("@google-cloud/opentelemetry-cloud-monitoring-exporter");
const { GcpDetectorSync } = require("@google-cloud/opentelemetry-resource-util");

// Create MeterProvider
const meterProvider = new MeterProvider({
  // Create a resource. Fill the `service.*` attributes in with real values for your service.
  // GcpDetectorSync will add in resource information about the current environment if you are
  // running on GCP. These resource attributes will be translated to a specific GCP monitored
  // resource if running on GCP. Otherwise, metrics will be sent with monitored resource
  // `generic_task`.
  resource: resourceFromAttributes({
    "service.name": "example-metric-service",
    "service.namespace": "samples",
    "service.instance.id": "12345",
  }).merge(new GcpDetectorSync().detect()),
});
// Register the exporter
meterProvider.addMetricReader(
  new PeriodicExportingMetricReader({
    // Export metrics every 10 seconds. 5 seconds is the smallest sample period allowed by
    // Cloud Monitoring.
    exportIntervalMillis: 10_000,
    exporter: new MetricExporter(),
  })
);

// Create a meter
const meter = meterProvider.getMeter("metrics-sample");

// Create a counter instrument
const counter = meter.createCounter("metric_name");
// Record a measurement
counter.add(10, { key: "value" });

// Wait for the metric to be exported
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: [
    // To use ExponentialHistogram aggregation for all Histograms:
    new View({
      aggregation: Aggregation.ExponentialHistogram(),
      instrumentType: InstrumentType.HISTOGRAM,
    }),

    // Or if you'd only like to target a specific instrument:
    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

Current Tags

  • 0.21.0                                ...           latest (7 months ago)

22 Versions

  • 0.21.0                                ...           7 months ago
  • 0.20.0                                ...           2 years ago
  • 0.19.0                                ...           2 years ago
  • 0.18.0                                ...           2 years ago
  • 0.17.0                                ...           3 years ago
  • 0.16.0                                ...           3 years ago
  • 0.15.0                                ...           3 years ago
  • 0.14.0                                ...           4 years ago
  • 0.13.0                                ...           5 years ago
  • 0.12.0                                ...           5 years ago
  • 0.11.0                                ...           5 years ago
  • 0.10.0                                ...           5 years ago
  • 0.9.0                                ...           5 years ago
  • 0.8.0                                ...           5 years ago
  • 0.7.0                                ...           5 years ago
  • 0.6.0                                ...           5 years ago
  • 0.5.0                                ...           6 years ago
  • 0.4.3                                ...           6 years ago
  • 0.4.2                                ...           6 years ago
  • 0.4.1                                ...           6 years ago
  • 0.4.0                                ...           6 years ago
  • 0.3.0                                ...           6 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 16
Dev Dependencies (17)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |