# zipkin

> The core tracer for Zipkin JS

Latest version **0.22.0** (published 2020-06-04) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install zipkin
pnpm add zipkin
yarn add zipkin
bun add zipkin
```

## Health

**Score 30/100 (F)** — status: abandoned.

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.22.0 |
| Published | 2020-06-04 |
| First published | 2015-07-13 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 478.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 568 |
| Author | OpenZipkin |
| Maintainers | openzipkin |

## Links

- npm: https://www.npmjs.com/package/zipkin
- Repository: https://github.com/openzipkin/zipkin-js
- Homepage: https://github.com/openzipkin/zipkin-js#readme
- Issues: https://github.com/openzipkin/zipkin-js/issues
- npm.io page: https://npm.io/package/zipkin

## Dependencies (2)

- [base64-js](https://npm.io/package/base64-js.md) ^1.1.2
- [is-promise](https://npm.io/package/is-promise.md) ^2.1.0

## Recent versions

- 0.22.0 (latest) — 2020-06-04
- 0.22.1-alpha.6 (canary) — 2021-03-01
- 0.22.1-alpha.3 — 2020-11-03
- 0.21.0 — 2020-04-16
- 0.20.0 — 2020-03-25
- 0.19.2 — 2020-02-06
- 0.19.2-alpha.6 — 2020-02-06
- 0.19.2-alpha.3 — 2020-01-30
- 0.19.2-alpha.1 — 2019-10-25
- 0.19.1 — 2019-10-16
- 0.20.0-alpha.1 — 2019-08-09
- 0.20.0-alpha.0 — 2019-08-09
- 0.19.0 — 2019-08-07
- 0.18.6 — 2019-07-24
- 0.18.5 — 2019-07-12
- … 44 more at https://npm.io/package/zipkin/versions

## README

# zipkin

This is the core npm package for Zipkin. It contains the public API which is used by the various
plugins (instrumentations and transports).

We include TypeScript [definition file](index.d.ts) which you can also use as documentation.

## Developing

Please always make sure that [TypeScript type definitions](index.d.ts) match source code modifications.

## Usage

```javascript
const zipkin = require('zipkin');

// In Node.js, the recommended context API to use is zipkin-context-cls.
const CLSContext = require('zipkin-context-cls');
const ctxImpl = new CLSContext(); // if you want to use CLS
const xtxImpl = new zipkin.ExplicitContext(); // Alternative; if you want to pass around the context manually

// Tracer will be a one to many relationship with instrumentation that use it (like express)
const tracer = new zipkin.Tracer({
  ctxImpl, // the in-process context
  recorder: new zipkin.ConsoleRecorder(), // For easy debugging. You probably want to use an actual implementation, like Kafka or AWS SQS.
  sampler: new zipkin.sampler.CountingSampler(0.01), // sample rate 0.01 will sample 1 % of all incoming requests
  traceId128Bit: true, // to generate 128-bit trace IDs. 64-bit (false) is default
  localServiceName: 'my-service' // indicates this node in your service graph
});
```

### In-process context (node only)

The event loop is what allows Node.js to perform non-blocking I/O operations, hence
several operations are happening at the same time and we need a way to correlate different operations that happen at the same time to a specific trace. There are two options for this: explicit and implicit context.

In the **explicit context**, we pass around an object `ctx` from the top layer of the application down to those operations we want to trace. For example, a `ctx` will be handed from the HTTP handler down to the application layer and finally to a HTTP call that queries external resources.

In the **implicit context**, we don't need to pass anything, the in-process context is transparent for the user (see [zipkin-context-cls](pakcages/zipkin-context-cls)).

### Local tracing

Sometimes you have activity that precedes a remote request that you want to
capture in a trace. `tracer.local` can time an operation, placing a
corresponding span ID in scope so that any downstream commands end up in the
same trace.

Here's an example tracing a synchronous function:

```javascript
// A span representing checkout completes before result is returned
const result = tracer.local('checkout', () => {
  return someComputation();
});
```

Here's an example tracing a function that returns a promise:

```javascript
// A span is in progress and completes when the promise is resolved.
const result = tracer.local('checkout', () => {
  return createAPromise();
});
```

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