Skip to content

Commit

Permalink
add db.rowCount
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Gruenfelder committed Dec 20, 2024
1 parent 8db0387 commit da266f1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/tracing/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ function trace(name, fn, targetObj, args, options = {}) {
*/
return otel.context.with(cds.context?._otelctx.setValue(cds.context._otelKey, span), () => {
const onSuccess = res => {
addDbRowCount(span, res)
span.setStatus({ code: SpanStatusCode.OK })
return res
}
Expand All @@ -317,3 +318,20 @@ function trace(name, fn, targetObj, args, options = {}) {
}

module.exports = trace

const addDbRowCount = (span, res) => {
if(!span.attributes["db.statement"] || !["all", "run"].includes(span.attributes["code.function"])) {
return
}
let rowCount;
switch(span.attributes["db.operation"]) {
case "DELETE":
case "UPDATE":
case "CREATE":
rowCount = res.changes;
break;
case "READ":
rowCount = res.length ?? 1
}
span.setAttribute("db.rowCount", rowCount)
}

0 comments on commit da266f1

Please sign in to comment.