• The application is intended to log certain transactions in the mongodb database, each transaction has a name, status and a trace(optional), a trace has a name, status, body(json). • Each time your code runs and has the "transaction.start" method, a new transaction will be created • When using one of the methods that will update the transaction, only the most current transaction will be changed. • The transaction has five methods: - start: creates a transaction (with pending status) - alert: sets the status to alert - rejected: sets the status to rejected - error: sets the status to error - success: sets the status to success - trace: create a trace
npm i trace-prisma
To start using the project, let's configure the .env, in it an environment variable called "DATABASE_URL", which must be configured with your connection string from your mongodb.
Exemple:
mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
Is necessary to call the function below, it will execute the command "npx prisma generate", in schema.prisma located inside the project
const { generateSchema } = require('trace-prisma/generate_schema')
generateSchema()
Now let's create our transactions and traces, to create a transaction it is not mandatory to have a job_id
const { Transection } = require('trace-prisma')
const transaction = new Transection('646faf02b716b92a81bfc181') //Job id
async function test() {
await transaction.start('Transaction_name')
await transaction.trace('Transaction_name', {body: {name: 'Jhon', age: 20}}, 'success', 'traceName')
if (true){
await transaction.success('Transaction_name')
}
}
test()