Walkthrough: Tracking requests from Sitecore to xConnect

Version: 10.4

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 ISendRequestHandler interface

  • Register the handler

Implement the ISendRequestHandler interface

To implement the ISendRequestHandler interface:

  • Create a new class that extends ISendRequestHandler. For example:

    RequestResponse
    public 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:

  1. Create an XML file under the App_Data\Config\Sitecore\Collection folder (you can specify any filename).

  2. 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>
    

Do you have some feedback for us?

If you have suggestions for improving this article,