@sentry/node
Version:
Sentry Node SDK using OpenTelemetry for performance instrumentation
58 lines (54 loc) • 1.88 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const attributes = require('@sentry/conventions/attributes');
const core = require('@sentry/core');
const semconv = require('./semconv.js');
function getAttributesFromCollection(collection) {
return {
// oxlint-disable-next-line typescript/no-deprecated
[semconv.ATTR_DB_MONGODB_COLLECTION]: collection.name,
// oxlint-disable-next-line typescript/no-deprecated
[attributes.DB_NAME]: collection.conn.name,
[attributes.DB_USER]: collection.conn.user,
// oxlint-disable-next-line typescript/no-deprecated
[attributes.NET_PEER_NAME]: collection.conn.host,
// oxlint-disable-next-line typescript/no-deprecated
[attributes.NET_PEER_PORT]: collection.conn.port
};
}
function setErrorStatus(span, error) {
span.setStatus({
code: core.SPAN_STATUS_ERROR,
message: `${error.message} ${error.code ? `
Mongoose Error Code: ${error.code}` : ""}`
});
}
function handlePromiseResponse(execResponse, span) {
if (!(execResponse instanceof Promise)) {
span.end();
return execResponse;
}
return execResponse.catch((err) => {
setErrorStatus(span, err);
throw err;
}).finally(() => span.end());
}
function handleCallbackResponse(callback, exec, originalThis, span, args) {
let callbackArgumentIndex = 0;
if (args.length === 2) {
callbackArgumentIndex = 1;
} else if (args.length === 3) {
callbackArgumentIndex = 2;
}
args[callbackArgumentIndex] = (err, response) => {
if (err) {
setErrorStatus(span, err);
}
span.end();
return callback(err, response);
};
return exec.apply(originalThis, args);
}
exports.getAttributesFromCollection = getAttributesFromCollection;
exports.handleCallbackResponse = handleCallbackResponse;
exports.handlePromiseResponse = handlePromiseResponse;
//# sourceMappingURL=utils.js.map