# Trace a Node.js app

The official OpenTelemetry auto-instrumentations for Node.js hook HTTP, Express, Fastify, gRPC, Postgres, Redis and more. No application code changes are needed. Epok accepts OTLP over HTTP, so keep the HTTP exporter; there is no gRPC endpoint.

Time to first span: **about 5 min**. API key: [app.epok.cloud, then Settings, then API Keys](https://app.epok.cloud).

## 1. Set the OTLP endpoint and key

Set these in the environment that starts your app. Use the base URL; the SDK appends `/v1/traces`. The header name must be `x-api-key`.

```
export OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.epok.cloud"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"   # not gRPC
export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=YOUR_API_KEY"
export OTEL_EXPORTER_OTLP_COMPRESSION="gzip"
export OTEL_SERVICE_NAME="checkout-service"          # becomes service.name
```

## 2. Install the auto-instrumentation

Install the official package and start Node with its register hook. The hook loads before your application code and initializes the SDK.

```
npm install @opentelemetry/api @opentelemetry/auto-instrumentations-node

# Start Node with the register hook. It sets up the SDK for you.
node --require @opentelemetry/auto-instrumentations-node/register app.js
```

## 3. Set service.name

`OTEL_SERVICE_NAME` becomes the `service.name` resource attribute. Use one stable name per service. This is the name you filter by in Epok.

## 4. Verify traces in Epok

1. Send a request through your app.
2. Open **Traces** in the app and filter by service name `checkout-service`.
3. A span tree appears within a few seconds. The service summary fills in after a few minutes of traffic.

## Logs

This guide does not use the Node.js OpenTelemetry logs SDK yet. Send logs with your existing logger to the OTLP collector. See [OpenTelemetry Collector](https://epok.cloud/docs/install/otel-collector).

## Troubleshooting

1. **No spans arrive.** A gRPC exporter cannot use the HTTP endpoint. Set `OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf` and confirm the register hook loads before your app code.
2. **Spans show as `unknown_service:node`.** `OTEL_SERVICE_NAME` did not reach the process. Set it in the same environment that starts Node.
3. **401 or 403.** 401 means no key was found; check the header is exactly `x-api-key` in `OTEL_EXPORTER_OTLP_HEADERS`. 403 means the key was read and rejected; check its scope and whether it was rotated.

Next

- [Go traces](https://epok.cloud/docs/install/traces/go): the SDK setup in main, with otelhttp for handlers.
- [Java traces](https://epok.cloud/docs/install/traces/java): one JVM flag for the official agent.
- [.NET traces](https://epok.cloud/docs/install/traces/dotnet): auto-instrumentation and the logging bridge.
- [Authentication](https://epok.cloud/docs/authentication): every accepted credential header.
