opentelemetry-js: Cannot get HTTP Context Propagation to work
What happened?
Hi, I have set up OTEL tracing but can’t get context propagation to work.
In my setup I have a web app that interacts with an express service that calls another express service. The services export traces to using Grpc a local Collector and are then exported to Jaeger. I can see the spans are exported fine, contain information from the http and express instrumentation libraries but context hasn’t been propagated - The relevant spans don’t have a parent and the relevant HTTP requests don’t contain the HTTP Headers that are needed.
The example project is here: https://github.com/tglanz/simple-tracing. The components are:
Web --> Die Roller --> Randomizer
The OTEL is being set up automatically by running node with some relevant OTEL env vars and specifically NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"
.
Note that I also tried initializing OTEL manually with the same results.
In the example repository, running docker compose up
will deploy the Web App at http://localhost:5173, the Die Roller at http://localhost:8000, the Randomizer service, a Collector with an OTLP Grpc receiver at http://localhost:4173 and a Jaeger FE at http://localhost:16686.
The collector logs (attached) don’t show any error that looks relevant.
Is there any issue here or do I miss something basic? Thanks!
OpenTelemetry Setup Code
Run the first service using node with the env variables below
export OTEL_TRACES_EXPORTER="otlp"
export OTEL_EXPORTER_OTLP_PROTOCOL="grpc"
export OTEL_EXPORTER_OTLP_COMPRESSION="gzip"
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://collector:4317"
export OTEL_EXPORTER_OTLP_HEADERS=""
export OTEL_EXPORTER_OTLP_TRACES_HEADERS=""
export OTEL_RESOURCE_ATTRIBUTES=""
export OTEL_NODE_RESOURCE_DETECTORS="env,host,os"
export OTEL_SERVICE_NAME="die-roller"
export OTEL_LOG_LEVEL="info"
export OTEL_PROPAGATORS=b3,tracecontext,baggage
export OTEL_TRACES_SAMPLES=always_on
export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"
Run the second service using similar env vars but only the service name is changed.
package.json
{
"name": "service-a",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@opentelemetry/api": "^1.6.0",
"@opentelemetry/auto-instrumentations-node": "^0.39.4",
"cors": "^2.8.5",
"express": "^4.18.2",
"pino-http": "^8.5.0",
"pino-pretty": "^10.2.3"
}
}
Relevant log output
The collector log was to big for putting in the issue and can be found here: https://raw.githubusercontent.com/tglanz/simple-tracing/main/service/collector.log
About this issue
- Original URL
- State: closed
- Created 8 months ago
- Comments: 19 (13 by maintainers)
This issue comes from a thread in CNCF’s slack https://cloud-native.slack.com/archives/C01NL1GRPQR/p1699010105287119
In that conversation it was pointed out that the sample project uses ESM imports (kudos to @RichiCoder1) and there are some PRs for handling it on specific packages https://github.com/open-telemetry/opentelemetry-js-contrib/pull/1736 https://github.com/open-telemetry/opentelemetry-js-contrib/pull/1701 https://github.com/open-telemetry/opentelemetry-js-contrib/pull/1694
We should probably check this 1st.