Skip to content

Instantly share code, notes, and snippets.

@jarededwards
Last active February 22, 2019 00:14
Show Gist options
  • Save jarededwards/bf6032b9a4865554f13d4b74b8bb13b6 to your computer and use it in GitHub Desktop.
Save jarededwards/bf6032b9a4865554f13d4b74b8bb13b6 to your computer and use it in GitHub Desktop.
const ddTrace = require('dd-trace');
import { config } from "config"
export const tracer = ddTrace.init({
enabled: true,
env: config.env,
logInjection: true,
sampleRate: 1,
});
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);
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;
}
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