Skip to content

Commit

Permalink
fix: Correctly handle pg.Cursor in pg query method (#3567)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed May 19, 2021
1 parent 95fe018 commit c3b1bb5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/tracing/src/integrations/postgres.ts
Original file line number Diff line number Diff 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 Down Expand 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

0 comments on commit c3b1bb5

Please sign in to comment.