# pinpoint-node-agent

> Pinpoint APM agent for Node.js — distributed tracing, error analysis, and URI statistics

Latest version **1.4.6** (published 2026-11-19) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install pinpoint-node-agent
pnpm add pinpoint-node-agent
yarn add pinpoint-node-agent
bun add pinpoint-node-agent
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.4.6 |
| Published | 2026-11-19 |
| First published | 2020-10-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.16 |
| Dependencies | 8 |
| Unpacked size | 1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 63 |
| Maintainers | feelform, npm.pinpoint.naver |
| Keywords | pinpoint, apm, nodejs, node, instrumentation, observability, monitoring, metrics, performance, debugging, profiling, trace, tracing, distributed-tracing, stacktrace, log, logging, error, errors, exception, exceptions, devops |

## Links

- npm: https://www.npmjs.com/package/pinpoint-node-agent
- Repository: https://github.com/pinpoint-apm/pinpoint-node-agent
- Issues: https://github.com/pinpoint-apm/pinpoint-node-agent/issues
- npm.io page: https://npm.io/package/pinpoint-node-agent

## Dependencies (8)

- [semver](https://npm.io/package/semver.md) ^7.5.3
- [loglevel](https://npm.io/package/loglevel.md) ^1.9.2
- [murmur-128](https://npm.io/package/murmur-128.md) ^1.0.0
- [internal-ip](https://npm.io/package/internal-ip.md) ^3.0.1
- [@grpc/grpc-js](https://npm.io/package/@grpc/grpc-js.md) ^1.14.5
- [google-protobuf](https://npm.io/package/google-protobuf.md) ^3.13.0
- [@pinpoint-apm/shimmer](https://npm.io/package/@pinpoint-apm/shimmer.md) ^1.2.2
- [require-in-the-middle](https://npm.io/package/require-in-the-middle.md) ^7.5.2

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.4.6 (latest) — 2026-11-19
- 1.1.0-next.0 (next) — 2025-06-27
- 1.4.5 — 2026-11-05
- 1.4.4 — 2026-10-22
- 1.4.3 — 2026-06-11
- 1.4.2 — 2026-04-03
- 1.4.1 — 2026-03-31
- 1.4.0 — 2026-03-25
- 1.3.1 — 2025-12-31
- 1.3.0 — 2025-11-03
- 1.2.0 — 2025-08-01
- 1.1.0 — 2025-06-30
- 1.0.1 — 2025-05-23
- 1.0.0 — 2025-05-22
- 1.0.0-next.2 — 2025-04-25
- … 37 more at https://npm.io/package/pinpoint-node-agent/versions

## README

# Pinpoint Node.js Agent
This is the official Node.js agent for [Pinpoint](https://github.com/naver/pinpoint).

If you have any feedback or questions,
please post them on the [Discuss issues](https://github.com/naver/pinpoint-node-agent/issues).

## Table of Contents
- [Installation and Getting Started](#installation-and-getting-started)
- [Configuration](#configuration)
- [Supported Modules](#supported-modules)
- [Agent-Collector Compatibility](#agent---collector-compatibility-table)
- [Contributing](#contributing)
- [Migrating `pinpoint-config.json` to v1.4](#migrating-pinpoint-configjson-to-v14)
- [License](#license)

## Migrating `pinpoint-config.json` to v1.4

> **If you use environment variables, no migration is needed.**

v1.4 restructured `pinpoint-config.json` format ([before v1.4](https://github.com/pinpoint-apm/pinpoint-node-agent/blob/1.3.1/lib/pinpoint-config-default.json) → [v1.4](https://github.com/pinpoint-apm/pinpoint-node-agent/blob/1.4.0/lib/pinpoint-config-default.json)). If you have an existing `pinpoint-config.json`, update it as follows:

| before v1.4 | v1.4 |
|------|------|
| `application-type` | `applicationServiceType` |
| `collector.span-port` | `collector.spanPort` |
| `collector.stat-port` | `collector.statPort` |
| `collector.tcp-port` | `collector.tcpPort` |
| `stream-deadline-minutes.client-side` | `collector.deadlineMinutes` |
| `http-status-code.errors` | `plugins.http.errorStatusCodes` |
| `express.enable` | `plugins.express` |
| `koa.enable` | `plugins.koa` |
| `mongo.enable` | `plugins.mongodb` |
| `redis.enable` | `plugins.redis` |
| `enabled-data-sending` | `features.dataSending` |
| `enabled-stats-monitor-sending` | `features.statsMonitoring` |
| `enabled-active-thread-count` | `features.activeThreadCount` |
| `container` | `features.container` |
| `logger-levels` | `features.logLevels` |
| _(new)_ | `features.uriStats` |
| _(new)_ | `features.errorAnalysis` |

v1.4 example:
```json
{
  "applicationServiceType": 1400,
  "collector": {
    "ip": "localhost",
    "spanPort": 9993,
    "statPort": 9992,
    "tcpPort": 9991,
    "deadlineMinutes": 10
  },
  "sampling": { "enable": true, "rate": 10 },
  "plugins": {
    "http": { "errorStatusCodes": "5xx,401,403" },
    "express": true,
    "koa": true
  },
  "features": {
    "uriStats": { "httpMethod": false, "capacity": 1000, "useUserInput": true },
    "errorAnalysis": { "maxDepth": 10 },
    "logLevels": { "default-logger": "WARN", "grpcLogger": "SILENT" }
  }
}
```

## Installation and Getting Started
### 1. Install
Install with [npm](https://www.npmjs.com/):
```sh
npm install --save pinpoint-node-agent
```
Install with [yarn](https://yarnpkg.com):
```sh
yarn add pinpoint-node-agent
```

### 2. Add the Agent

ES6
```ecmascript 6
  import 'pinpoint-node-agent'
```

CommonJS
```javascript
  require('pinpoint-node-agent')
```

#### Next.js
In Next.js, use `NODE_OPTIONS` in `package.json`:
```json
"scripts": {
  "build": "next build",
  "dev": "next dev --turbopack",
  "start": "NODE_OPTIONS=--require=pinpoint-node-agent next start"
}
```

> **Note:** `PINPOINT_TRACE_EXCLUSION_URL_PATTERNS` cannot be set from a `.env` file. Use a shell script instead:

```json
"scripts": {
  "start": "./start.sh"
}
```

```sh
#!/bin/bash
export PINPOINT_TRACE_EXCLUSION_URL_PATTERNS="/health_check,/admin/**"
export PINPOINT_APPLICATION_NAME="your-app-name"
NODE_OPTIONS=--require=pinpoint-node-agent next start
```

```sh
chmod +x start.sh
```

## Configuration

### Environment Variables
Based on the [pinpoint-config-default.json](/lib/pinpoint-config-default.json) file, only necessary parts are set as environment variables.

name | default | description
-----|---------|------------
PINPOINT_AGENT_ID |  | Optional (≤24 chars). Auto-generated random hex if unset. Pattern: `[a-zA-Z0-9._-]+`.
PINPOINT_AGENT_NAME |  | Recommended. Shown in Inspector UI (e.g. pod name, hostname). ≤255 chars. Pattern: `[a-zA-Z0-9._-]+`.<br><img width="611" alt="Agent Name in Inspector" src="https://github.com/user-attachments/assets/8022baa4-8b38-4553-9c12-88de17bc8f22" />
PINPOINT_APPLICATION_NAME | | **Required.** App name (≤24 chars). Multiple agents can share one name. Pattern: `[a-zA-Z0-9._-]+`.
PINPOINT_COLLECTOR_IP | localhost | Pinpoint collector address. e.g. `192.168.0.1`
PINPOINT_SAMPLING_RATE | 10 | Sampling ratio `1/N`. Default `10` = ~10%. See [Performance tester](/demo/performance-tester).
PINPOINT_LOGGER_LEVELS |  | Comma-separated logger levels. e.g. `default-logger=INFO,grpcLogger=SILENT`
PINPOINT_ENABLE | true | Set `false` to disable the agent.
PINPOINT_CONTAINER | false | Docker/Kubernetes mode. Auto-detected from `/.dockerenv`, `/proc/self/cgroup`, or `KUBERNETES_SERVICE_HOST`.
PINPOINT_TRACE_EXCLUSION_URL_PATTERNS |  | Comma-separated URL patterns. e.g. `/health_check,/admin/**`. Replaces old `PINPOINT_TRACE_EXCLUSION_URL_PATTERN` (still recognized; plural form takes precedence). [Unit tests](https://github.com/pinpoint-apm/pinpoint-node-agent/blob/01fcbdefe5a0ffba9c957bee0da3fb7397638182/test/utils/ant-path-matcher.test.js#L332)
PINPOINT_TRACE_EXCLUSION_URL_CACHE_SIZE | | Cache for fixed-pathname URLs. Unnecessary for dynamic paths like `/user/1000`. [Unit tests](https://github.com/pinpoint-apm/pinpoint-node-agent/blob/01fcbdefe5a0ffba9c957bee0da3fb7397638182/test/utils/ant-path-matcher.test.js#L447)
PINPOINT_HTTP_STATUS_CODE_ERRORS | 5xx,401,403 | HTTP status codes treated as errors.
PINPOINT_FEATURES_URI_STATS | true | Set `false` to disable URI stats.
PINPOINT_FEATURES_URI_STATS_HTTP_METHOD | false | Include HTTP method in URI key (e.g. `GET /path`).
PINPOINT_FEATURES_URI_STATS_CAPACITY | 1000 | Max URI patterns per snapshot window.
PINPOINT_FEATURES_URI_STATS_TIME_WINDOW |  | Snapshot window in ms (default: `30000`).
PINPOINT_FEATURES_URI_STATS_USE_USER_INPUT | true | Use user-defined URI template when available. Set a custom URI template on `req`: `req['pinpoint.metric.uri-template'] = '/my/uri'`
PINPOINT_FEATURES_ERROR_ANALYSIS | true | Set `false` to disable error analysis. When `errorAnalysis` config is not set, the feature is disabled.
PINPOINT_FEATURES_ERROR_ANALYSIS_MAX_DEPTH | 10 | Max depth for `Error.cause` chain traversal.

Custom URI template example:
```javascript
const handler = function(req, res) {
  req['pinpoint.metric.uri-template'] = '/user/input/uri/from/pages'
  res.status(200).json({ name: 'custom-uri' })
}
```

### User Configuration File (`pinpoint-config.json`) — since v1.4.0
From [#404](https://github.com/pinpoint-apm/pinpoint-node-agent/issues/404) onward, the agent loads `pinpoint-config.json` automatically:

1. The directory containing your entry script (`require.main.filename`).
2. The current working directory (`process.cwd()`).

If neither location contains the file, built-in defaults are used.

> **Tip:** With `node -r pinpoint-node-agent`, `require.main` can be temporarily undefined. Place `pinpoint-config.json` in `process.cwd()` or use environment variables.

Example layout:
```
my-service/
├─ package.json
├─ server.js
└─ pinpoint-config.json
```


## Supported Modules
* Express 4 and 5
* Koa(koa-router >=5.2.0 <8)
* HTTP, HTTPS
* Redis, ioredis(>=2.0.0 <5.0.0)
* mysql and mysql2
* mongoDB driver v4.0 or higher
* [Fetch API with Undici in Node.js](https://nodejs.org/en/learn/getting-started/fetch)
* Next.js

## Agent - Collector compatibility table
Agent Version | Collector 1.x | Collector 2.x | Collector 3.x
------------- | --------------- | --------------- | ---------------
above v0.8 | no      | yes | yes

## Contributing

We are looking forward to your contributions via pull requests.

To contribute to Pinpoint Node JS agent, you should pass all test suites and your unit tests.

## License

```
   Copyright 2020-present NAVER Corp.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
```

---
_Source: https://npm.io/package/pinpoint-node-agent · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
