0

I have many java applications and they have been instrumented with Micrometer(SpringBoot natively support it). They send metric to OTLP Mimir.

I have a NodeJS application which I want to instrument with OTEL and want same naming semantic convention on both.

I did some research and figured out it is impossible to do on Micrometer here. Therefore, I want to configure NodeJS application to emit metric with custom names.

One such metric is:

  • OTEL emits http.server.request.duration.count
  • Micrometer emits http.server.requests.count

Tags are also different.

Here is my code so far:

import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { AlwaysOnSampler, BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { Resource } from "@opentelemetry/resources";
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-grpc";
import { BatchLogRecordProcessor, LoggerProvider } from "@opentelemetry/sdk-logs";
import logsAPI from "@opentelemetry/api-logs";
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-grpc";
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-grpc";
import { MeterProvider, PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";

export const setupOpenTelemetry = (serviceName: string) => {
  const tracerProvider = new NodeTracerProvider({
    resource: new Resource({
      [ATTR_SERVICE_NAME]: serviceName
    }),
    sampler: new AlwaysOnSampler()
  });

  // const exporter = new ConsoleSpanExporter();
  const otlpExporter = new OTLPTraceExporter();
  //provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
  tracerProvider.addSpanProcessor(new BatchSpanProcessor(otlpExporter));
  // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
  tracerProvider.register();

  const metricExporter = new OTLPMetricExporter();
  const meterProvider = new MeterProvider({});

  meterProvider.addMetricReader(
    new PeriodicExportingMetricReader({
      exporter: metricExporter,
      exportIntervalMillis: 1000
    })
  );
  // To start a logger, you first need to initialize the Logger provider.
  const loggerProvider = new LoggerProvider();
  // Add a processor to export log record
  // loggerProvider.addLogRecordProcessor(new SimpleLogRecordProcessor(new ConsoleLogRecordExporter()));
  loggerProvider.addLogRecordProcessor(new BatchLogRecordProcessor(new OTLPLogExporter()));
  logsAPI.logs.setGlobalLoggerProvider(loggerProvider);

  registerInstrumentations({
    tracerProvider,
    meterProvider,
    instrumentations: [
      // Express instrumentation expects HTTP layer to be instrumented
      new HttpInstrumentation(),
      new ExpressInstrumentation()
    ]
  });
};

1
  • "I did some research and figured out it is impossible to do on Micrometer here." That is an interesting conclusion of your research since the issue tells you the name of the component that makes this possible. :) You can use an ObservationConvention an ObservationFilter (limited) or a MeterFilter to rename metrics in Micrometer. Commented Jan 8 at 6:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.