koa-opentracing
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))
span.finish()
})
app.listen('4010')
Compatible with koa@1.*
const koaOpentracing = require('koa-opentracing').v1
API
function koaOpentracing(app: Koa, opt: Object) {}
koaOpentracing.middleware(name: String): Function {}
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
}
class Tracer {
startSpan(name: string, options?: SpanOptions): Span;
inject(spanContext: SpanContext | Span, format: string, carrier: any): void;
extract(format: string, carrier: any): SpanContext | null;
wrap(fn: Function, opt: Object): Function;
expose(format: Span, spanContext?: SpanContext | Span): Object;
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