Message Tracing
Message Tracing is an identification of each message flow in each transaction which goes through the gateway. WSO2 API Manager provides the facility to do message tracing by installing the Message Tracer feature developed for WSO2 Products. It is used to logging, auditing and debugging message content and it’s direction.
Message Tracer is a part of carbon-analytics. From API Manager 2.1.0 onwards, Message Tracer feature is build into API Manager.
Configuring Message Tracer
Follow the below steps to configure Message Tracer in API Manager.
- Log into Managemet Console (https://localhost:9443/carbon).
- Navigate to Configure > Message Tracing in Configure Tab to open the Message Tracing Configuration.
- Select Enable Message Tracing and click Update to enable Message Tracking.
- Select following options as well if you wish to get the message tracing in detail.
Configuration | Description |
---|---|
Dump Message Content | Enable Message tracing for the Content of the Message as well. |
Enable Logging | Enable Logging into available logging handler to log the tracing message. |
Enable Analytics Event Publishing | Publish tracing events to API Manager Analytics |
Tracing Events Publishing to API Manager Analytics
You can trace the messages of event publishing to API Manager Analytics with Message Tracing feature following below steps.
Before you begin,
Make sure you have configured API Manager Analytics. Refer Configuring APIM Analytics to configure Analytics.
Select Enable Analytics Event Publishing in Message Tracer Configuration and click update.
Once you have saved the changes, APIM will generate stream definition in <APIIM_HOM>/repository/deployment/server/eventstreams/DAS_MESSAGE_TRACE_1.0.0.json.
Copy the DAS_MESSAGE_TRACE_1.0.0.json file to <APIM_ANALITICS_HOME>/repository/deployment/server/eventstreams directory to deploy the same definition in API Manager Analytics.
Login to API Manager Analytics (https://localhost:9444/carbon) and navigate to Main > Event > Streams.
You will be able to see the deployed stream under event streams. Now we need to persist the event stream to save data into a table.
- Click Edit in the stream definition DAS_MESSAGE_TRACE:1.0.0 and open the edit view.
- Click Next[Persist Event] at the bottom of the edit view.
- In the next page select Persist Event Stream and select all attribute checkboxes to perist and click on Save Event Stream button.
You should configure an Event receiver to point thid Event stream. - Go to Main -> Event -> Receivers in API Manager Analytics and and click on Add Event Receiver.
Add following details and click on Add Event Receiver.
property Value Event Receiver Name message_trace_receiver Input Event Adoptor Type wso2event Is events duplicated in cluster false Event Stream DAS_MESSAGE_TRACE:1.0.0 Message format wso2event Next, a publisher need to be configured in order to publish events to API Manager Analytics. To do that,
Go to Main > Event > Publishers in API Manager Analytics and click Add Event Publisher.
In Create a New Event Publisher page, add the following details and click Add Event Publisher.
Property Value Event Publisher Name message_tracer_publisher Event Source DAS_MESSAGE_TRACE:1.0.0 Stream Attributes Keep default values
Output Event Adaptor Type wso2event Receiver URL tcp://localhost:7612 User Name admin Password admin Protocol thrift Publishing mode non-blocking Message Format wso2event
Results
After enabling Message tracing, Dump Message Contnet and Logging, you can see the log Message similar to this from API Console for events like API invocation etc.
[2017-01-11 11:43:08,039] INFO - HandlerUtils Massage Info: Transaction id=632470820207822377292 Message direction=IN Server name=172.17.0.1:9763 Timestamp=1515651188039 Service name=__SynapseService Operation Name=mediate [2017-01-11 11:43:08,040] INFO - HandlerUtils Massage Info: Transaction id=632470820207822377292 Message direction=OUT Server name=172.17.0.1:9763 Timestamp=1515651188040 Service name=__SynapseService Operation Name=mediate [2017-01-11 11:43:08,047] INFO - HandlerUtils Massage Info: Transaction id=632471565977965101628 Message direction=IN Server name=172.17.0.1:9763 Timestamp=1515651188047 Service name=__SynapseService Operation Name=mediate [2017-01-11 11:43:08,060] INFO - HandlerUtils Massage Info: Transaction id=632471565977965101628 Message direction=OUT Server name=172.17.0.1:9763 Timestamp=1515651188058 Service name=__SynapseService Operation Name=mediate
If you have enabled Analytics event Publishing,
- Login to WSO2 API Manager Analytics (https://localhost:9444/carbon)
- Navigate to Main > Data Explorer.
- Select the table DAS_MESSAGE_TRACE and click Search.
You can see the event data traced in WSO2 Analytics Data Explorer as below.