GoogleCloudPlatform/opentelemetry-operations-js

Cloud Monitoring Exporter's README is outdated.

Closed this issue · 1 comments

What version of OpenTelemetry are you using?

"@google-cloud/opentelemetry-cloud-monitoring-exporter": "^0.15.0",
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/sdk-metrics": "^1.8.0",

What version of Node are you using?

v16.18.0

What did you do?

The @google-cloud/opentelemetry-cloud-monitoring-exporter's README seems to be outdated, and it does not reflect the changes introduced by the latest version of the package (v0.15.0).

The example shown in the README will not work as this package exposes the MetricExporter class, which implements @opentelemetry/sdk-metrics's PushMetricExporter class and the MeterProvider class expects a MetricReader instead.

It appears that for the PushMetricExporter class to be able to export metrics, this MUST be registered to the Metrics SDK with a MetricReader (see here for reference).

What did you expect to see?

In my understanding, this package exposes an interface to use the Push Model Exporting .

Therefore, a possible way to register the exporter in the latest version of @opentelemetry/sdk-metrics (at the moment of writing v1.8.0) is to do something like this:

import { MetricExporter } from '@google-cloud/opentelemetry-cloud-monitoring-exporter';
import { MeterProvider } from '@opentelemetry/sdk-metrics';

const exporter = new MetricExporter({ projectId: GOOGLE_PROJECT_ID });

const meterProvider = new MeterProvider();

const periodicExportingMetricReader = new PeriodicExportingMetricReader({
  exporter,
});

meterProvider.addMetricReader(periodicExportingMetricReader);

// Now, start recording data
const meter = meterProvider.getMeter('example-meter');
const counter = meter.createCounter('metric_name');
counter.add(10, { key: 'value' });

What did you see instead?

N/A

Additional context

I think a clear example will go a long way with people wanting to use OpenTelemetry and this exporter. So I would also like to make the following suggestions even if they are out of scope:

  • A working example similar to this one.
  • Information and a collection of resources about IAM permissions and credentials needed for this exporter to work in a GCP project.

Thanks for creating an issue. We already have #158 for creating a sample.

As for the README, your code looks right to me. Would you be willing to send a PR to update the "usage" section of the README with your code? The only thing I'd change is to use require() instead of esm for the barebones example.