Skip to content

feat: MySQL Tracing Support - #3088

Merged
HazAT merged 6 commits into
masterfrom
node-mysql
Dec 4, 2020
Merged

feat: MySQL Tracing Support#3088
HazAT merged 6 commits into
masterfrom
node-mysql

Conversation

@kamilogorek

@kamilogorekkamilogorek commented Dec 1, 2020

Copy link
Copy Markdown
Contributor

MySQL and MariaDB tracing support.

Usage:

constSentry=require("@sentry/node");constTracing=require("@sentry/tracing");constmysql=require("mysql");Sentry.init({dsn: "__PUBLIC_DSN__",integrations: [newTracing.Integrations.Mysql(),],tracesSampleRate: 1.0,});constconnection=mysql.createConnection({user: "root",password: "docker",});connection.connect(function(err){if(err){console.error("error connecting: "+err.stack);return;}console.log("connected as id "+connection.threadId);});// the rest of the code, for raw-node code we need manual instrumentation, eg.consttransaction=Sentry.startTransaction({op: "transaction",name: "My Transaction",});Sentry.configureScope((scope)=>{scope.setSpan(transaction);});connection.query("SELECT 1 + 1 AS solution",function(error,results,fields){console.log(err ? err.stack : results[0].solution);// 2if(transaction)transaction.finish();connection.end();});

Works nicely with Express too:

constSentry=require("@sentry/node");constTracing=require("@sentry/tracing");constmysql=require("mysql");constexpress=require("express");Sentry.init({dsn: "__PUBLIC_DSN__",integrations: [newSentry.Integrations.Http({tracing: true}),newTracing.Integrations.Express({app: express.Router,methods: ["get"],}),newTracing.Integrations.Mysql(),],tracesSampleRate: 1.0,});constapp=express();constconnection=mysql.createConnection({user: "root",password: "docker",});connection.connect();app.use(Sentry.Handlers.requestHandler());app.use(Sentry.Handlers.tracingHandler());app.use(express.json());app.get("/hi",functionsayHi(req,res){connection.query("SELECT 1 + 1 AS solution",function(error,results,fields){res.send(results[0].solution);});});app.use(Sentry.Handlers.errorHandler());app.listen(3000);

@kamilogorek
kamilogorek requested a review from a teamDecember 1, 2020 13:51
@kamilogorek
kamilogorekforce-pushed the node-mysql branch 3 times, most recently from 1deded0 to 0fe030bCompareDecember 1, 2020 14:01
@github-actions

github-actionsBot commented Dec 1, 2020

Copy link
Copy Markdown
Contributor

size-limit report

PathSize
@sentry/browser - CDN Bundle (gzipped)19.73 KB (-0.01% 🔽)
@sentry/browser - Webpack20.6 KB (0%)
@sentry/react - Webpack20.6 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped)26.88 KB (-0.01% 🔽)

@lobsterkatielobsterkatie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One small nit, but otherwise LGTM!

P.S. Any possibility of adding some tests?

Comment threadpackages/tracing/src/integrations/mysql.ts Outdated
Comment threadpackages/tracing/src/integrations/mysql.ts Outdated
@HazAT
HazAT merged commit a1934b4 into masterDec 4, 2020
@HazAT
HazAT deleted the node-mysql branch December 4, 2020 11:41
Sign up for freeto 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.

3 participants

@kamilogorek@lobsterkatie@HazAT