Transaction Log Custom Graph Template
  • 23 Aug 2024
  • 2 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Transaction Log Custom Graph Template

  • Dark
    Light
  • PDF

Article summary

We have included an Interactive Training to provide a more engaging and visual learning experience. End users are required to complete their training through the CSG University.


Transaction Logging is a useful practice for monitoring, auditing, and debugging transactions in Xponent. Each transaction in a graph is recorded with start and end time stamps, input/ output schema values, success state, and graph name.

Not every situation calls for transaction logging. If speed is an issue or data persistence is not a problem (i.e. you can afford to ignore failed records) then you may decide not to include transaction logging. Xponent recommends transaction logging during development as it speeds up debugging and QA. It is also useful for production systems where you can diagnose the end state of transactions that failed. An alternative approach is to write all failed transactions to an error queue rather than a database.

Package contents

  • Graphs: 
  • initiateTxn
  • finalisetxn
  • Transaction Log (example graph)
  • Nodes: 
  • DB Insert, Update
  • Script: 
  • createGuid - creates a globally unique identifier used as transactionId
  • getCurrentTime - creates a timestamp for database insert
  • Schema: transaction:{}

Setup 

  • Create a database table called txnLog like this (MySQL - with MySQL 5.7 you can use json field types for inputMsg/outputMsg - this is not supported in the Xponent Aurora DB):
CREATE TABLE transactionLog (
  transactionId varchar(50) NOT NULL PRIMARY KEY,
  tsStart datetime(3) not null,
  tsEnd datetime(3) null,
  graphName varchar(50) not null,
  inputMsg text,
  outputMsg text,
  statusCode varchar(200) not null,
  errorCode varchar(5) not null,
  UNIQUE KEY transactionId_UNIQUE (transactionId)
);
  • Create a database connection to the database containing the transactionLog table
  • Deploy the Transaction Log graph template

  • Set the initiate and finalize transaction sub-graph nodes typically on the top-level graph that you want to log. There is an example graph included in the graph template.

Using  

The graph above is included as an example in the graph template. It can be used to test the initial setup and then deleted. 

  1. Deploy the Transaction Log template to create all the necessary objects.
  2. Place the initiateTxn subgraph node as close to the beginning of the top-level graph as possible
    1. This inserts a record to the database detailing the transaction ID, transaction start time, graph name (taken from MetaData), and input schema value
  3. Place the finaliseTxn subgraph node at the end of your transaction (consider all exit points in your graph).
    1. This updates the record with transaction end time, output schema value, output status, and error codes
  4. Your business logic should use the 'writeMeta' node to set the outcome of the transaction
    1. This details the success or failure of the transaction
    2. It details any error messages encountered throughout the transaction 
    3. If metadata is not set, finaliseTxn will set unsuccessful values into the response by default
  5. Your business logic should exit (successfully or error) to the finaliseTxn subgraph

This is very useful for debugging especially during development. The inputMsg contains the state of the JSON at the beginning of the transaction - this can be copied and used to replicate that exact transaction by submitting the json to the editor.



Is it helpful? React and share your comment

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.
ESC

Eddy AI, facilitating knowledge discovery through conversational intelligence