Last active
February 22, 2019 00:14
-
-
Save jarededwards/bf6032b9a4865554f13d4b74b8bb13b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ddTrace = require('dd-trace'); | |
import { config } from "config" | |
export const tracer = ddTrace.init({ | |
enabled: true, | |
env: config.env, | |
logInjection: true, | |
sampleRate: 1, | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tracer = require("./ddTracer"); | |
import * as Koa from "koa"; | |
import * as Router from "koa-router"; | |
import * as traceView from "./traceView"; | |
const app = new Koa(); | |
const traceRouter = new Router(); | |
// the route we care about | |
traceRouter.get("/trace/traceTest/:user", traceView.traceTest); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const functionOne = async () => { | |
logger.info('made it in functionOne'); | |
const childOf = tracer.scope().active(); | |
const functionOneSpan = tracer.startSpan('functionOne', { childOf }) | |
let result: any = await sleep(10); | |
try { | |
await functionTwo(); | |
} catch (error) { | |
logger.error(error); | |
} | |
functionOneSpan.finish(); | |
return result; | |
}; | |
export const functionTwo = async () => { | |
logger.info('made it in functionTwo'); | |
const childOf = tracer.scope().active(); | |
const functionTwoSpan = tracer.startSpan('functionTwo', { childOf }) | |
let result: any; | |
await sleep(5); | |
result = await appdb(); | |
functionTwoSpan.finish(); | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tracer = require("dd-trace"); | |
import { trace } from "./traceDAL"; | |
export const traceTest = async (ctx: Context) => { | |
logger.info('in the view in traceTest') | |
// postgres call | |
const fromAppDB = await trace.appdb(); | |
// redis call | |
const fromRedis = await trace.redis(); | |
// mysql call | |
const fromUserDB = await trace.userdb(ctx.params.user); | |
// internal application function | |
const fromInternalFunctions = await trace.functionOne(); | |
ctx.body = { fromAppDB, fromUserDB, fromRedis, fromInternalFunctions }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment