Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS X-ray import with Typescript

I currently use postgresql-node in my lambda with

import { Client } from 'pg'

I want to instrument the Postgresql lib with AWS X-ray. The Nodejs example has this line:

var AWSXRay = require('aws-xray-sdk');
var pg = AWSXRay.capturePostgres(require('pg'));

How would I convert the second line in that to proper Typescript. All the variations I come up with produce some errors or warnings. For example I would guess this would work:

const pg = AWSXRay.capturePostgres(require('pg'))

but not only you get ESlint warning for require being used without import but after that pg.Client says pg namespace not found.

like image 880
vertti Avatar asked Oct 17 '25 13:10

vertti


1 Answers

Well, it's slightly ugly but this seems to work:

import * as pg from 'pg'
const patchedPg = AWSXRay.capturePostgres(pg)
like image 114
vertti Avatar answered Oct 20 '25 04:10

vertti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!