1.2.0 ā€¢ Published 3 years ago

error-issue-tracker-sdk v1.2.0

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
3 years ago

A simple, flexible, light sdk to track any kind of errors and create automatic issue if found new.

Demo

Take a look to the demo šŸ‘‰šŸ‘‰ HERE šŸ‘ˆšŸ‘ˆ

There are many ways to use this sdk:

  • Use it as a webhook for your data collection in order to create issue for new alerts. For example, from ElasticSearch alert action.
  • Use it to search similar issues from a text input
  • etc.

Install

yarn add -D error-issue-tracker-sdk

Usage

import { trackErrors } from 'error-issue-tracker-sdk'
// --- your issue client
class MyIssueClient {
  async createIssue(error) {
    // here you can create the issue related to an untracked error
    return {
      id: 'newIdIssue',
      url: 'http://issue-client/newIdIssue',
      body: `Found ${error.newOccurrences.length} occurences of "${error.name}"`,
    }
  }
  async updateIssue(error) {
    // here you can update the issue for example add a new comment for new occurences
    const comments = [
      ...error.issue.comments,
      `Found new ${error.newOccurrences.length} occurences of ${error.name}`,
    ]
    return { ...error.issue, comments }
  }
}
// --- your database provider
class MyDatabase {
  constructor() {
    this.store = {}
  }
  async save(error) {
    // here you save the error in a store
    this.store[error.projectId] = this.store[error.projectId] || []
    const savedError = {
      id: this.store[error.projectId].length.toString(),
      ...error,
    }
    this.store[error.projectId].push(savedError)
    return savedError
  }
  async fetch(projectId) {
    // here you can update the issue for example add a new comment for new occurences
    return this.store[projectId] || []
  }
}
// Your custom comparator
const compareError = (a, b) =>
  a.message.toLowerCase().localeCompare(b.message.toLowerCase())
// use it
const errors = [
  { message: 'Error when create the checkout', timestamp: 1 },
  { message: 'Error When Create The Checkout', timestamp: 2 },
  { message: 'Null Pointer Exception on payment page', timestamp: 3 },
  { message: 'cannot call login on undefined', timestamp: 4 },
  { message: 'Null Pointer Exception on payment page', timestamp: 5 },
]
src_1
  .trackErrors(errors, {
    issueClient: new MyIssueClient(),
    database: new MyDatabase(),
    compareError,
    projectId: 'MyApplication',
  })
  .then((trackedErrors) => console.log(trackedErrors))
// should return
// - "Error when create the checkout" (occurrences : 2)
// - "Null Pointer Exception on payment page" (occurrences : 2)
// - "cannot call login on undefined" (occurences : 1)

Usage in Typescript

Take a look to the typescript version

Author

šŸ‘¤ Ludovic Dorival

Show your support

Give a ā­ļø if this project helped you!

šŸ“ License

Copyright Ā© 2021 Ludovic Dorival. This project is BSD--3--Clause licensed.

Contributing

We welcome community contributions and pull requests. See CONTRIBUTING.md for information on how to set up a development environment and submit code.

This README was generated with ā¤ļø by readme-md-generator

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago