GoogleCloudPlatform/opentelemetry-operations-js

Google Cloud Monitoring Exporter is not working as expected

RaginiDhatric opened this issue · 1 comments

Please answer these questions before submitting a bug report.

What version of OpenTelemetry are you using?

@opentelemetry/sdk-metrics@0.33.0
@opentelemetry/sdk-metrics-base@0.27.0
@opentelemetry/api-metrics@0.33.0
@google-cloud/opentelemetry-cloud-monitoring-exporter@0.14.0

What version of Node are you using?

v18.8.0

What did you do?

If possible, provide a recipe for reproducing the error.

I followed the example here at the readme.

What did you expect to see?

I expect the metrics to be exported to Google Cloud Monitoring.

What did you see instead?

I do not see any errors while running the code, but the metrics are not exported to google monitoring.

Additional context

Add any other context about the problem here.

This is the code that I've written to export the metrics.

const { MeterProvider } = require('@opentelemetry/sdk-metrics');
const { MetricKind, AggregatorKind } = require('@opentelemetry/sdk-metrics-base');
const { ValueType } = require('@opentelemetry/api-metrics');
const { MetricExporter } = require('@google-cloud/opentelemetry-cloud-monitoring-exporter');
  
  const stackExporter = new MetricExporter({ projectId: 'projectId', 
    keyFilename: 'path-to-file',
    keyFile: 'path-to-file',
    credentials: {
      client_email: 'my-email',
      private_key: 'my-key',
    }
   });

  // Register the exporter
  const stackdriverMeterProvider = new MeterProvider({
    stackExporter,
    interval: 60000,
  });
  const meter = stackdriverMeterProvider.getMeter('example-stackdriver');

  const metrics = [
      {
    descriptor: {
       name: "workflowStatus",
       description: "The count of workflow runs",
       unit: "1",
       metricKind: MetricKind.COUNTER,
       valueType: ValueType.INT,
  },
    attributes: {
       "project": "projectId",
  },
     aggregator: AggregatorKind.SUM
  },
  ]
  stackExporter.export(metrics)

  // Now, start recording data
  const counter = meter.createCounter('stack_driver_counter');
  counter.add(1, { test_key : 'test_value' });
}

Thank you.

@opentelemetry/sdk-metrics@0.33.0
@opentelemetry/sdk-metrics-base@0.27.0

These packages are intended to be used together. @opentelemetry/sdk-metrics is the replacement for the deprecated @opentelemetry/sdk-metrics-base package. Unfortunately the Cloud Monitoring exporter is quite out of date so you will have to use it with the old @opentelemetry/sdk-metrics-base@0.27.0 for the time being. That older version does not have views which you added in your example.

I just tried it out and things are working on that older version still as in the example you linked to. I am planning to update to a newer version of the upstream packages but just don't have the time right now. Follow along on #379