#support

NodeJS App Integration with OpenTelemetry Issue

TLDR Vinay was having trouble integrating OpenTelemetry into a NodeJS app. Srikanth advised updating to the latest versions of the relevant npm packages, which resolved the issue.

Powered by Struct AI
6
1w
Solved
Join the chat
Nov 15, 2023 (2 weeks ago)
Vinay
Photo of md5-df99c3a98afa01492fc4cd4589255d81
Vinay
01:03 PM
Hey guys, I'm trying to integrate node into my nodeJS app. This manual integration of OpenTelemetry, as the app is on AdonisJS and there are no auto instrumentations. This is the tracing.js file I'm using.

// tracing.js
'use strict'
const process = require('process');

const { Resource } = require('@opentelemetry/resources');
const opentelemetry = require('@opentelemetry/sdk-node');
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
const { diag, DiagConsoleLogger, DiagLogLevel } = require('@opentelemetry/api');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');

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

const exporterOptions = {
  url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || '',
}

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

// 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));
});


And after running, I didn't see any data on SigNoz. After enabling debug logs, I see this:

{"stack":"OTLPExporterError: Bad Request\n    at IncomingMessage. (/Users/vinay/vananam/internal-api/node_modules/@opentelemetry/otlp-exporter-base/src/platform/node/util.ts:131:27)\n    at /Users/vinay/vananam/internal-api/node_modules/@opentelemetry/context-async-hooks/src/AbstractAsyncHooksContextManager.ts:75:49\n    at AsyncLocalStorage.run (node:async_hooks:335:14)\n    at AsyncLocalStorageContextManager.with (/Users/vinay/vananam/internal-api/node_modules/@opentelemetry/context-async-hooks/src/AsyncLocalStorageContextManager.ts:40:36)\n    at IncomingMessage.contextWrapper (/Users/vinay/vananam/internal-api/node_modules/@opentelemetry/context-async-hooks/src/AbstractAsyncHooksContextManager.ts:75:26)\n    at IncomingMessage.emit (node:events:526:35)\n    at endReadableNT (node:internal/streams/readable:1408:12)\n    at processTicksAndRejections (node:internal/process/task_queues:82:21)","message":"Bad Request","name":"OTLPExporterError","data":"{\"code\":3,\"message\":\"ReadUint64: unsupported value type, error found in #10 byte of ...|UnixNano\\\":{\\\"low\\\":200|..., bigger context ...|\\\":\\\"test manual span\\\",\\\"kind\\\":1,\\\"startTimeUnixNano\\\":{\\\"low\\\":200587200,\\\"high\\\":395822425},\\\"endTimeUnixNan|...\"}","code":"400"}


Would anyone be able to help out? I'm not sure if it a tracing issue, or my SigNoz setup issue
Nov 16, 2023 (1 week ago)
Srikanth
Photo of md5-ce04a9988e2fd758a659dc55be6f2543
Srikanth
03:49 AM
What is the otlp-http exporter version you are using? The error "Bad Request","name":"OTLPExporterError","data":"{\"code\":3,\"message\":\"ReadUint64: unsupported value type, error found in #10 byte of indicates the payload is wrong.
Vinay
Photo of md5-df99c3a98afa01492fc4cd4589255d81
Vinay
08:19 AM
0.44.0
Nov 17, 2023 (1 week ago)
Srikanth
Photo of md5-ce04a9988e2fd758a659dc55be6f2543
Srikanth
06:15 AM
That should work, but if possible please use these latest verified versions
npm install --save @opentelemetry/api@^1.6.0                                                                       
npm install --save @opentelemetry/sdk-node@^0.45.0
npm install --save @opentelemetry/auto-instrumentations-node@^0.39.4
npm install --save @opentelemetry/exporter-trace-otlp-http@^0.45.0

Vinay
Photo of md5-df99c3a98afa01492fc4cd4589255d81
Vinay
07:09 AM
Cool, will check. Could that be the issue? In the sdk itself?
07:32
Vinay
07:32 AM
Wow, yeah that worked! Thanks Srikanth! 🙌:skin-tone-4: