npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zipkin-simple

v1.0.0

Published

A simple node.js client for zipkin tracing system

Downloads

21

Readme

zipkin-simple

npm version Build Status

A simple node.js client for zipkin tracing system

This is a basic alternative to the official (and more complete) zipkin-js.

Focus of this version is being easier to use and having a more idiomatic api.

Current Caveats

  • Only http transport
  • Only standard annotations (client send, client receive, server send and server receive)

Install

npm install zipkin-simple --save

Usage

var Zipkin = require('zipkin-simple')
var tracer = new Zipkin({
  debug: false,
  host: "127.0.0.1",
  port: "9411",
  path: "/api/v1/spans"
})

var traceData
traceData = tracer.sendClientSend(traceData, {
  service: 'service name',
  name: 'endpoint name'
})

The basic idea is that the tracer only manage the comunication to the zipkin server and lets you manage the trace data however you prefer.

This means that it's up to you on how to store the trace data and how to sync that among clients and servers.

Zipkin suggest to use http headers, but you are free to use anything else.

Transports

At the current version zipkin-simple only support three type of transports: http, http-simple, custom function

Http sends traces via http in batches of configurable sizes, in order to decrease the traffic to the zipkin server. This is the default

Http-simple sends a request for each trace "update" (i.e. adding a new trace) and thus is not suited for production environments

You can also pass in a custom function that will be used as the transport. It will receive a call every time there's a trace update with the trace data and the current zipking options:

tracer.options({
  transport: function dummy(data, options) {
    console.log(data)
  }
})

In this example each trace update will be logged on the console instead of being sent to zipkin.

Another example can be found in the tests.

API

We use the names "client process" and "server process" as in zipkin documentation but zipkin-simple can also be used in a single process environment or to track local methods. In this case consider "client process" as the caller method and server process as the called method.

You also don't need to send both client and server annotations, especially when tracking local methods. Just one of the two couples will suffice to zipkin to correctly generate the spans.

All methods are in "underscore" notation but provide camelCase aliases, use the one that fits your style better.

See an usage example in seneca-zipkin-tracer

tracer.options(opts)

If opts is passed in update current options, otherwise just return existing options.

Options include:

  • debug: wether to write debug info to the console
  • host: the hostname or ip address for the zipkin server
  • port: the port for the http transport of the zipkin server
  • path: the endpoint where to send data on the zipkin server (if uncertain, leave the default unchanged)
  • sampling: the sampling ratio, from 0 to 1 (0 means don't send data, 1 send all data)
  • transport: which transport to use. Currently supported are "html" (default), "html-simple" or a custom function. Each transport may have additional options available
  • batchSize: for http transport only, size of the batch of traces to send to zipkin
  • batchTimeout: for http transport only, inactivity time before sending uncompleted batches to zipkin

tracer.sendClientSend(traceData, annotationData)

Add the cs annotation to the current span (and trace).

This is intended to be used on the client process just before it fires a request to the server.

Whilest annotationData is mandatory, traceData can be null: in that case a new root trace will be created.

The methods return a new or updated traceData to be used for further calls

Annotation Data contains additional info about the current method:

  • service: the name of the current service. It should be an identifier of running process (or class of processes), i.e.: web_server, background_worker, checkout_process. This will be displayed in the zipkin console
  • name: the name of the method being tracked, i.e.: POST /user or update_credentials. Thi will be displayed in the zipking console on the single span

tracer.sendClientReceive(traceData, annotationData)

Add the cr annotation to the current span (and trace).

This is intended to be used on the client process when it receives data back from the server.

Both traceData and annotationData are mandatory.

For details about annotationData see here

tracer.sendServerReceive(traceData, annotationData)

Add the sr to the current span (and trace).

This is intended to be used on the server process as soon it receives data from the client.

Whilest annotationData is mandatory, traceData can be null: in that case a new root trace will be created and the trace will be considered to be server-only

For details about annotationData see here

tracer.sendServerSend(traceData, annotationData)

Add the ss to the current span (and trace).

This is intended to be used on the server process when it has completed its operations and is about to send data back to the client.

Both traceData and annotationData are mandatory.

For details about annotationData see here

tracer.getChild(traceData)

Return trace data to be sent alongside the next child request.

This is used to generate a child span, in example when the current request calls another endpoint before completing.

traceData is the data related to the current span as returned by one of the send methods. If null or undefined a new root trace is generated

License

MIT

Acknowledgements

Maintainer - Paolo Chiodi

This project was kindly sponsored by nearForm.