This sample explains about the message tracing and visualization with BAM. That is a request can be sent to the end point by passing through some intermediate stages, and by using BAM we can trace each messages and visualize the message body in each intermediate stage.
In this sample we'll consider a use case, that request for a web services to 'PlaceOrder' travels through some sequences in ESB and then it reaches the end point web service.

Assume a situation where the Order placing web services fronted by a proxy service, and the proxy service consists of the above sequences to mediate the message. As shown in the above diagram, the message first arrives to the 'AuthenticateSequence' and then it'll authenticate the credit card credentials and the account balance for the purchase. In the case of failure of authentication the message will be directed to AuthencateErrorHandlerSequence. In the success case the message will be dispatched to the 'PlaceOrderSequence'. Further here the main order processing will occur and in the case of failure of processing the order, the message will be dispatched to the 'PlaceOrderErrorHandlerSequence'.
In the each of the sequences for the IN and OUT the event will be published to the BAM with bam_activity_id and the current_sequence_name. Therefore the message can be identified by it's unique bam_activity_id and can trace how the message was dispatched from end-to-end. And in the case of failure of message, the message failure can be traced with visualizing the message path.
We'll consider the above use case in this sample, and see how we can trace the message from end-to-end. Each of the above steps will be described in detail in the following steps.
Pre-requisites: Apache-ant
Make sure you machine has apache-ant, if not please install the apache-ant.(http://ant.apache.org/)
We need to create the Index for the BASE column family as the events received by BAM is directly stored here. This index is used to filter out the events which has the bam_activity_id and will group them together.
At this moment we need to create the ClusterStreamSelector. Follow the below given steps to create the index.


In the analyzer you need to write the analytics such that it analyzes the gathered data by the BAM according to you requirement. In this sample we are interested in viewing the message trace from end-to-end, therefore we'll be writing such that the events with same bam_activity_id will be group up (Which corresponds to the one request), and sorted by the time stamp of the event.
The analyzer sequence for this situation,
<analyzerSequence name="MessageTracing">
<trigger cron="1 * * * * ? *"/>
<analyzers>
<get name="BASE" batchSize="100">
<where index="ActivityIndex">
<range column="bam_activity_id" start="" end=""/>
</where>
</get>
<groupBy>
<field name="bam_activity_id"/>
</groupBy>
<orderBy field="timestamp"/>
</analyzers>
</analyzerSequence>
The above given analyzer sequence is given in the WSO2BAM/Samples/end-to-end-messageTracing/MessageTracing.xml. Follow the below given steps to ad dthe analyzer sequence to the BAM server.


Now you can see two index from the index table as below.

In this section we cna see how to design your own gadgets according to your requirement. In this section we created table to visulaize the message details of the events.
The below given steps will explain how to create the gadgets and visualize the data collected.













Now we have come to the end of the sample and now you know the way of generating the custom gadgets from BAM and tracing the messages.