Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't receive or visualize metrics in Grafana/Prometheus #163

Open
LuiFerPereira opened this issue Dec 1, 2024 · 1 comment
Open

Don't receive or visualize metrics in Grafana/Prometheus #163

LuiFerPereira opened this issue Dec 1, 2024 · 1 comment

Comments

@LuiFerPereira
Copy link

Hi,
I'm trying a scenario to push metrics from opentelemetry but it's not working. Can you help me? please.

My configurations are:

  1. Start image downloaded from Docker Hub

Image

  1. After, I'm configured the OTLP Exported from opentelemetry:

Note: The GRAFANA_AGENT_URL is: 'http://localhost:4318'

import {getNodeAutoInstrumentations} from '@opentelemetry/auto-instrumentations-node';
import {BatchSpanProcessor} from '@opentelemetry/sdk-trace-base';
import {NodeSDK} from '@opentelemetry/sdk-node';
import {OTLPTraceExporter} from '@opentelemetry/exporter-trace-otlp-grpc';
import {OTLPMetricExporter} from '@opentelemetry/exporter-metrics-otlp-http';
import {Resource} from '@opentelemetry/resources';
import {ATTR_SERVICE_NAME} from '@opentelemetry/semantic-conventions';
import {
  //ConsoleMetricExporter,
  PeriodicExportingMetricReader,
} from '@opentelemetry/sdk-metrics';
import {diag, DiagConsoleLogger, DiagLogLevel} from '@opentelemetry/api';

diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);

const traceExporter = new OTLPTraceExporter({
  url: process.env.GRAFANA_AGENT_URL,
});

const metricOTLPReader = new PeriodicExportingMetricReader({
  exporter: new OTLPMetricExporter({
    url: process.env.GRAFANA_AGENT_URL,
  }),
  exportIntervalMillis: 10000, // Set to 10 seconds for demonstrative purposes only, don't use this in production
});

/*const metricConsolePReader = new PeriodicExportingMetricReader({
  exporter: new ConsoleMetricExporter(),
  exportIntervalMillis: 1000,
});*/

const sdk = new NodeSDK({
  traceExporter,
  metricReader: metricOTLPReader,
  resource: new Resource({
    [ATTR_SERVICE_NAME]: process.env.SERVICE_NAME,
  }),
  spanProcessors: [new BatchSpanProcessor(traceExporter)],
  instrumentations: [
    getNodeAutoInstrumentations({
      '@opentelemetry/instrumentation-fs': {enabled: false},
      '@opentelemetry/instrumentation-grpc': {enabled: true},
      '@opentelemetry/instrumentation-pg': {enabled: false},
      '@opentelemetry/instrumentation-express': {enabled: false},
      '@opentelemetry/instrumentation-dns': {enabled: false},
      '@opentelemetry/instrumentation-net': {enabled: false},
      '@opentelemetry/instrumentation-nestjs-core': {enabled: false},
      '@opentelemetry/instrumentation-aws-lambda': {enabled: false},
      '@opentelemetry/instrumentation-http': {
        enabled: false,
        ignoreIncomingRequestHook: (req): boolean => {
          return req.url === '/health';
        },
      },
    }),
  ],
});

process.on('SIGTERM', () => {
  void sdk.shutdown();
});

export default sdk;

  1. When starting the micro-services, I'm initialize the sdk:
async function bootstrap() {
  sdk.start();
  ....
  1. From a controller, I'm creating a counter and increasing value each request:
const filterRequestsCounter = getMeter().createCounter(
  `filter_requests_total`,
  {
    description: 'Total number of filter requests',
    unit: 'req',
  }
);
....
filterRequestsCounter.add(1);

In Grafana or Prometheus never I visualized the metric: filter_requests_total
*Grafana
Image

  • Prometheus:
    Image

It's not working. What am I doing wrong?

@zeitlinger
Copy link
Member

Please check the following:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants