PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/articles/api-management/api-management-howto-api-inspector.md

https://gitlab.com/yeah568/azure-content
Markdown | 262 lines | 220 code | 42 blank | 0 comment | 0 complexity | 930a7551165ffa129596a8f64c1059d8 MD5 | raw file
  1. <properties
  2. pageTitle="How to use the API Inspector to trace calls in Azure API Management"
  3. description="Learn how to trace calls using the API Inspector in Azure API Management."
  4. services="api-management"
  5. documentationCenter=""
  6. authors="steved0x"
  7. manager="erikre"
  8. editor=""/>
  9. <tags
  10. ms.service="api-management"
  11. ms.workload="mobile"
  12. ms.tgt_pltfrm="na"
  13. ms.devlang="na"
  14. ms.topic="article"
  15. ms.date="05/25/2016"
  16. ms.author="sdanie"/>
  17. # How to use the API Inspector to trace calls in Azure API Management
  18. API Management provides an API Inspector tool to help you with debugging and troubleshooting your APIs. The API Inspector can be used programmatically and can also be used directly from the developer portal.
  19. In addition to tracing operations, API Inspector also traces [policy expression](https://msdn.microsoft.com/library/azure/dn910913.aspx) evaluations. For a demonstration, see [Cloud Cover Episode 177: More API Management Features](https://azure.microsoft.com/documentation/videos/episode-177-more-api-management-features-with-vlad-vinogradsky/) and fast-forward to 21:00.
  20. This guide provides a walk-through of using API Inspector.
  21. >[AZURE.NOTE] API Inspector traces are only generated and made available for requests containing subscription keys that belong to the [administrator](api-management-howto-create-groups.md) account.
  22. ## <a name="trace-call"> </a> Use API Inspector to trace a call
  23. To use API Inspector, add an **ocp-apim-trace: true** request header to your operation call, and then download and inspect the trace using the URL indicated by the **ocp-apim-trace-location** response header. This can be done programatically, and can also be done directly from the developer portal.
  24. This tutorial shows how to use the API Inspector to trace operations using the Basic Calculator API that is configured in the [Manage your first API](api-management-get-started.md) getting started tutorial. If you haven't completed that tutorial it only takes a few moments to import the Basic Calculator API, or you can use another API of your choosing such as the Echo API. Each API Management service instance comes pre-configured with an Echo API that can be used to experiment with and learn about API Management. The Echo API returns back whatever input is sent to it. To use it, you can invoke any HTTP verb, and the return value will simply be what you sent.
  25. To get started, click **developer portal** in the Azure Classic Portal for your API Management service. Operations can be called directly from the developer portal which provides a convenient way to view and test the operations of an API.
  26. >If you haven't yet created an API Management service instance, see [Create an API Management service instance][] in the [Get started with Azure API Management][] tutorial.
  27. ![API Management developer portal][api-management-developer-portal-menu]
  28. Click **APIs** from the top menu, and then click **Basic Calculator**.
  29. ![Echo API][api-management-api]
  30. Click **Try it** to try the **Add two integers** operation.
  31. ![Try it][api-management-open-console]
  32. Keep the default parameter values, and select the subscription key for the product you want to use from the **subscription-key** drop-down.
  33. By default in the developer portal the **Ocp-Apim-Trace** header is already set to **true**. This header configures whether or not a trace is generated.
  34. ![Send][api-management-http-get]
  35. Click **Send** to invoke the operation.
  36. ![Send][api-management-send-results]
  37. In the response headers will be an **ocp-apim-trace-location** with a value similar to the following example.
  38. ocp-apim-trace-location : https://contosoltdxw7zagdfsprykd.blob.core.windows.net/apiinspectorcontainer/ZW3e23NsW4wQyS-SHjS0Og2-2?sv=2013-08-15&sr=b&sig=Mgx7cMHsLmVDv%2B%2BSzvg3JR8qGTHoOyIAV7xDsZbF7%2Bk%3D&se=2014-05-04T21%3A00%3A13Z&sp=r&verify_guid=a56a17d83de04fcb8b9766df38514742
  39. The trace can be downloaded from the specified location and reviewed as demonstrated in the next step.
  40. ## <a name="inspect-trace"> </a>Inspect the trace
  41. To review the values in the trace, download the trace file from the **ocp-apim-trace-location** URL. It is a text file in JSON format, and contains entries similar to the following example.
  42. {
  43. "traceId": "abcd8ea63d134c1fabe6371566c7cbea",
  44. "traceEntries": {
  45. "inbound": [
  46. {
  47. "source": "handler",
  48. "timestamp": "2015-06-23T19:51:35.2998610Z",
  49. "elapsed": "00:00:00.0725926",
  50. "data": {
  51. "request": {
  52. "method": "GET",
  53. "url": "https://contoso5.azure-api.net/calc/add?a=51&b=49",
  54. "headers": [
  55. {
  56. "name": "Ocp-Apim-Subscription-Key",
  57. "value": "5d7c41af64a44a68a2ea46580d271a59"
  58. },
  59. {
  60. "name": "Connection",
  61. "value": "Keep-Alive"
  62. },
  63. {
  64. "name": "Host",
  65. "value": "contoso5.azure-api.net"
  66. }
  67. ]
  68. }
  69. }
  70. },
  71. {
  72. "source": "mapper",
  73. "timestamp": "2015-06-23T19:51:35.2998610Z",
  74. "elapsed": "00:00:00.0726213",
  75. "data": {
  76. "configuration": {
  77. "api": {
  78. "from": "/calc",
  79. "to": {
  80. "scheme": "http",
  81. "host": "calcapi.cloudapp.net",
  82. "port": 80,
  83. "path": "/api",
  84. "queryString": "",
  85. "query": {},
  86. "isDefaultPort": true
  87. }
  88. },
  89. "operation": {
  90. "method": "GET",
  91. "uriTemplate": "/add?a={a}&b={b}"
  92. },
  93. "user": {
  94. "id": 1,
  95. "groups": [
  96. "Administrators",
  97. "Developers"
  98. ]
  99. },
  100. "product": {
  101. "id": 1
  102. }
  103. }
  104. }
  105. },
  106. {
  107. "source": "handler",
  108. "timestamp": "2015-06-23T19:51:35.2998610Z",
  109. "elapsed": "00:00:00.0727522",
  110. "data": {
  111. "message": "Request is being forwarded to the backend service.",
  112. "request": {
  113. "method": "GET",
  114. "url": "http://calcapi.cloudapp.net/api/add?a=51&b=49",
  115. "headers": [
  116. {
  117. "name": "Ocp-Apim-Subscription-Key",
  118. "value": "5d7c41af64a44a68a2ea46580d271a59"
  119. },
  120. {
  121. "name": "X-Forwarded-For",
  122. "value": "33.52.215.35"
  123. }
  124. ]
  125. }
  126. }
  127. }
  128. ],
  129. "outbound": [
  130. {
  131. "source": "handler",
  132. "timestamp": "2015-06-23T19:51:35.4256650Z",
  133. "elapsed": "00:00:00.1960601",
  134. "data": {
  135. "response": {
  136. "status": {
  137. "code": 200,
  138. "reason": "OK"
  139. },
  140. "headers": [
  141. {
  142. "name": "Pragma",
  143. "value": "no-cache"
  144. },
  145. {
  146. "name": "Content-Length",
  147. "value": "124"
  148. },
  149. {
  150. "name": "Cache-Control",
  151. "value": "no-cache"
  152. },
  153. {
  154. "name": "Content-Type",
  155. "value": "application/xml; charset=utf-8"
  156. },
  157. {
  158. "name": "Date",
  159. "value": "Tue, 23 Jun 2015 19:51:35 GMT"
  160. },
  161. {
  162. "name": "Expires",
  163. "value": "-1"
  164. },
  165. {
  166. "name": "Server",
  167. "value": "Microsoft-IIS/8.5"
  168. },
  169. {
  170. "name": "X-AspNet-Version",
  171. "value": "4.0.30319"
  172. },
  173. {
  174. "name": "X-Powered-By",
  175. "value": "ASP.NET"
  176. }
  177. ]
  178. }
  179. }
  180. },
  181. {
  182. "source": "handler",
  183. "timestamp": "2015-06-23T19:51:35.4256650Z",
  184. "elapsed": "00:00:00.1961112",
  185. "data": {
  186. "message": "Response headers have been sent to the caller. Starting to stream the response body."
  187. }
  188. },
  189. {
  190. "source": "handler",
  191. "timestamp": "2015-06-23T19:51:35.4256650Z",
  192. "elapsed": "00:00:00.1963155",
  193. "data": {
  194. "message": "Response body streaming to the caller is complete."
  195. }
  196. }
  197. ]
  198. }
  199. }
  200. ## <a name="next-steps"> </a>Next steps
  201. - Check out the other topics in the [Get started with advanced API configuration][] tutorial.
  202. - Watch a demo of tracing policy expressions in [Cloud Cover Episode 177: More API Management Features](https://azure.microsoft.com/documentation/videos/episode-177-more-api-management-features-with-vlad-vinogradsky/). Fast-forward to 21:00 to see the demo.
  203. >[AZURE.VIDEO episode-177-more-api-management-features-with-vlad-vinogradsky]
  204. [Use API Inspector to trace a call]: #trace-call
  205. [Inspect the trace]: #inspect-trace
  206. [Next steps]: #next-steps
  207. [Configure API settings]: api-management-howto-create-apis.md#configure-api-settings
  208. [Responses]: api-management-howto-add-operations.md#responses
  209. [How create and publish a product]: api-management-howto-add-products.md
  210. [Get started with Azure API Management]: api-management-get-started.md
  211. [Create an API Management service instance]: api-management-get-started.md#create-service-instance
  212. [Get started with advanced API configuration]: api-management-get-started-advanced.md
  213. [Azure Classic Portal]: https://manage.windowsazure.com/
  214. [api-management-developer-portal-menu]: ./media/api-management-howto-api-inspector/api-management-developer-portal-menu.png
  215. [api-management-api]: ./media/api-management-howto-api-inspector/api-management-api.png
  216. [api-management-echo-api-get]: ./media/api-management-howto-api-inspector/api-management-echo-api-get.png
  217. [api-management-developer-key]: ./media/api-management-howto-api-inspector/api-management-developer-key.png
  218. [api-management-open-console]: ./media/api-management-howto-api-inspector/api-management-open-console.png
  219. [api-management-http-get]: ./media/api-management-howto-api-inspector/api-management-http-get.png
  220. [api-management-send-results]: ./media/api-management-howto-api-inspector/api-management-send-results.png