@sentry/tracing
Advanced tools
Comparing version 7.24.0 to 7.24.1
@@ -81,2 +81,6 @@ var { | ||
function isCursor(maybeCursor) { | ||
return maybeCursor && typeof maybeCursor === 'object' && maybeCursor.once && typeof maybeCursor.once === 'function'; | ||
} | ||
/** Tracing integration for mongo package */ | ||
@@ -148,18 +152,36 @@ class Mongo { | ||
const span = _optionalChain([parentSpan, 'optionalAccess', _4 => _4.startChild, 'call', _5 => _5(getSpanContext(this, operation, args))]); | ||
const maybePromise = orig.call(this, ...args) ; | ||
const maybePromiseOrCursor = orig.call(this, ...args); | ||
if (utils.isThenable(maybePromise)) { | ||
return maybePromise.then((res) => { | ||
if (utils.isThenable(maybePromiseOrCursor)) { | ||
return maybePromiseOrCursor.then((res) => { | ||
_optionalChain([span, 'optionalAccess', _6 => _6.finish, 'call', _7 => _7()]); | ||
return res; | ||
}); | ||
} | ||
// If the operation returns a Cursor | ||
// we need to attach a listener to it to finish the span when the cursor is closed. | ||
else if (isCursor(maybePromiseOrCursor)) { | ||
const cursor = maybePromiseOrCursor ; | ||
try { | ||
cursor.once('close', () => { | ||
_optionalChain([span, 'optionalAccess', _8 => _8.finish, 'call', _9 => _9()]); | ||
}); | ||
} catch (e) { | ||
// If the cursor is already closed, `once` will throw an error. In that case, we can | ||
// finish the span immediately. | ||
_optionalChain([span, 'optionalAccess', _10 => _10.finish, 'call', _11 => _11()]); | ||
} | ||
return cursor; | ||
} else { | ||
_optionalChain([span, 'optionalAccess', _8 => _8.finish, 'call', _9 => _9()]); | ||
return maybePromise; | ||
_optionalChain([span, 'optionalAccess', _12 => _12.finish, 'call', _13 => _13()]); | ||
return maybePromiseOrCursor; | ||
} | ||
} | ||
const span = _optionalChain([parentSpan, 'optionalAccess', _10 => _10.startChild, 'call', _11 => _11(getSpanContext(this, operation, args.slice(0, -1)))]); | ||
const span = _optionalChain([parentSpan, 'optionalAccess', _14 => _14.startChild, 'call', _15 => _15(getSpanContext(this, operation, args.slice(0, -1)))]); | ||
return orig.call(this, ...args.slice(0, -1), function (err, result) { | ||
_optionalChain([span, 'optionalAccess', _12 => _12.finish, 'call', _13 => _13()]); | ||
_optionalChain([span, 'optionalAccess', _16 => _16.finish, 'call', _17 => _17()]); | ||
lastArg(err, result); | ||
@@ -166,0 +188,0 @@ }); |
@@ -76,2 +76,6 @@ import { _optionalChain } from '@sentry/utils/esm/buildPolyfills'; | ||
function isCursor(maybeCursor) { | ||
return maybeCursor && typeof maybeCursor === 'object' && maybeCursor.once && typeof maybeCursor.once === 'function'; | ||
} | ||
/** Tracing integration for mongo package */ | ||
@@ -143,18 +147,36 @@ class Mongo { | ||
const span = _optionalChain([parentSpan, 'optionalAccess', _4 => _4.startChild, 'call', _5 => _5(getSpanContext(this, operation, args))]); | ||
const maybePromise = orig.call(this, ...args) ; | ||
const maybePromiseOrCursor = orig.call(this, ...args); | ||
if (isThenable(maybePromise)) { | ||
return maybePromise.then((res) => { | ||
if (isThenable(maybePromiseOrCursor)) { | ||
return maybePromiseOrCursor.then((res) => { | ||
_optionalChain([span, 'optionalAccess', _6 => _6.finish, 'call', _7 => _7()]); | ||
return res; | ||
}); | ||
} | ||
// If the operation returns a Cursor | ||
// we need to attach a listener to it to finish the span when the cursor is closed. | ||
else if (isCursor(maybePromiseOrCursor)) { | ||
const cursor = maybePromiseOrCursor ; | ||
try { | ||
cursor.once('close', () => { | ||
_optionalChain([span, 'optionalAccess', _8 => _8.finish, 'call', _9 => _9()]); | ||
}); | ||
} catch (e) { | ||
// If the cursor is already closed, `once` will throw an error. In that case, we can | ||
// finish the span immediately. | ||
_optionalChain([span, 'optionalAccess', _10 => _10.finish, 'call', _11 => _11()]); | ||
} | ||
return cursor; | ||
} else { | ||
_optionalChain([span, 'optionalAccess', _8 => _8.finish, 'call', _9 => _9()]); | ||
return maybePromise; | ||
_optionalChain([span, 'optionalAccess', _12 => _12.finish, 'call', _13 => _13()]); | ||
return maybePromiseOrCursor; | ||
} | ||
} | ||
const span = _optionalChain([parentSpan, 'optionalAccess', _10 => _10.startChild, 'call', _11 => _11(getSpanContext(this, operation, args.slice(0, -1)))]); | ||
const span = _optionalChain([parentSpan, 'optionalAccess', _14 => _14.startChild, 'call', _15 => _15(getSpanContext(this, operation, args.slice(0, -1)))]); | ||
return orig.call(this, ...args.slice(0, -1), function (err, result) { | ||
_optionalChain([span, 'optionalAccess', _12 => _12.finish, 'call', _13 => _13()]); | ||
_optionalChain([span, 'optionalAccess', _16 => _16.finish, 'call', _17 => _17()]); | ||
lastArg(err, result); | ||
@@ -161,0 +183,0 @@ }); |
{ | ||
"name": "@sentry/tracing", | ||
"version": "7.24.0", | ||
"version": "7.24.1", | ||
"description": "Extensions for Sentry AM", | ||
@@ -19,9 +19,9 @@ "repository": "git://github.com/getsentry/sentry-javascript.git", | ||
"dependencies": { | ||
"@sentry/core": "7.24.0", | ||
"@sentry/types": "7.24.0", | ||
"@sentry/utils": "7.24.0", | ||
"@sentry/core": "7.24.1", | ||
"@sentry/types": "7.24.1", | ||
"@sentry/utils": "7.24.1", | ||
"tslib": "^1.9.3" | ||
}, | ||
"devDependencies": { | ||
"@sentry/browser": "7.24.0", | ||
"@sentry/browser": "7.24.1", | ||
"@types/express": "^4.17.14" | ||
@@ -28,0 +28,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1239407
8414
+ Added@sentry/core@7.24.1(transitive)
+ Added@sentry/types@7.24.1(transitive)
+ Added@sentry/utils@7.24.1(transitive)
- Removed@sentry/core@7.24.0(transitive)
- Removed@sentry/types@7.24.0(transitive)
- Removed@sentry/utils@7.24.0(transitive)
Updated@sentry/core@7.24.1
Updated@sentry/types@7.24.1
Updated@sentry/utils@7.24.1