Skip to content

integrate opentracing with connect like style middlewares

Notifications You must be signed in to change notification settings

Luncher/opentracing-connect

Repository files navigation

opentracing-connect

NPM version Build Status Coverage David Status

Quick Start

Integrated With Express

const express = require('express')
const { Tracer, RouterProxy } = require('opentracing-connect')

const app = new express()

const serviceName = 'One'
//create and register global tracer
Tracer.createGlobalTracer(serviceName, { logger: console })
//proxy express router
const Router = RouterProxy.create({ router: express.Router(), proxy: { type: "express" } })

Router.get('/one',  async (request, response, next) => {
  //request has trace prop: traceCtx
  const result = await doSomething(request.traceCtx.span)
  console.log('service one result:')
  console.dir(result)
  response.json(result)
})

Integrated With Koa2

const Koa = require('koa')
const KoaRouter = require('koa-router')

const app = new Koa()
const serviceName = 'Two'
const tracer = Tracer.createGlobalTracer(serviceName, { logger: console })
const Router = RouterProxy.create({ router: KoaRouter(), proxy: { type: "koa2" } })

Router.get('/two', async (ctx, next) => {
  try {
    const userIds = [1, 2]
    //ctx has trace prop: traceCtx    
    const result = await getUserInfo(userIds, { span: ctx.traceCtx.span })
    ctx.traceCtx.span.log({'event': 'request_end'})
    ctx.body = result
  } catch(err) {
    console.log(err)
  }

  return 
})

RouterProxy Configure

{
  //router instance
  router: expressRouter,
  //proxy type
  proxy: {
    type: 'express'
  },
  //add cusmomize tags
  customizeTags: function ({ span, tracer}, ...args) {

  }
}

About

integrate opentracing with connect like style middlewares

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published