JSPM

  • Created
  • Published
  • Downloads 375744
  • Score
    100M100P100Q191866F
  • License Apache-2.0

AWS X-Ray Patcher for Postgres (Javascript)

Package Exports

  • aws-xray-sdk-postgres

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (aws-xray-sdk-postgres) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Requirements

AWS X-Ray SDK Core Postgres 6.1.0 or greater

AWS X-Ray and Postgres

AWS X-Ray Postgres package automatically records query information, request and response data. Simply patch the Postgres package via 'capturePostgres' as seen below.

The AWS X-Ray SDK Core has two modes - 'manual' and 'automatic'. Automatic mode uses the Continuation Local Storage package (CLS) and automatically keeps track of the current segment and subsegment. This is the default mode. Manual mode requires you pass around the segment reference. See examples below.

environment variables

POSTGRES_DATABASE_VERSION        Sets additional data for the sql subsegment.
POSTGRES_DRIVER_VERSION          Sets additional data for the sql subsegment.

Automatic mode example

var AWSXRay = require('aws-xray-sdk-core');
var capturePostgres = require('aws-xray-sdk-postgres');

var pg = capturePostgres(require('pg'));

...

var client = new pg.Client();

client.connect(function (err) {
  ...

  client.query({name: 'moop', text: 'SELECT $1::text as name'}, ['brianc'], function (err, result) {
    //automatically captures query information and error (if any)
  });
});

...

var pool = new pg.Pool(config);
pool.connect(function(err, client, done) {
  if(err) {
    return console.error('error fetching client from pool', err);
  }
  var query = client.query('SELECT * FROM mytable', function(err, result) {
    //automatically captures query information and error (if any)
  });
});

Manual mode example

var AWSXRay = require('aws-xray-sdk-core');
var capturePostgres = require('aws-xray-sdk-postgres');

var pg = capturePostgres(require('pg'));

...

var client = new pg.Client();

client.connect(function (err) {
  ...

  client.query({name: 'moop', text: 'SELECT $1::text as name'}, ['mcmuls'], function (err, result) {
    //automatically captures query information and error (if any)
  });
});

...

var pool = new pg.Pool(config);
pool.connect(function(err, client, done) {
  if(err) {
    return console.error('error fetching client from pool', err);
  }
  var query = client.query('SELECT * FROM mytable', function(err, result) {
    //automatically captures query information and error (if any)
  }, segment));
};