Using APIM as a Proxy for Serverless360 BAM
Tags: azure, api, monitoring
Published: 2023-02-07 04:37:16

Many companies like all their API calls to external services routed through Azure API Management (APIM). If you are a user of Serverless360 BAM, then one of the options is to use Azure API Management as a proxy to your BAM API and then use APIM from within Logic Apps.

**Serverless360 BAM**

Serverless360 is an enterprise product that aims to provide simple yet powerful toolsets for all operational needs in Azure Cloud. Serverless360 offers an end-to-end distributed tracing feature called BAM. BAM helps users identify how a transaction flows in a business process and spotlight failures in those transactions. BAM can be instrumented in your business process by containing services like Logic Apps, Function Apps, APIMs, an On-prem system (capable of making an API call), etc.

**Azure API Management Proxy**

The standard approach for BAM would look something like the below. There are three main areas:

- The BAM Service provided by Serverless360
- Your database and storage where you want to store your BAM data
- The components which you wish to publish BAM events

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u92waypppqr9p7m3ao42.png)

Depending on the hosting option you choose for BAM, you may choose to host the BAM Service yourself or host it on the Serverless360 SaaS platform.

For the scenario we are discussing here, as a BAM user, you might pass your calls to Serverless360 BAM through your own Azure API Management solution before they go to Serverless360. It would look like the below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqwrch330evx3v2vqneo.png)

**Why might you choose to do this?**

There are several different reasons you might consider doing this, which include:

- You want to centrally route all API calls through APIM for operational and monitoring purposes.
- You might want to connect APIM to BAM, and you might use the advanced subscription and critical management features in APIM to give other teams access to BAM
- You might want to have a layer of abstraction from your implementation to a 3rd party service.
- You might want to simplify your configuration scenarios for logic apps, so you don’t need to use a custom connector.
- There can be some performance benefits by using APIM rather than a custom connector with Logic Apps.

**How do we set up this scenario?**

It is easy to set up this scenario. The steps to do this are below.

**Download the API Specification for Serverless360 BAM**

You need to go to the action menu from the BAM home page and access the BAM connection details.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2c45eplugsv393v5z0dm.png)

You can get the link to the Swagger for your BAM API to view it in swagger UI.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f1tgi3lkqu4tk73au4kw.png)

You can paste the link into the browser, and it will then show you the BAM API.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k3z7fmepcat5z82z5nk8.png)

The swagger link you need for APIM is shown above with the arrow; you can click it if you want and see the Swagger.

It would help if you took this URL to APIM so you could import your API.

**Create BAM API in APIM**

Next, go to Azure APIM and start to create a new API using the import Open API option.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5w073i2pwosbx8u4f8cs.png)

You can then add the URL for the Swagger, which will import information about your BAM API. You probably want to modify the API suffix so it has an extension that matches the pattern for the standard you are using in your APIM.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ka08csf4v5mkv0wwj8f2.png)

Next, click Create, and APIM will import the API and set up BAM for you.

You will now see a new API, as shown below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gqklvbssmf8k6qku6es.png)

**Set the host and key for BAM**

Next, you need to set the key for calling your BAM API. The best way to do this is to get the key from the BAM portal, and then in the policy for your All Operations on the API, you can add the header to set the key, as shown below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aslh8m8n5rdbf4ofg1qq.png)

Most people will probably have a named value which will be either a secret or linked to a Key Vault which will be used to set the BAM API key in the policy.

Your APIM is now set up to be able to send messages to BAM.

**Use BAM in your Logic App**

Next, I will go to my Logic Apps and look to add an APIM action. If you select your APIM instance and the BAM API you created, you will see the list of operations imported when we set up APIM.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h9ubb8ztmsgq1ajamvck.png)

You can now use these operations as we do with the custom connector.

With APIM having all of the schemas for the BAM API, your Logic App will be able to create a rich design-time experience, just like with the custom connector, as shown below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/07nwgom8b5cowgcki7nz.png)

The main difference is that instead of creating an API connection behind the scenes and inheriting the additional configuration complexity that Logic Apps have in that area, you inherit the cool features for Logic Apps and APIM. You will be able to do more advanced security scenarios such as managed identity, and you can supply a subscription key and other things depending on how you have set up APIM.

You will also avoid the custom connector throttling limits, so we expect to see a performance improvement here too.

**Summary**

Hopefully, you will find that choosing to use APIM as a proxy is easy to set up, and it will open some more advanced setup scenarios that some BAM users may find helpful. Choosing the right distributed tracing tool plays a vital role in your business.