Skip to content

Metrics not exported when multiple exporters are present #1900

@chippment

Description

@chippment

What version of OpenTelemetry are you using?

    "@opentelemetry/api": "1.7.0",
    "@opentelemetry/auto-instrumentations-node": "0.40.2",
    "@opentelemetry/exporter-metrics-otlp-grpc": "0.46.0",
    "@opentelemetry/exporter-metrics-otlp-proto": "0.46.0",
    "@opentelemetry/exporter-prometheus": "0.47.0",
    "@opentelemetry/host-metrics": "0.34.1",
    "@opentelemetry/sdk-node": "0.46.0",

What version of Node are you using?

v21.5.0

What did you do?

My use case is that the instrumentation shall use two separate exporters to export to two different endpoints. However, the data only gets exported via the first configured exporter. The second exporter receives an empty list of scope metrics in the export function.

Here is a sample application that reproduces the issue:

monitoring.js:

const { HostMetrics } = require('@opentelemetry/host-metrics');
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const { NodeSDK } = require("@opentelemetry/sdk-node")
const { PeriodicExportingMetricReader, ConsoleMetricExporter } = require("@opentelemetry/sdk-metrics");
const { metrics } = require('@opentelemetry/api');

const exporter = new PrometheusExporter(
  {
    startServer: true
  }, () => {
    console.log('prometheus scrape endpoint: http://localhost:9464/metrics')
  }
);

const sdk = new NodeSDK({
    metricReader: exporter
});

sdk.start();

const hostMetrics = new HostMetrics({ name: 'example-host-metrics' });
hostMetrics.start();

const periodicReader = new PeriodicExportingMetricReader({
    exportIntervalMillis: 5000,
    exporter: new ConsoleMetricExporter() // this will never print any of the host metrics
});

metrics.getMeterProvider().addMetricReader(periodicReader) // expecting this to be the one global meter provider

app.js:

const express = require('express')
const app = express()

app.get('/', function (req, res) {
  res.send('Hello World')
})

app.listen(3000)

start via: node -r ./monitoring.js app.js

What did you expect to see?

Metrics being exported to two different endpoints via two different exporters.

What did you see instead?

Only the first exporter receiving a list of scope metrics while the second one receives an empty list. Thus, nothing gets exported via the second exporter.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions