top of page

Azure APIM Tracing not taking up correct Subscription key


You created an Azure API Management Instance. In this you created a Product, example named "TestProduct" without any custom / default policy.


You attached it to an API (here, we will use the test Echo API) which requires a subscription and you created a subscription (here, we named "Test Subscription").


For some reason, you see that the APIM policy or the endpoint is not giving the result you expect. You wish the debug and trace the entire the request passing through the APIM.

You enable Tracing on the subscription (it will be enabled for maximum of 1 hour and of-course you'd need to be careful about handling the sensitive keys as shown in the warning below).

You intend to test the API from the Azure portal.



You go the the APIs -> Echo API -> GET applying "TestProduct" in the Product scope. You then click on Trace.


If you check the "ocp-apim-subscription-key", this is different that what you expect. It did not honor the "Test Subscription" you created for it. But which key is this?


If you head back to Subscriptions tab on the left, its surprising that the "master" i.e. Built-in all-access subscription "Tracking" also got enabled and above tracing picked up the subscription key of this one!



This seems to be an issue while doing it from the Azure portal.


There's a workaround wherein you can use Postman (or any other REST client, here, we will use postman) to trace the API calls.

You install the postman tool and get the Request URL from tracing request you sent above.

In the headers section of the tool, add below (ensure the tracing is still enabled on the "Test Subscription" subscription) -

ocp-apim-subscription-key : <The subscription key of "Test Subscription" one above>

ocp-apim-trace: True


Send the request (GET/POST etc. based on your use case) and inspect the response headers. You should get "Ocp-Apim-Trace-Location" in response header key.



Grab this URL and paste it in your browser. It is a JSON content and you can copy it from there and use in your favourite editor. This is the same trace you expected it from the browser with the accurate Product-Subscription now taken up.



Happy Azure APIM Tracing!

28 views0 comments

Comments


bottom of page