使用要求追蹤對 API 進行偵錯Debug your APIs using request tracing

本教學課程會說明如何檢查要求處理,協助您對 API 進行偵錯和疑難排解。This tutorial describes how to inspect request processing to help you with debugging and troubleshooting your API.

在本教學課程中,您了解如何:In this tutorial, you learn how to:

  • 追蹤呼叫Trace a call

API 偵測器

必要條件Prerequisites

追蹤呼叫Trace a call

API 追蹤

  1. 選取 [API]。Select APIs.

  2. 按一下 API 清單中的 [Demo Conference API]。Click Demo Conference API from your API list.

  3. 切換至 [測試] 索引標籤。Switch to the Test tab.

  4. 選取 [GetSpeakers] 作業。Select GetSpeakers operation.

  5. 務必包含名為 Ocp-Apim-Trace 且值為 true 的 HTTP 標頭。Make sure to include an HTTP header named Ocp-Apim-Trace with the value set to true.

    注意

    如果 Ocp-Apim-Subscription-Key 未自動填入,您可以移至開發人員入口網站並且在設定檔頁面公開金鑰,以便擷取該金鑰。If Ocp-Apim-Subscription-Key is not automatically populated, you can retrieve it by going to the Developer Portal and exposing the keys on the profile page.

  6. 按一下 [傳送] 以進行 API 呼叫。Click "Send" to make an API call.

  7. 請等待呼叫完成。Wait for the call to complete.

  8. 移至 API 主控台中的 [追蹤] 索引標籤。Go to the Trace tab in the API console. 您可以按一下下列任一連結,跳至詳細的追蹤資訊:輸入後端輸出You can click any of the following links to jump to detailed trace info: inbound, backend, outbound.

    在 [輸入] 區段中,您會看到 API 管理從呼叫者那邊接收的原始要求,以及所有套用到要求的原則,包括我們在步驟 2 中新增的速率限制與設定標頭原則。In the inbound section, you see the original request API Management received from the caller and all the policies applied to the request including the rate-limit and set-header policies we added in step 2.

    在 [後端] 區段中,您會看到 API 管理傳送至 API 後端的要求及其接收的回應。In the backend section, you see the requests API Management sent to the API backend and the response it received.

    在 [輸出] 區段中,您會看到回應在傳回至呼叫者之前套用的所有原則。In the outbound section, you see all the policies applied to the response before sending back to the caller.

    提示

    每個步驟也會顯示 API 管理收到要求後耗用的時間。Each step also shows the elapsed time since the request is received by API Management.

後續步驟Next steps

在本教學課程中,您已了解如何:In this tutorial, you learned how to:

  • 追蹤呼叫Trace a call

前進到下一個教學課程:Advance to the next tutorial: