I am trying to set up a tracing installation for the Hello world example from Lightstep https://lightstep.com/blog/opentelemetry-nodejs/:
const express = require("express");
const PORT = process.env.PORT || "8080";
const app = express();
app.get("/", (req, res) => {
res.send("Hello World");
});
app.listen(parseInt(PORT, 10), () => {
console.log(`Listening for requests on http://localhost:${PORT}`);
});
My tracing.js looks as follows:
'use strict';
const opentelemetry = require('@opentelemetry/api');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { BatchSpanProcessor } = require("@opentelemetry/tracing");
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { autoinstrumentationsnode } = require('@opentelemetry/auto-instrumentations-node');
module.exports = () => {
const provider = new NodeTracerProvider();
const exporterOptions = {
serviceName: "my-service-name",
url: "http://localhost:4317",
}
const exporter = new CollectorTraceExporter(exporterOptions);
provider.addSpanProcessor(new BatchSpanProcessor(exporter));
provider.register();
registerInstrumentations({
instrumentations: [
new autoinstrumentationsnode(),
],
})
return opentelemetry.trace.getTracer("instrumentation-example");
}
My collector is listening on the localhost:4317, the config file is as follows:
receivers:
otlp:
protocols:
grpc:
endpoint: "localhost:4317"
exporters:
logzio:
account_token: token
processors:
batch:
extensions:
pprof:
endpoint: :1777
zpages:
endpoint: :55679
health_check:
service:
extensions: [health_check, pprof, zpages]
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [logzio]
I am running otelcontribcol_darwin_amd64 version 23. It sends the traces to my logz.io account. It works for Java and Python apps.
With node.js I am stuck. The terminal says the node is running on localhost:8080, but it just doesn't send any traces anywhere. When I change the output to console, it does show me the traces. So the problem is somewhere in the communication between the collector and instrumentation.
Could you please advise as to what I could try to fix this?
Many thanks!