@intlgadmin/skywalking-nodejs-prisma-plugin
v1.0.0
Published
This plugin relies on skywalking nodejs agent. As a supplement to skywalking nodejs agent, it adds the detection of PRISMA accessing the database.
Downloads
21
Readme
Prisma plugin of SkyWalking NodeJS Agent
This plugin relies on skywalking nodejs agent. As a supplement to skywalking nodejs agent, it adds the detection of PRISMA accessing the database.
Install SkyWalking NodeJS package from npmjs
$ npm install --save @tencent/skywalking-nodejs-prisma-pluginSet up Plugin
Like SkyWalking NodeJS SDK , this plugin requires SkyWalking backend (OAP) 8.0+ and NodeJS >= 10.
import prismaPlugin from '@tencent/skywalking-nodejs-prisma-plugin';
// or
const { default: prismaPlugin } = require('@tencent/skywalking-nodejs-prisma-plugin');
// SkyWalking NodeJS Agent start(),
prismaPlugin.install({
prisma, // PrismaClient instance
databaseInfo: {
dbType: 'Mysql',
peer: 'ip:3306',
dbName: 'db_name',
},
});For example:
const { default : axios } = require('axios');
const Koa = require('koa');
const app = new Koa();
const { default: agent } = require('skywalking-backend-js');
const { PrismaClient } = require('@prisma/client');
const { default: prismaPlugin } = require('@tencent/skywalking-nodejs-prisma-plugin');
const prisma = new PrismaClient();
agent.start({
serviceName: 'my-service-name',
serviceInstance: 'my-service-instance-name',
collectorAddress: '127.0.0.1:11800',
});
prismaPlugin.install({
prisma,
databaseInfo: {
dbType: 'Mysql',
peer: 'ip:3306',
dbName: 'db_name',
}
});
// logger
app.use(async (ctx, next) => {
await next();
const rt = ctx.response.get('X-Response-Time');
console.log(`${ctx.method} ${ctx.url} - ${rt}`);
});
// x-response-time
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
ctx.set('X-Response-Time', `${ms}ms`);
});
// response
app.use(async ctx => {
const table1 = await prisma.table1.findMany();
console.log('share:',allShare);
let httpContent = await axios.get('http://www.baidu.com');
console.log('httpContent:', httpContent.data.length);
const table2 = await prisma.table2.findMany();
console.log('appointment:', appointment);
httpContent = await axios.get('http://127.0.0.1:10000/');
console.log('httpContent:', httpContent.data.length);
ctx.body = 'OK.';
});
app.listen(3000,'::');