APIM + Functions
  • 31 Oct 2024
  • 1 Minute to read
  • Dark
    Light
  • PDF

APIM + Functions

  • Dark
    Light
  • PDF

Article summary

In this scenario we are allowing a 3rd party to submit reservations to our reservation API. We will then process those with Azure Functions on the backend of the API.
In this case I am correlating events from 2 seperate App Insights instances to create a consolidated transaction view for the support user and business user.

Below is the transaction search view.

image.png

I can click on a transaction and view the details of the steps it went through. In this case I am looking at stages from the APIM backend and also a request and trace log event from the functions.

image.png

You could extend this scenario using your own custom log events in the functions too.

Walk Thru Video

This video will show how this demo works.

Parent Transaction Query

For the parent transaction I am looking at just the API operation and for info about what happened. I will use the operation_id property for correlation to downstream events within the transaction.

let inputApimServiceName = "kv-eai-apim.azure-api.net";
let inputApiName = "external-api-booking-api";
let inputOperationName = "booking-save";
requests
| where customDimensions.["Service Name"] == inputApimServiceName
| where customDimensions.["API Name"] == inputApiName
| where customDimensions.["Operation Name"] == inputOperationName
| order by timestamp desc

Stage in Transaction Query

API Backend Stage

In this case I am looking for the dependency call which would match to my backend on the API. I can correlate with the operation id

let inputOperationId = {operation_Id};
let inputApimServiceName = "kv-eai-apim.azure-api.net";
let inputApiName = "external-api-booking-api";
let inputOperationName = "PUT /api/Booking-Save";
dependencies
| where type == "Backend"
| where customDimensions.["Service Name"] == "kv-eai-apim.azure-api.net"
| where operation_Id == inputOperationId
| where name == inputOperationName

Function Request Stage

This example looks at the request table and creates an event for the function request execution.

let inputOperationId = {operation_Id};
let inputFunctionAppName = "kv-res-booking-api";
let inputFunctionName = "Booking-Save";
requests 
| where cloud_RoleName == inputFunctionAppName
| where name == inputFunctionName
| where operation_Id == inputOperationId

Function Trace Stage

This stage uses the function trace logs and finds a matching trace event for the function indicating the function started.

let inputOperationId = {operation_Id};
let inputFunctionAppName = "kv-res-booking-api";
let inputFunctionName = "Functions.Booking-Save";
traces 
| where operation_Id == inputOperationId
| where cloud_RoleName == inputFunctionAppName
| where customDimensions.prop__functionName == inputFunctionName
| extend prop__status_ = tostring(customDimensions.prop__status)
| where customDimensions.EventName == "FunctionStarted"

Was this article helpful?

What's Next