Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions packages/tracing/src/integrations/postgres.ts
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import { Hub } from '@sentry/hub';
import { EventProcessor, Integration } from '@sentry/types';
import { fill, loadModule, logger } from '@sentry/utils';
import { fill, isThenable, loadModule, logger } from '@sentry/utils';

interface PgClient {
prototype: {
Expand DownExpand Up@@ -36,6 +36,7 @@ export class Postgres implements Integration {
* function (query, params, callback) => void
* function (query) => Promise
* function (query, params) => Promise
* function (pg.Cursor) => pg.Cursor
*/
fill(pkg.Client.prototype, 'query', function(orig: () => void | Promise<unknown>) {
return function(this: unknown, config: unknown, values: unknown, callback: unknown) {
Expand All@@ -60,10 +61,17 @@ export class Postgres implements Integration {
});
}

return (orig.call(this, config, values) as Promise<unknown>).then((res: unknown) => {
span?.finish();
return res;
});
const rv = typeof values !== 'undefined' ? orig.call(this, config, values) : orig.call(this, config);

if (isThenable(rv)) {
return (rv as Promise<unknown>).then((res: unknown) => {
span?.finish();
return res;
});
}

span?.finish();
return rv;
};
});
}
Expand Down