0.2.26 • Published 3 years ago

data-tracer v0.2.26

Weekly downloads
8
License
ISC
Repository
github
Last release
3 years ago

Data Tracer

N|Solid

Installation

$ npm i data-tracer
Import
import { Audit, DataTracer } from 'data-tracer';
Instantiate Tracer

Mongoose

Audit.addTracer('mongoose', { connectionString: 'mongodb://localhost:27017/db', appName: 'Apple-Rest' });

Mongo Aggregation Query

import { Audit } from 'data-tracer';


app.get('/audits', async (req: any, res: any) => {
      let query: any = req.query;
      if (query['page'] == undefined) query['page'] = 1;
      if (query['limit'] == undefined) query['limit'] = 10;
      let q: any =
        query['q'] == undefined
          ? [{}]
          : [
            { when: { $regex: `${query['q']}`, $options: 'i' } },
            { what: { $regex: `${query['q']}`, $options: 'i' } },
            { type: { $regex: `${query['q']}`, $options: 'i' } },
            { where: { $regex: `${query['q']}`, $options: 'i' } },
            { why: { $regex: `${query['q']}`, $options: 'i' } },
          ];
      return Audit.aggregate([
        {
          $facet: {
            audits: [
              {
                $match: {
                  type: { $in: JSON.parse(query['type']) },
                  createdAt: {
                    $gte: new Date(query['startDate']),
                    $lte: new Date(query['endDate']),
                  },
                  $or: JSON.parse(JSON.stringify(q)),
                },
              },
              { $limit: parseInt(query['limit']) },
              { $skip: (query['page'] - 1) * query['limit'] },
            ],
            apps: [
              {
                $group: {
                  _id: null,
                  apps: { $addToSet: "$appName" }
                }
              }, { "$unset": ["_id"] }
            ]
          },
        },
      ]).then((result: any) => res.json({ data: result }));
    });

MySQL

Audit.addTracer('mysql', { host: 'localhost', user: 'root', 'password': 'root', database: 'myDB' });
Instantiate Mail Alerts (Optional)
DataTracer.configureAlert({
    'apiKey': 'abcdefghijklmnopqrstuvwxyz',
    'provider': 'sendgrid',
    'subject': `Error from ${APP_NAME}`,
    'from': 'achu10@live.in',
    'mailTo': 'achu10@live.in',
    'type': ['SEVERE']  // Severity types to trigger email
});
Sample usage
Definition
    Audit.logEvent(
        type,
        what,
        subject,
        status,
        who,
        where,
        why,
        is,
        meta
    );
Example
    Audit.logEvent(
        'INFO',
        'Ping',
        'api was triggered',
        'Successful',
        undefined,
        'app.js',
        'to Check Server status',
        'Event',
        {
            'key1': value,
            'key2': [
                {
                  'key21': 'value21'
                }
            ]
        }
    )

Examples

Screenshot

N|Solid

Roadmap WIP

  • Local file logging
  • Dashboard UI
  • QL for filtering Audit Events, Logs
  • Plugins like console, authorization etc.
  • ELK Integration
  • Monitoring
  • Tracing
  • etc...
0.2.26

3 years ago

0.2.25

4 years ago

0.2.24

4 years ago

0.2.23

4 years ago

0.2.22

4 years ago

0.2.21

4 years ago

0.2.20

4 years ago

0.2.19

4 years ago

0.2.18

4 years ago

0.2.17

4 years ago

0.2.16

4 years ago

0.2.15

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.1.0

4 years ago

0.2.0

4 years ago

0.0.24

4 years ago

0.0.25

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.17

4 years ago

0.0.18

4 years ago

0.0.15

4 years ago

0.0.16

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago