Walkthrough: Tracking requests from Sitecore to xConnect
The ISendRequestHandler interface injects logic to run before and after a request is sent to xConnect. Any client that wants to track and log requests to xConnect must implement the ISendRequestHandler interface and register it in the configuration file.
This walkthrough describes how to:
-
Implement the
ISendRequestHandlerinterface -
Register the handler
Implement the ISendRequestHandler interface
To implement the ISendRequestHandler interface:
-
Create a new class that extends
ISendRequestHandler. For example:RequestResponsepublic class TestSendRequestHandler : ISendRequestHandler { public async Task PreHandle(HttpRequestMessage request) { PreHandleCount++; PreHandledMessages.Add(request); } public async Task PostHandle(HttpResponseMessage response, TimeSpan? duration) { PostHandleCount++; PostHandledMessages.Add(response); } }
Register the handler
To register the handler in the configuration file:
-
Create an XML file under the
App_Data\Config\Sitecore\Collectionfolder (you can specify any filename). -
Register the handler using the following code (substituting the name of the handler):
RequestResponse<Settings> <Sitecore> <XConnect> <Collection> <Services> <ISendRequestHandler> <Type>Sitecore.Xdb.UnitTests.RequestLoggingFixture.TestSendRequestHandler, Sitecore.Xdb. UnitTests</Type> <As>Sitecore.Xdb.Common.Web.ISendRequestHandler, Sitecore.Xdb.Common.Web</As> <LifeTime>Singleton</LifeTime> </ISendRequestHandler> </Services> </Collection> </XConnect> </Sitecore> </Settings>