open-telemetry / opentelemetry-js

OpenTelemetry JavaScript Client
https://opentelemetry.io
Apache License 2.0
2.71k stars 789 forks source link

Issue with gRPC while using auto instrumentation #3939

Closed teammakdi closed 1 year ago

teammakdi commented 1 year ago

What happened?

Steps to Reproduce

I'm trying to use opentelemetry auto configuration

npm install --save @opentelemetry/api @opentelemetry/auto-instrumentations-node
node --require @opentelemetry/auto-instrumentations-node/register app.js

.env

OTEL_TRACES_EXPORTER=otlp
OTEL_EXPORTER_OTLP_ENDPOINT=http://xxx.xx.xx.xx:4317
OTEL_NODE_RESOURCE_DETECTORS=all
OTEL_SERVICE_NAME=test

Expected Result

App should send traces to the configured OTLP endpoint with gRPC protocol

Actual Result

Error

Additional Details

node version: 16.x

Relevant log output


test  | OpenTelemetry automatic instrumentation started successfully
test  | @opentelemetry/instrumentation-grpc Module @grpc/grpc-js has been loaded before @opentelemetry/instrumentation-grpc so it might not work, please initialize it before requiring @grpc/grpc-js
test  | {"stack":"Error: Parse Error: Expected HTTP/\n    at Socket.socketOnData (node:_http_client:534:22)\n    at Socket.emit (node:events:513:28)\n    at addChunk (node:internal/streams/readable:315:12)\n    at readableAddChunk (node:internal/streams/readable:289:9)\n    at Socket.Readable.push (node:internal/streams/readable:228:10)\n    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)\n    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)","message":"Parse Error: Expected HTTP/","code":"HPE_INVALID_CONSTANT","reason":"Expected HTTP/","rawPacket":"\u0000\u0000\u0006\u0004\u0000\u0000\u0000\u0000\u0000\u0000\u0005\u0000\u0000@\u0000","name":"Error"}
teammakdi commented 1 year ago

Got it fixed by doing

npm install --save @opentelemetry/instrumentation-grpc @opentelemetry/api @opentelemetry/auto-instrumentations-node 
ArtunSubasi commented 8 months ago

I still have the same problem and the above suggestion does not work for me. Did anyone find another solution?

gigi commented 7 months ago

The same issue with the nestjs

klacointe commented 6 months ago

Same issue with auto-instrumentations-node. @teammakdi solution does not work for me, mentioned packages was already installed at their latest version.