Skip to main content

Hello World - Send Your First Trace

What You Will Build​

A command-line app that creates three OpenTelemetry spans - a successful greeting, a disk-space warning, and a config-parsing error - and sends traces, logs, and metrics to your Scout collector. After running it you will see all three signal types correlated in TraceX and LogX. This guide covers all 9 officially supported languages.

Prerequisites​

  • A Scout account with a collector running (5-Minute Quick Start if you haven't set one up yet)
  • The language runtime for the tab you pick installed on your machine
  • Your collector endpoint (default http://localhost:4318)

Choose Your Language​

Install Dependencies​

package.json
{
"name": "hello-world-nodejs",
"version": "1.0.0",
"private": true,
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/api-logs": "^0.213.0",
"@opentelemetry/exporter-logs-otlp-http": "^0.213.0",
"@opentelemetry/exporter-metrics-otlp-http": "^0.213.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.213.0",
"@opentelemetry/resources": "^2.6.0",
"@opentelemetry/sdk-logs": "^0.213.0",
"@opentelemetry/sdk-metrics": "^2.6.0",
"@opentelemetry/sdk-trace-base": "^2.6.0",
"@opentelemetry/sdk-trace-node": "^2.6.0"
}
}
npm install

The Code​

main.js
function sayHello(tracer, otelLogger, helloCounter) {
tracer.startActiveSpan("say-hello", (span) => {
otelLogger.emit({
severityText: "INFO",
severityNumber: SeverityNumber.INFO,
body: "Hello, World!",
});
helloCounter.add(1);
span.setAttribute("greeting", "Hello, World!");
span.end();
});
}

The full example also includes checkDiskSpace (warning) and parseConfig (error with exception). View full source on GitHub →

Run It​

OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 node main.js

Verify in Scout​

  1. Open TraceX and search for the service name (e.g. hello-world-nodejs).
  2. Click the trace to see three spans: say-hello, check-disk-space, and parse-config.
  3. Open LogX - logs from say-hello and the other spans carry the same trace ID, so you can jump between the trace and its logs.
  4. Check Metrics for the hello.count counter.

What Each Span Demonstrates​

SpanSignalsWhat it shows
say-hellotrace + log + metricNormal operation with an INFO log and counter
check-disk-spacetrace + log (or event)Degraded state with a WARN log
parse-configtrace + log (or event)Error path with exception recording and ERROR status

What's Next​

Was this page helpful?