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

koa-opentracing

v1.3.7

Published

koa-opentracing ======

Downloads

96,759

Readme

koa-opentracing

Build Status Coverage Status

A koa opentracing plugin and fully compatible with opentracing.

Usage

const Koa = require('koa')
const app = new Koa()

const koaOpentracing = require('koa-opentracing')
koaOpentracing(app, {
  appname: 'test',
  logger: [
    {
      log: console.log
    }
  ]
})
app.use(async ctx => {
  const span = ctx.tracer.startSpan('span')
  await new Promise(r => setTimeout(r, 1000)) // Some time-consuming work
  span.finish()
})
app.listen('4010')

Compatible with koa@1.*

const koaOpentracing = require('koa-opentracing').v1

API


/**
 * main function to add a middleware to assign a tracer on context
 * @param {Koa} app koa application
 * @param {Object} opt options
 * @param {String} opt.appname service name
 * @param {Logger[]} opt.logger an array of logger instance
 * @param {Carrier|String} [opt.httpCarrier] an carrier be used for extract span from http header
 * @param {Object} [opt.httpTag] options of data need to trace of the whole http request
 * @param {Boolean} [opt.httpTag.header] if true will trace the header of the request
 * @param {Object} [opt.carrier] an map of carriers instance
 * @param {Sampler} [opt.sampler] an sampler instance
 */
function koaOpentracing(app: Koa, opt: Object) {}

/**
 * create an koa middleware and auto start a span
 *
 * * Compatible with koa@1.*
 *
 * @param {String} name span name
 * @return {Function} middleware
 */
koaOpentracing.middleware(name: String): Function {}

/**
 * all log method of loggers will be triggered after span finished
 */
interface Logger {
  log(span: Span): void
}

interface Carrier {
  inject(spanContext): spanContextCarrier
  extract(header): spanContextCarrier
}

interface spanContextCarrier {
  traceId: String
  spanId: String
  baggage?: Object
}

interface Sampler {
  isSampled(ctx: Context): Boolean
}

/**
 * Will be instantiated at the beginning of each request and assigned to ctx.tracer
 */
class Tracer {
    /**
     * Starts and returns a new Span representing a logical unit of work.
     *
     * @param {string} name - the name of the operation (REQUIRED).
     * @param {SpanOptions} [options] - options for the newly created span.
     * @return {Span} - a new Span object.
     */
    startSpan(name: string, options?: SpanOptions): Span;
    /**
     * Injects the given SpanContext instance for cross-process propagation
     *
     * @param  {SpanContext} spanContext - the SpanContext to inject into the
     *         carrier object. As a convenience, a Span instance may be passed
     *         in instead (in which case its .context() is used for the
     *         inject()).
     * @param  {string} format - the format of the carrier.
     * @param  {any} carrier - see the documentation for the chosen `format`
     *         for a description of the carrier object.
     */
    inject(spanContext: SpanContext | Span, format: string, carrier: any): void;
    /**
     * Returns a SpanContext instance extracted from `carrier` in the given
     *
     * @param  {string} format - the format of the carrier.
     * @param  {any} carrier - the type of the carrier object is determined by
     *         the format.
     * @return {SpanContext}
     *         The extracted SpanContext, or null if no such SpanContext could
     *         be found in `carrier`
     */
    extract(format: string, carrier: any): SpanContext | null;

    /**
     *
     * A utility method to simplify the use of tracer.
     *
     * It will wrap a method, start a span before method called and finish the
     * span after method execution completed. The method name will be used by
     * default for the name of the span.
     *
     * @param {Function} fn Time-consuming method to track
     * @param {Object} opt
     * @param {any} [opt.thisObj]
     * @param {string} [opt.fnName] function name will be used as span name
     * @param {Boolean} [opt.logParams] if true will trace the params
     * @param {Boolean} [opt.logReturn] if true will trace the return
     * @return {Function} wrapped method
     */
    wrap(fn: Function, opt: Object): Function;

    /**
     * Simplified form of inject. The spanContext is optional and if spanContext
     * is undefined will use current span or create a new SpanContext.
     *
     * @param {String} format
     * @param {SpanContext|Span} [spanContext]
     * @return {Object} be injected object
     */
    expose(format: Span, spanContext?: SpanContext | Span): Object;

    /**
     * @return {Boolean} whether this tracer is sampled
     */
    isSampled(): Boolean;
}

Built in

Need to import manually like following ways.

const HTTPCarrier = require('koa-opentracing/src/carrier/httpCarrier')

src/carrier/httpCarrier

Cross-process tracking via http header

src/logger/zipkinLogger

Built-in logger for zipkin

class ZipkinLogger {
  constructor(opt: {
    version?: 'v1' | 'v2' = 'v1'
    endpoint: string
    interval: number = 1000
  })
}

src/sampler/constSampler

A simple constant sampler

class ConstSampler {
  constructor(decision: boolean)
}

License

MIT LICENSE