koa-opentracing
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -20,3 +20,3 @@ 'use strict'; | ||
this._tags = spanOptions.tags || {}; | ||
this._references = spanOptions.references; | ||
this._references = spanOptions.references || []; | ||
this._parentSpanContext = null; | ||
@@ -27,11 +27,4 @@ | ||
if (!this.context()) { | ||
if (this._references && this._references.length > 0) { | ||
const parentSpanContext = this._references[0].referencedContext(); | ||
if (parentSpanContext instanceof Span) { | ||
this._parentSpanContext = parentSpanContext.context(); | ||
} else { | ||
this._parentSpanContext = parentSpanContext; | ||
} | ||
} | ||
if (!this.CONTEXT && this._references.length > 0) { | ||
this._parentSpanContext = this._references[0].referencedContext(); | ||
} | ||
@@ -38,0 +31,0 @@ |
@@ -72,3 +72,7 @@ 'use strict'; | ||
assert(name, 'name is required when startSpan'); | ||
spanOptions.references = spanOptions.references || []; | ||
if (this.currentSpan) { | ||
const reference = opentracing.childOf(this.currentSpan); | ||
spanOptions.references.push(reference); | ||
} | ||
const span = new Span(this, spanOptions); | ||
@@ -75,0 +79,0 @@ span.setOperationName(name); |
{ | ||
"name": "koa-opentracing", | ||
"main": "dist/index.js", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"repository": "https://github.com/teambition/koa-opentracing.git", | ||
@@ -13,3 +13,3 @@ "author": "cnwangjie", | ||
"build": "babel src -d dist", | ||
"prepublish": "yarn build" | ||
"prepublishOnly": "yarn build" | ||
}, | ||
@@ -16,0 +16,0 @@ "dependencies": { |
@@ -18,3 +18,3 @@ const cluster = require('cluster') | ||
this._tags = spanOptions.tags || {} | ||
this._references = spanOptions.references | ||
this._references = spanOptions.references || [] | ||
this._parentSpanContext = null | ||
@@ -25,11 +25,4 @@ | ||
if (!this.context()) { | ||
if (this._references && this._references.length > 0) { | ||
const parentSpanContext = this._references[0].referencedContext() | ||
if (parentSpanContext instanceof Span) { | ||
this._parentSpanContext = parentSpanContext.context() | ||
} else { | ||
this._parentSpanContext = parentSpanContext | ||
} | ||
} | ||
if (!this.CONTEXT && this._references.length > 0) { | ||
this._parentSpanContext = this._references[0].referencedContext() | ||
} | ||
@@ -36,0 +29,0 @@ |
@@ -52,3 +52,7 @@ const assert = require('assert') | ||
assert(name, 'name is required when startSpan') | ||
spanOptions.references = spanOptions.references || [] | ||
if (this.currentSpan) { | ||
const reference = opentracing.childOf(this.currentSpan) | ||
spanOptions.references.push(reference) | ||
} | ||
const span = new Span(this, spanOptions) | ||
@@ -55,0 +59,0 @@ span.setOperationName(name) |
62
test.js
const Koa = require('koa') | ||
const app = new Koa() | ||
const Router = require('koa-router') | ||
const koaOpentracing = require('./dist') | ||
const koaOpentracing = require('./src/index') | ||
// const ConstSampler = koaOpentracing.sampler.ConstSampler | ||
const ZipkinLogger = require('./src/logger/zipkinLogger') | ||
const router = new Router() | ||
router.get('/asd/*', koaOpentracing.middleware('t0')) | ||
router.get('/asd/s', async ctx => { | ||
await new Promise(resolve => setTimeout(resolve, 1000)) | ||
}) | ||
router.get('/asd/:a', async ctx => { | ||
await new Promise(resolve => setTimeout(resolve, +ctx.params.a)) | ||
}) | ||
// const ZipkinLogger = koaOpentracing.logger.ZipkinLogger | ||
// const router = new Router() | ||
// router.get('/asd/*', koaOpentracing.middleware('t0')) | ||
// router.get('/asd/s', async ctx => { | ||
// await new Promise(resolve => setTimeout(resolve, 1000)) | ||
// }) | ||
// router.get('/asd/:a', async ctx => { | ||
// await new Promise(resolve => setTimeout(resolve, +ctx.params.a)) | ||
// }) | ||
koaOpentracing(app, { | ||
@@ -20,20 +20,32 @@ appname: 'test', | ||
{log: console.log}, | ||
// new ZipkinLogger({ | ||
// endpoint: 'http://192.168.0.22:9411', | ||
// version: 'v2', | ||
// interval: 1000 | ||
// }) | ||
new ZipkinLogger({ | ||
endpoint: 'http://192.168.0.22:9411', | ||
version: 'v2', | ||
interval: 1000 | ||
}) | ||
], | ||
}) | ||
app.use(router.routes()) | ||
// app.use(async ctx => { | ||
// const date = Date.now() | ||
// await ctx.tracer.wrap(async function ttttt (a) { | ||
// await new Promise(resolve => setTimeout(resolve, 1000)) | ||
// if (Math.random() > 0.5) { throw new Error('err') } | ||
// return '11111111' | ||
// })('aaaaa') | ||
// console.log(Date.now() - date) | ||
// }) | ||
// app.use(router.routes()) | ||
app.use(async ctx => { | ||
const date = Date.now() | ||
const span0 = ctx.tracer.startSpan('t0') | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
const span2 = ctx.tracer.startSpan('t2') | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
const span1 = ctx.tracer.startSpan('t1') | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
span0.finish() | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
span2.finish() | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
span1.finish() | ||
await ctx.tracer.wrap(async function ttttt (a) { | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
if (Math.random() > 0.5) { throw new Error('err') } | ||
return '11111111' | ||
})('aaaaa') | ||
console.log(Date.now() - date) | ||
}) | ||
app.listen('4010') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
169057
33
1109