# zipkin-transport-http

> Transports Zipkin trace data via HTTP

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

## Install

```sh
npm install zipkin-transport-http
pnpm add zipkin-transport-http
yarn add zipkin-transport-http
bun add zipkin-transport-http
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.22.0 |
| Published | 2020-06-04 |
| First published | 2016-07-16 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 40.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 568 |
| Author | Openzipkin |
| Maintainers | openzipkin |

## Links

- npm: https://www.npmjs.com/package/zipkin-transport-http
- 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-transport-http

## Dependencies (1)

- [zipkin](https://npm.io/package/zipkin.md) ^0.22.0

## Recent versions

- 0.22.0 (latest) — 2020-06-04
- 0.22.1-alpha.6 (canary) — 2021-03-01
- 0.22.1-alpha.5 — 2021-01-28
- 0.22.1-alpha.3 — 2020-11-03
- 0.21.1-alpha.3 — 2020-06-04
- 0.21.1-alpha.1 — 2020-05-14
- 0.21.1-alpha.0 — 2020-05-14
- 0.21.0 — 2020-04-16
- 0.20.0 — 2020-03-25
- 0.19.3-alpha.2 — 2020-02-24
- 0.19.3-alpha.1 — 2020-02-24
- 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
- … 42 more at https://npm.io/package/zipkin-transport-http/versions

## README

# zipkin-transport-http

![npm](https://img.shields.io/npm/dm/zipkin-transport-http.svg)

This is a module that sends Zipkin trace data to a configurable HTTP endpoint.

## Usage

`npm install zipkin-transport-http --save`

```javascript
const {
  Tracer,
  BatchRecorder,
  jsonEncoder: {JSON_V2}
} = require('zipkin');
const {HttpLogger} = require('zipkin-transport-http');
const noop = require('noop-logger');

const recorder = new BatchRecorder({
  logger: new HttpLogger({
    endpoint: 'http://localhost:9411/api/v2/spans', // Required
    jsonEncoder: JSON_V2, // JSON encoder to use. Optional (defaults to JSON_V1)
    httpInterval: 1000, // How often to sync spans. Optional (defaults to 1000)
    headers: {'Authorization': 'secret'}, // Custom HTTP headers. Optional
    timeout: 1000, // Timeout for HTTP Post. Optional (defaults to 0)
    maxPayloadSize: 0, // Max payload size for zipkin span. Optional (defaults to 0)
    agent: new http.Agent({keepAlive: true}), // Agent used for network related options. Optional (defaults to null)
    log: noop, // Logger to use. Optional (defaults to console)
    fetchImplementation: require('node-fetch') // Pluggable fetch implementation (defaults to global fetch or fallsback to node fetch)
  })
});

const tracer = new Tracer({
  recorder,
  ctxImpl, // this would typically be a CLSContext or ExplicitContext
  localServiceName: 'service-a' // name of this application
});
```

## Options

### Required

- **endpoint** - HTTP endpoint which spans will be sent.

### Optional

- **agent** - HTTP(S) agent to use for any networking related options.
  - Takes an [http](https://nodejs.org/api/http.html#http_class_http_agent)/[https](https://nodejs.org/api/https.html) NodeJS Agent.
  - Defaults to null

```javascript
// Example using a self-signed CA, along with cert/key for mTLS.
new HttpLogger({
  endpoint: 'http://localhost:9411/api/v2/spans',
  agent: new http.Agent({
    ca: fs.readFileSync('pathToCaCert'),
    cert: fs.readFileSync('pathToCert'),
    key: fs.readFileSync('pathToPrivateKey')
  })
})
```

- **headers** - Any additional HTTP headers to be sent with span.
  - Will set `'Content-Type':  'application/json'` at a minimum
- **httpInterval** - How often to sync spans.
  - Defaults to 1000
- **jsonEncoder** - JSON encoder to use when sending spans.
  - Defaults to JSON_V1
- **maxPayloadSize** - Max payload size for zipkin span.
  - Will drop any spans exceeding this threshold.
  - Defaults to 0 (Disabled)
- **log** - Internal logger used within the transport.
  - Defaults to console
- **timeout** - Timeout for HTTP Post when sending spans.
  - Defaults to 0 (Disabled)
- **fetchImplementation** - The fetch API to be used for sending spans.
  - Defaults to default global fetch or fallsback to `node-fetch`.
  - A different fetch implementation can be plugged to fulfill different requirements, for example one can use [fetch-retry](https://github.com/jonbern/fetch-retry) to allow retries and exponential back-off:

    ```javascript
    const {HttpLogger} = require('zipkin-transport-http');
    const fetch = require('node-fetch');
    const fetchRetryBuilder = require('fetch-retry');

    const fetchRetryOptions = {
      // retry on any network error, or > 408 or 5xx status codes
      retryOn: (attempt, error, response) => error !== null
        || response == null
        || response.status >= 408,
      retryDelay: tryIndex => 1000 ** tryIndex // with an exponentially growing backoff
    };

    const fetchImplementation = fetchRetryBuilder(fetch, fetchRetryOptions);

    const httpLogger = new HttpLogger({
      endpoint: `http://localhost:9411/api/v1/spans`,
      httpInterval: 1,
      fetchImplementation
    });
    ```

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