Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: PostgreSQL Tracing Support #3064

Merged
merged 4 commits into from
Dec 4, 2020
Merged

feat: PostgreSQL Tracing Support #3064

merged 4 commits into from
Dec 4, 2020

Conversation

kamilogorek
Copy link
Contributor

@kamilogorek kamilogorek commented Nov 19, 2020

PostgreSQL and CockroachDB tracing support.

Usage:

const Sentry = require("@sentry/node");
const Tracing = require("@sentry/tracing");
const pg = require("pg");

Sentry.init({
  dsn: "__PUBLIC_DSN__",
  integrations: [
    new Tracing.Integrations.Postgres(),
  ],
  tracesSampleRate: 1.0,
});

const client = new pg.Client({
  user: "postgres",
  password: "docker",
});

client.connect();

// the rest of the code, for raw-node code we need manual instrumentation, eg.

const transaction = Sentry.startTransaction({
  op: "transaction",
  name: "My Transaction",
});

Sentry.configureScope((scope) => {
  scope.setSpan(transaction);
});

client.query("SELECT $1::text as message", ["Hello world!"], (err, res) => {
  console.log(err ? err.stack : res.rows[0].message); // Hello World!
  if (transaction) transaction.finish();
  client.end();
});

Works nicely with Express too:

const Sentry = require("@sentry/node");
const Tracing = require("@sentry/tracing");
const pg = require("pg");
const express = require("express");

Sentry.init({
  dsn: "__PUBLIC_DSN__",
  integrations: [
    new Sentry.Integrations.Http({ tracing: true }),
    new Tracing.Integrations.Express({
      app: express.Router,
      methods: ["get"],
    }),
    new Tracing.Integrations.Postgres(),
  ],
});

const app = express();
const client = new pg.Client({
  user: "postgres",
  password: "docker",
});

client.connect();

app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());
app.use(express.json());

app.get("/hi", function sayHi(req, res) {
  client.query("SELECT $1::text as name", ["picklerick"], (err, rows) => {
    res.send(rows[0]);
  });
});

app.use(Sentry.Handlers.errorHandler());

app.listen(3000);

@kamilogorek kamilogorek requested a review from a team November 19, 2020 15:17
@github-actions
Copy link
Contributor

github-actions bot commented Nov 19, 2020

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 19.73 KB (+0.01% 🔺)
@sentry/browser - Webpack 20.6 KB (0%)
@sentry/react - Webpack 20.6 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 26.88 KB (+0.01% 🔺)

@kamilogorek
Copy link
Contributor Author

Thanks @lobsterkatie, will make appropriate changes once I finish Mongo work.

@kamilogorek kamilogorek changed the title node-postgres tracing integration feat: PostgreSQL Tracing Support Nov 24, 2020
@ghost
Copy link

ghost commented Nov 25, 2020

Is there a timeline for when this will be merged and released? The Express fix in here would be really nice to have given it is causing a lot of duplicates in our issues page.

@kamilogorek
Copy link
Contributor Author

@dlaudate-embark I'll extract it from the PR today so we can ship it tomorrow/monday

@kamilogorek
Copy link
Contributor Author

@dlaudate-embark ref: #3078

Copy link
Member

@lobsterkatie lobsterkatie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Maybe some tests, though?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants