# Node.js logs: pino, winston and console

Send the logs your Node.js app already writes with pino, winston, bunyan or console, each tied to the request that wrote it.

You don't need a new logger. OpenTelemetry for Node.js sends pino and winston records as they are written, with the trace and span of the request around them, so a log line opens its trace and a trace shows its logs.

## What you get

- Your app's logs in [Logs](https://flowhawk.dev/docs/signals#logs), next to your traces and metrics, searchable with the same query language (`severity>=WARN service=checkout "timeout"`), grouped into patterns or followed live.
- A log line that names a request path joins the [business flow](https://flowhawk.dev/docs/flows) of that route, so a failing checkout shows these logs on the checkout flow's page.
- A line that carries a trace id opens its trace.
- Alert on any search with **Alert on this**, and let the agent read these logs when it investigates an incident.

## Set it up with the Flowhawk SDK

The Flowhawk Node.js SDK (Node.js 18 or later) sends lines written with `console`, pino, winston and bunyan with no code change, tied to their request and business flow, and still prints them:

```
npm install @flowhawk/sdk-node
```

```
require("@flowhawk/sdk-node").init({ service: "orders" });   // first line of the entry file
```

First create an ingest key: in the app, open **Settings > API keys** and pick **Services**. In the examples below, `KEY` stands for that key. Keep it out of your repository, like any other secret.

```
FLOWHAWK_API_KEY=KEY
FLOWHAWK_CONTROL_URL=https://api.flowhawk.dev
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.flowhawk.dev
FLOWHAWK_ENVIRONMENT=production
```

Each flow's collection settings decide the lowest level kept and which fields are redacted, and you can change them in Flowhawk without a redeploy. `FLOWHAWK_CONSOLE_LOGS=off` leaves `console` alone.

## Or with plain OpenTelemetry

```
npm install @opentelemetry/api @opentelemetry/auto-instrumentations-node
npm install @opentelemetry/winston-transport     # only for winston
```

```
OTEL_SERVICE_NAME=orders
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.flowhawk.dev
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20KEY
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production,service.version=1.4.2
```

The space in the header is written `%20`. Set `service.version` to your release, so a deploy shows as a change next to the flows it made better or worse.

```
OTEL_LOGS_EXPORTER=otlp node --require @opentelemetry/auto-instrumentations-node/register app.js
```

The pino and winston instrumentations are part of the auto-instrumentation: they add the trace id to each record and send it. `console` lines aren't sent this way.

## Check it arrived

Open **Logs** in the app and filter on the service. If nothing shows after a minute, [Help and troubleshooting](https://flowhawk.dev/docs/help) says why data can be refused (a wrong key, an empty balance) and how to see it.

## Common questions

### Do errors I log show up as issues?

Yes, when the record carries the error with its stack, as `logger.error({ err }, "charge failed")` does in pino. An error a request handler throws is recorded on its trace either way.

### My app runs on Vercel or Heroku. Do I need this?

Their log drains send what your app prints without any code ([Vercel](https://flowhawk.dev/integrations/vercel-log-drain), [Heroku](https://flowhawk.dev/integrations/heroku-log-drain)). Sending through OpenTelemetry adds the trace and flow to each line.

## Related

[**OpenTelemetry for Express and Node.js**Trace an Express, Fastify or NestJS app with OpenTelemetry, and send it to Flowhawk with one flag or one line.](https://flowhawk.dev/integrations/opentelemetry-express) [**OpenTelemetry for Next.js**Trace a Next.js app's server rendering, route handlers and fetch calls with @vercel/otel, and send them to Flowhawk.](https://flowhawk.dev/integrations/opentelemetry-nextjs) [**Vercel log drain**Send the logs of your Vercel projects to Flowhawk with a log drain. No SDK and no code change.](https://flowhawk.dev/integrations/vercel-log-drain)

[Try it free for 14 days](https://app.flowhawk.dev/signup?trial=1) [Read the getting started guide](https://flowhawk.dev/docs/getting-started)

---

URL: https://flowhawk.dev/integrations/nodejs-logs
