GoogleCloudPlatform/opentelemetry-operations-js

Support histogram metrics in @google-cloud/opentelemetry-cloud-monitoring-exporter

Closed this issue · 5 comments

I have tried to use @google-cloud/opentelemetry-cloud-monitoring-exporter and create metrics of type histogram with the following code:

const {MetricExporter} = require("@google-cloud/opentelemetry-cloud-monitoring-exporter");
const {MeterProvider} = require("@opentelemetry/sdk-metrics-base");
const exporter = new MetricExporter()
const meter = new MeterProvider({ exporter, interval: 60000 }).getMeter('climate-heroes-meter')
const metric = req.body.metric

meter.createHistogram(metric.name, {
    description: metric.description
}).record(metric.value, metric.attributes)

This failed with the following message (logged to Google Cloud Platform Logging):

Request was missing field metricDescriptor.metricKind: The descriptor does not have the metric kind set.

While having a look at the source code I found this @TODO comment:

Do you already know when this will be implemented? From what I saw in the Google documentation it looks like the histogram metric chould count as gauge metric (s. https://cloud.google.com/monitoring/api/v3/kinds-and-types#metric-kinds).

Is my understanding correct? If yes, I am more than happy to provide a patch of the code referenced above for review. If not, can someone explain to me how histogram metrics are handled in Google Cloud Monitoring?

Thanks in advance!

Cloud Monitoring API supports histogram points as Distribution (no Gauge needed). We do plan to implement this, but the OpenTelemetry JS SDK is undergoing a lot of changes right now and hasn't been released in ~4 months with the new changes.

Specifically, the exporter interfaces are changing a lot (e.g. open-telemetry/opentelemetry-js#2829, open-telemetry/opentelemetry-js#2809, open-telemetry/opentelemetry-js#2725). I would say it's not worth trying to support histograms in the 4 month old version. Would be better to wait until the all of these changes are released.

Thanks for this update, which is very helpful. I have seen that opentelemetry-js has just been updated a few days ago. Do you know when @google-cloud/opentelemetry-cloud-monitoring-exporter (and @google-cloud/opentelemetry-cloud-trace-exporter) will be updated to support this version 1.1.0?

The upstream metrics changes haven't been released still so nothing to update there. The trace exporter should work fine with the new versions without a new release (it has carat dependencies). Are you having issues with the trace exporter?

Thanks again for the update. I have not yet looked into the opentelemetry update in detail, just read that they had breaking changes. I don't have any issues with tracing and just assumed that the breaking changes might also affect it.
I will wait for the updates you mentioned and will do an update to the latest version of opentelemetry these days. Thanks for your support!

Any news about supporting histograms? Would like to start tracking some latencies in our metrics, but it's a bit tedious with just counters and gauges. 😇