Hello everyone, I am running a standalone docker i...
# support
m
Hello everyone, I am running a standalone docker instance of signoz, and while I instrument our nest js microservices some services accept but some other throw a weird error:
Copy code
Debugger listening on <ws://127.0.0.1:9229/cf0c2f79-99cc-4a30-8906-60114c064ccf>
For help, see: <https://nodejs.org/en/docs/inspector>

/ironji-dinero/node_modules/@opentelemetry/instrumentation/src/autoLoader.ts:39
  const meterProvider = options.meterProvider || metrics.getMeterProvider();
                                                         ^
TypeError: Cannot read properties of undefined (reading 'getMeterProvider')
    at registerInstrumentations (/ironji-dinero/node_modules/@opentelemetry/instrumentation/src/autoLoader.ts:39:58)
    at NodeSDK.start (/ironji-dinero/node_modules/@opentelemetry/sdk-node/src/sdk.ts:214:29)
    at Object.<anonymous> (/ironji-dinero/src/tracer.ts:26:5)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/ironji-dinero/src/main.ts:12:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47
We have
node v16.16.0
could anyone help here? What might be the issue and we can resolve it? This is what we have as a
tracer.ts
file:
Copy code
'use strict';

import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { Resource } from '@opentelemetry/resources';
import * as opentelemetry from '@opentelemetry/sdk-node';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

// Configure the SDK to export telemetry data to the console
// Enable all auto-instrumentations from the meta package
const exporterOptions = {
  url: '<http://signoz-otel-collector:4318/v1/traces>',
};

const traceExporter = new OTLPTraceExporter(exporterOptions);
const sdk = new opentelemetry.NodeSDK({
  traceExporter,
  instrumentations: [getNodeAutoInstrumentations()],
  resource: new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]: 'dinero',
  }),
});

// initialize the SDK and register with the OpenTelemetry API
// this enables the API to record telemetry
sdk.start();

// gracefully shut down the SDK on process exit
process.on('SIGTERM', () => {
  sdk
    .shutdown()
    .then(() => console.log('Tracing terminated'))
    .catch((error) => console.log('Error terminating tracing', error))
    .finally(() => process.exit(0));
});

export default sdk;
v
Copy code
const metricReader = new PeriodicExportingMetricReader({
	exporter: new OTLPMetricExporter({
		url: '<http://127.0.0.1:4318/v1/metrics>',
	}),
	// Default is 60000ms (60 seconds). Set to 10 seconds for demonstrative purposes only.
	exportIntervalMillis: 10000,
});

const myServiceMeterProvider = new MeterProvider({
	resource,
	readers: [metricReader],
});

// Set this MeterProvider to be global to the app being instrumented.
opentelemetry.metrics.setGlobalMeterProvider(myServiceMeterProvider);
can you add the same in your
tracer.ts
. the current setup that you shared initialises the tracer provider but you need a global meter provider
m
Hi @Vikrant Gupta, thank you for responding, but from where these modules are imported?
PeriodicExportingMetricReader
,
OTLPMetricExporter
,
MeterProvider
v
Copy code
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
import {
	MeterProvider,
	PeriodicExportingMetricReader,
} from '@opentelemetry/sdk-metrics';
m
This looks as a new way for setting it up, would you point me to the docs for this? I was referring to this docs, but they seem to not look like this one you provided
v
The doc provides info only around traces data, the above additions helps you extract metrics data as well.
let me check and get it updated if required, in the meantime were you able to achieve the metrics data ?
m
not yet, I failed to understand how I should add the new settings you shared in
tracer.ts
file
v
https://signoz-community.slack.com/archives/C01HWQ1R0BC/p1716883000454569?thread_ts=1716809375.430109&amp;cid=C01HWQ1R0BC use the instructions and add it after your tracing setup and the required imports. then use the same logic
metrics.getMeter
and export the required data..
m
Hi @Vikrant Gupta, I added it like this
Copy code
'use strict';

import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { Resource } from '@opentelemetry/resources';
import {
  MeterProvider,
  PeriodicExportingMetricReader,
} from '@opentelemetry/sdk-metrics';
import * as opentelemetry from '@opentelemetry/sdk-node';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

// Configure the SDK to export telemetry data to the console
// Enable all auto-instrumentations from the meta package
const exporterOptions = {
  url: '<http://127.0.0.1:4318/v1/traces>',
};

const traceExporter = new OTLPTraceExporter(exporterOptions);
const metricReader = new PeriodicExportingMetricReader({
  exporter: new OTLPMetricExporter({
    url: '<http://127.0.0.1:4318/v1/metrics>',
  }),
  exportIntervalMillis: 10000,
});
const resource = new Resource({
  [SemanticResourceAttributes.SERVICE_NAME]: 'elio',
});
const myServiceMeterProvider = new MeterProvider({
  resource,
  readers: [metricReader],
});
const sdk = new opentelemetry.NodeSDK({
  traceExporter,
  instrumentations: [getNodeAutoInstrumentations()],
  resource,
});
opentelemetry.metrics.setGlobalMeterProvider(myServiceMeterProvider);
// initialize the SDK and register with the OpenTelemetry API
// this enables the API to record telemetry
sdk.start();

// gracefully shut down the SDK on process exit
process.on('SIGTERM', () => {
  sdk
    .shutdown()
    .then(() => console.log('Tracing terminated'))
    .catch((error) => console.log('Error terminating tracing', error))
    .finally(() => process.exit(0));
});

export default sdk;
However, I am getting a new error, saying
Property 'setGlobalMeterProvider' does not exist on type 'typeof import("/Users/ironji/descholar/myprojects/ironji/ironji-stargate/node_modules/@opentelemetry/sdk-metrics/build/src/index")'
it looks like this method
setGlobalMeterProvider
does not exists on opentelemetry.metrics or maybe I am doing it in a wrong way, any assistance here?
v
Copy code
import opentelemetry from '@opentelemetry/api';
the opentelemetry you are using is from different package. it is supposed be from
@opentelemetry/api
also the
SDK
accepts
metricReader
you can add your metric reader here or try it the same way you did earlier just correct the imports