Skip to content

Commit

Permalink
mssql changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mnadeem committed Feb 27, 2021
1 parent 4caeca6 commit e8e57b1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ config.js
.env.development.local
.env.test.local
.env.production.local
.yalc
yalc.lock

npm-debug.log*
yarn-debug.log*
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@
"@opentelemetry/plugin-express": "^0.13.1",
"@opentelemetry/plugin-http": "^0.15.0",
"@opentelemetry/plugin-https": "^0.15.0",
"opentelemetry-plugin-aws-sdk": "^0.2.1",
"@opentelemetry/tracing": "^0.15.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"log4js": "^6.3.0",
"mssql": "^6.3.1",
"opentelemetry-plugin-aws-sdk": "^0.2.1",
"opentelemetry-plugin-mssql": "^0.1.0",
"prom-client": "^13.1.0"
},
"devDependencies": {
"@babel/cli": "^7.12.16",
"@babel/core": "^7.12.16",
"@babel/node": "^7.12.16",
"@babel/preset-env": "^7.12.16",
"@babel/plugin-transform-runtime": "^7.12.15",
"@babel/preset-env": "^7.12.16",
"nodemon": "^2.0.7",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2"
Expand Down
8 changes: 3 additions & 5 deletions src/dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,20 @@ sql.on('error', err => {
});

export const getFlightById = (flightId) => {
const childSpan = tracer.startSpan('dao.getFlightById');

const request = new sql.Request(pool);
let query = queryGetFlightById();

childSpan.setAttribute('dao.getFlightById.sql', query);

request
.input('flightId', sql.Int, flightId)
.input('appId', sql.Int, flightId)
.query(query)
.then((result) => {
logger.info(result.recordset);
}).catch(err => {
childSpan.recordException(err);
//childSpan.recordException(err);
logger.error(err);
}).finally(() => childSpan.end());
}).finally();
};

logger.debug("DAO initialized");
33 changes: 16 additions & 17 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const doSomeWorkInNewSpan = (parentSpan) => {
}, context.active());

childSpan.setAttribute('code.filepath', "test");
doSomeHeavyWork(1);
doSomeWorkInNewNestedSpan(childSpan);
childSpan.end();
}
Expand All @@ -56,8 +55,6 @@ const doSomeWorkInNewNestedSpan = (parentSpan) => {
}, ctx);

childSpan.setAttribute('code.filepath', "test2");
//Do some work
doSomeHeavyWork(1);
context.with(setSpan(context.active(), childSpan), doSomeWorkInNewNested2Span);
childSpan.end();
}
Expand All @@ -71,43 +68,45 @@ const doSomeWorkInNewNested2Span = () => {
.then(results => logger.trace(results))
.catch(err => {
logger.error(err);
});

childSpan.end();
}).finally(() => {
childSpan.end();
});
}

function asyncWorkOne(parentSpan) {
const ctx = setSpan(context.active(), parentSpan);
const childSpan = tracer.startSpan('asyncWorkOne', {
attributes: { 'code.function' : 'asyncWorkOne' }
}, ctx);
function asyncWorkOne(parentSpan) {

let promise = new Promise((resolve, reject) => {
try {

const ctx = setSpan(context.active(), parentSpan);
const childSpan = tracer.startSpan('asyncWorkOne', {
attributes: { 'code.function' : 'asyncWorkOne' }
}, ctx);
doSomeHeavyWork(1);
resolve("promise 1 done!")
childSpan.end();
} catch (e) {
reject(e);
} finally {
childSpan.end();
}
});
return promise;
}

function asyncWorkTwo(parentSpan) {
const ctx = setSpan(context.active(), parentSpan);
const childSpan = tracer.startSpan('asyncWorkTwo', {
attributes: { 'code.function' : 'asyncWorkTwo' }
}, ctx);

let promise = new Promise((resolve, reject) => {
try {
const ctx = setSpan(context.active(), parentSpan);
const childSpan = tracer.startSpan('asyncWorkTwo', {
attributes: { 'code.function' : 'asyncWorkTwo' }
}, context.active());
doSomeHeavyWork(2);
resolve("promise 2 done!");
childSpan.end();
} catch (e) {
reject(e);

} finally {
childSpan.end();
}
});
Expand Down
5 changes: 5 additions & 0 deletions src/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const provider = new NodeTracerProvider ({
// You may use a package name or absolute path to the file.
path: "opentelemetry-plugin-aws-sdk",
},
mssql: {
enabled: true,
// You may use a package name or absolute path to the file.
path: "opentelemetry-plugin-mssql",
},
},
logLevel: LogLevel.ERROR,
});
Expand Down

0 comments on commit e8e57b1

Please sign in to comment.