Tutorial: Debug your APIs using request tracing

This tutorial describes how to inspect (trace) request processing in Azure API Management to help you debug and troubleshoot your API.

In this tutorial, you learn how to:

  • Trace an example call
  • Review request processing steps

API inspector

Prerequisites

Verify allow tracing setting

The Allow tracing setting for the subscription used for your API must be enabled. If you're using the built-in all-access subscription, it's enabled by default. To verify in the portal, navigate to your API Management instance and select Subscriptions.

Allow tracing for subscription

Trace a call

  1. Sign in to the Azure portal, and navigate to your API Management instance.
  2. Select APIs.
  3. Select Demo Conference API from your API list.
  4. Select the Test tab.
  5. Select the GetSpeakers operation.
  6. Confirm that the HTTP request header includes Ocp-Apim-Trace: True and a valid value for Ocp-Apim-Subscription-Key. If it isn't, select + Add Header to add the header.
  7. Select Send to make an API call.

Configure API tracing

Tip

If Ocp-Apim-Subscription-Key isn't automatically populated in the HTTP request, you can retrieve it in the portal. Select Subscriptions, and open the context menu (...) for your suscription. Select Show/hide keys. You can also regenerate keys if needed. Then, add a key to the header.

Review trace information

  1. After the call completes, go to the Trace tab in the HTTP Response.

  2. Select any of the following links to jump to detailed trace info: Inbound, Backend, Outbound.

    Review response trace

    • Inbound - Shows the original request API Management received from the caller and the policies applied to the request. For example, if you added policies in Tutorial: Transform and protect your API, they will appear here.

    • Backend - Shows the requests API Management sent to the API backend and the response it received.

    • Outbound - Shows the policies applied to the response before sending back to the caller.

    Tip

    Each step also shows the elapsed time since the request is received by API Management.

  3. On the Message tab, the ocp-apim-trace-location header shows the location of the trace data stored in Azure blob storage. If needed, go to this location to retrieve the trace.

    Trace location in Azure Storage

Next steps

In this tutorial, you learned how to:

  • Trace an example call
  • Review request processing steps

Advance to the next tutorial: