Skip to main content
This guide walks you through instrumenting a small Node.js application with OpenTelemetry and sending its logs, metrics, traces, and session replays into Managed ClickStack. The backend is instrumented with no changes to the application source code. The HackerNews Analyzer is a Node.js app that queries the HackerNews dataset hosted in the public ClickHouse demo. Every chart, table, and search box is backed by a real ClickHouse query, so every interaction produces a trace whose main span is the HTTPS call from the backend out to ClickHouse. This guide assumes you’ve completed Setting up your OpenTelemetry Collector and have a ClickStack collector running and reachable from the machine you run this application on. Ensure you have recorded its OTLP endpoint and the OTLP_AUTH_TOKEN you set when deploying it. You will put those values in .env before instrumenting.

Prerequisites

  • A ClickStack collector reachable from this machine. If you haven’t deployed one yet, follow Setting up your OpenTelemetry Collector first.
  • The OTLP/HTTP endpoint of that collector (commonly port 4318) and the OTLP_AUTH_TOKEN you set on it. Use these as OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_HEADERS=authorization=<token>.
  • Node 18+ and npm.

Clone the repository

Clone HackerNews Analyzer, install dependencies, and copy the env template:
You’ll fill .env in the next steps, then instrument from this directory.

Instrument the application

1

Run the application

From the cloned hn-news-analyzer directory, start the app. The ClickHouse data source defaults to the public read-only demo cluster, so it runs without any further configuration:
Open http://localhost:5001. You will see a year selector, summary statistics, an activity chart, top users and domains tables, and a search box. Click around: switch years, drill into stories.
The HackerNews Analyzer application running locally
At this point the application is running but uninstrumented. ClickStack shows no data: it is waiting for telemetry.
2

Configure environment

The SDKs read standard OpenTelemetry exporter variables. They are not hardcoded in source. Open .env and set:
OTEL_EXPORTER_OTLP_ENDPOINT is the OTLP/HTTP endpoint (port 4318). OTEL_EXPORTER_OTLP_HEADERS is the authorization header, in the form authorization=<token> with no Bearer prefix.If the collector does not enforce auth, leave the token empty (OTEL_EXPORTER_OTLP_HEADERS=authorization=). The variable must still be present; the SDK skips initialization if it is unset or fully empty.The browser SDK reuses these same values. vite.config.ts bakes the endpoint and token into the public bundle at build time, so use a throwaway ingestion token, not a production one.
3

Instrument the application

Pick one path. All three end at the same instrumented app.
With the repo cloned and .env filled in, paste this prompt into a coding agent in that directory to instrument the application.
4

Generate traffic and view telemetry

Restart the application so the new launch command and freshly built browser bundle take effect:
Confirm the startup banner prints three “Health check passed” lines for /v1/traces, /v1/metrics, and /v1/logs. Reload the browser tab so Vite serves the updated bundle, then switch years and click into stories to generate traffic.Open the ClickStack UI:
  1. Go to Search and filter to the last 5 minutes. Logs for hn-analyzer-api stream in.
ClickStack search showing hn-analyzer-api logs from the last five minutes
  1. Click into a request and walk up the trace. You will see the Express handler span, a child HTTP span pointing at sql-clickhouse.clickhouse.com with real network duration, and correlated console.log records on the same trace.
ClickStack trace with an Express handler span and a child HTTP span to ClickHouse
  1. Open Session Replay to play back a scrubbable video of a browser session, synced to the trace timeline.
ClickStack session replay synced to the trace timeline
Logs, metrics, traces, and session replays land in the same UI, share the same query language, and are correlated automatically.

Further reading