GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing google.github.io — sqlcommenter Sequelize.js
IntroductionThis package is in the form of Besides plain sequelize.js wrapping, we also provide a wrapper for the following frameworks: RequirementsInstallationWe can add integration into our applications in the following ways: ManuallyPlease read installing sqlcommenter-nodejs from source Package managerAdd to your package.json the dependency and then run UsagePlain sequelize wrapperExpress middlewareThis wrapper/middleware can be used as is or better with express.js FieldsIn the database server logs, the comment’s fields are:
OptionsWhen creating the middleware, one can optionally configure the injected
comments by passing in the
|
| Field | On by default |
|---|---|
| client_timezone | ❌
|
| db_driver | ❌
|
| route | ✔
|
| traceparent | ❌
|
| tracestate | ❌
|
options configA configuration object specifying where to collect trace data from. Accepted
fields are: TraceProvider: Should be OpenTelemetry,
indicating which library to collect trace context from.
| Field | Possible values |
|---|---|
| TraceProvider | OpenTelemetry |
wrapMainSequelizeAsMiddleware(
Sequelize,
include={ traceparent: true, tracestate: true },
options={ TraceProvider: 'OpenTelemetry' }
);
wrapMainSequelizeAsMiddleware(Sequelize, include={client_timezone: true});
wrapMainSequelizeAsMiddleware(Sequelize, include={route: true});
wrapMainSequelizeAsMiddleware(Sequelize, include={db_driver: true});
// Manually set all the variables.
wrapMainSequelizeAsMiddleware(
Sequelize,
include={
client_timezone: true,
db_driver: true,
route: true,
traceparent: true,
tracestate: true,
},
options={ TraceProvider: 'OpenTelemetry' }
);
Check out a full express + opentelemetry example here.
// In file app.js.
const { NodeTracerProvider } = require("@opentelemetry/node");
const { BatchSpanProcessor } = require("@opentelemetry/tracing");
const {
TraceExporter,
} = require("@google-cloud/opentelemetry-cloud-trace-exporter");
const tracerProvider = new NodeTracerProvider();
// Export to Google Cloud Trace
tracerProvider.addSpanProcessor(
new BatchSpanProcessor(new TraceExporter({ logger }), {
bufferSize: 500,
bufferTimeout: 5 * 1000,
})
);
tracerProvider.register();
// OpenTelemetry initialization should happen before importing any libraries
// that it instruments
const { Sequelize } = require("sequelize");
const {
wrapSequelizeAsMiddleware,
} = require("@google-cloud/sqlcommenter-sequelize");
const sequelize = new Sequelize("postgres://user:[email protected]:5432/dbname");
const express = require("express");
const app = express();
const port = process.env.APP_PORT || 3000;
// SQLCommenter express middleware injects the route into the traces
app.use(
wrapSequelizeAsMiddleware(
sequelize,
{
client_timezone: false,
db_driver: false,
route: true,
traceparent: true,
tracestate: true,
},
{ TraceProvider: "OpenTelemetry" }
)
);
app.get("/", (req, res) => res.send("Hello, sqlcommenter-nodejs!!"));
app.get("^/polls/:param", function (req, res) {
sequelize
.query("SELECT * from polls_question")
.then(function (polls) {
const blob = JSON.stringify(polls);
res.send(blob);
})
.catch(function (err) {
console.log(err);
res.send(500);
});
});
app.listen(port, () => console.log(`Application listening on ${port}`));
// In file app.js.
const Sequelize = require('sequelize');
const {wrapSequelizeAsMiddleware} = require('@google-cloud/sqlcommenter-sequelize');
const express = require('express');
// Using a connection URI
const sequelize = new Sequelize('postgres://user:[email protected]:5432/dbname');
const app = express();
const port = process.env.APP_PORT || 3000;
// Use the sequelize+express middleware with route
app.use(wrapSequelizeAsMiddleware(sequelize, {route: true}));
app.get('/', (req, res) => res.send('Hello, sqlcommenter-nodejs!!'));
app.get('^/polls/:param', function(req, res) {
sequelize.query('SELECT * from polls_question').then(function(polls) {
const blob = JSON.stringify(polls);
res.send(blob);
}).catch(function(err) {
console.log(err);
res.send(500);
});
});
app.listen(port, () => console.log(`Application listening on ${port}`));
// In file app.js
const Sequelize = require('sequelize');
const {wrapSequelizeAsMiddleware} = require('@google-cloud/sqlcommenter-sequelize');
const express = require('express');
// Using a connection URI
const sequelize = new Sequelize('postgres://user:[email protected]:5432/dbname');
const app = express();
const port = process.env.APP_PORT || 3000;
// Use the sequelize+express middleware with db driver and timezone
app.use(wrapSequelizeAsMiddleware(sequelize, {
db_driver: true,
client_timezone: true
}));
app.get('/', (req, res) => res.send('Hello, sqlcommenter-nodejs!!'));
app.get('^/polls/:param', function(req, res) {
sequelize.query('SELECT * from polls_question').then(function(polls) {
const blob = JSON.stringify(polls);
res.send(blob);
}).catch(function(err) {
console.log(err);
res.send(500);
});
});
app.listen(port, () => console.log(`Application listening on ${port}`));
// In file app.js.
const { NodeTracerProvider } = require("@opentelemetry/node");
const { BatchSpanProcessor } = require("@opentelemetry/tracing");
const {
TraceExporter,
} = require("@google-cloud/opentelemetry-cloud-trace-exporter");
const tracerProvider = new NodeTracerProvider();
// Export to Google Cloud Trace
tracerProvider.addSpanProcessor(
new BatchSpanProcessor(new TraceExporter({ logger }), {
bufferSize: 500,
bufferTimeout: 5 * 1000,
})
);
tracerProvider.register();
// OpenTelemetry initialization should happen before importing any libraries
// that it instruments
const { Sequelize } = require("sequelize");
const {
wrapSequelizeAsMiddleware,
} = require("@google-cloud/sqlcommenter-sequelize");
const sequelize = new Sequelize("postgres://user:[email protected]:5432/dbname");
const express = require("express");
const app = express();
const port = process.env.APP_PORT || 3000;
// SQLCommenter express middleware injects the route into the traces
app.use(
wrapSequelizeAsMiddleware(
sequelize,
{
client_timezone: true,
db_driver: true,
route: true,
traceparent: true,
tracestate: true,
},
{ TraceProvider: "OpenTelemetry" }
)
);
app.get("/", (req, res) => res.send("Hello, sqlcommenter-nodejs!!"));
app.get("^/polls/:param", function (req, res) {
sequelize
.query("SELECT * from polls_question")
.then(function (polls) {
const blob = JSON.stringify(polls);
res.send(blob);
})
.catch(function (err) {
console.log(err);
res.send(500);
});
});
app.listen(port, () => console.log(`Application listening on ${port}`));
which after running by
$ node app.js
Application listening on 3000
On making a request to that server at http://localhost:3000/polls/1000, the PostgreSQL logs show:
2019-06-03 14:32:10.842 PDT [32004] LOG: statement: SELECT * from polls_question
/*traceparent='00-11000000000000ff-020000ee-01',tracestate='brazzaville=t61rcWkgMzE,rondo=00f067aa0ba902b7'*/2019-06-03 14:32:10.842 PDT [32004] LOG: statement: SELECT * from polls_question
/*route='%5E%2Fpolls%2F%1000'*/2019-06-03 14:32:10.842 PDT [32004] LOG: statement: SELECT * from polls_question
/*client_timezone:'%2B00%3A00',db_driver='sequelize%3A0.0.1'*/2019-06-03 14:32:10.842 PDT [32004] LOG: statement: SELECT * from polls_question
/*client_timezone:'%2B00%3A00',db_driver='sequelize%3A0.0.1',route='%5E%2Fpolls%2F%1000',traceparent='00-11000000000000ff-020000ee-01',tracestate='brazzaville=t61rcWkgMzE,rondo=00f067aa0ba902b7'*/| Resource | URL |
|---|---|
| @google-cloud/sqlcommenter-sequelize on npm | https://www.npmjs.com/package/@google-cloud/sqlcommenter-sequelize |
| express.js | https://expressjs.com/ |