Azure API Gateway
The Azure API Gateway integration automatically:
- Real-time monitoring: Captures requests, responses, and performance metrics instantly
- Serverless architecture: Uses Azure Event Hub and Functions for cost-effective, scalable monitoring
- Policy-based capture: Uses APIM policies to collect API data seamlessly
- Multi-API support: Monitors all APIs configured in your Azure API Management instance
- Error handling: Built-in retry logic and error handling for reliable data delivery
- Easy deployment: ARM template and step-by-step deployment process
Architecture Overview
Azure API Management → Azure Event Hub → Azure Function App → Treblle APIThis integration leverages Azure’s native services to provide real-time API monitoring:
- Azure API Management: Captures API requests/responses using policies
- Azure Event Hub: Provides reliable message streaming and buffering
- Azure Function App: Processes events and forwards to Treblle with error handling and retry logic
Prerequisites
Before you begin, ensure you have:
- Azure subscription with appropriate permissions
- Treblle account with API key and SDK token
- Azure API Management service deployed
- Azure CLI or PowerShell (for deployment) or access to Azure Portal
- Visual Studio Code with Azure Functions extension (recommended for development)
Installation Methods
Step 1: Clone the Repository
git clone https://github.com/Treblle/treblle-azure.git
cd treblle-azureStep 2: Create Resource Group
- Navigate to Resource Manager in Azure Portal
- Click Create a resource group
- Provide a name (e.g.,
treblle-demo) - Select your preferred region
- Click Review + Create
Step 3: Deploy API Management Service
- Go to Marketplace in Azure Portal
- Search for “API Management” (APIM)
- Click Create and configure:
- Resource name: Your APIM service name
- Organization name: Your organization
- Administrator email: Your email address
- Resource group: Select the group created in Step 2
- Click Review + Create
- Wait 20-30 minutes for deployment to complete
Step 4: Create Storage Account
- Go to Marketplace again
- Search for “Storage Account”
- Click Create and provide:
- Storage account name: Unique name (e.g.,
trebllestorage) - Resource group: Same as previous steps
- Region: Same as APIM service
- Storage account name: Unique name (e.g.,
- Click Review + Create
Step 5: Create Event Hub Namespace
- Navigate to Marketplace
- Search for “Event Hubs”
- Click Create Event Hub Namespace
- Configure:
- Namespace name: Unique name (e.g.,
treblle-eventhub-ns) - Resource group: Same as previous resources
- Region: Same region as other resources
- Namespace name: Unique name (e.g.,
- Click Review + Create
Step 6: Create Event Hub
- Navigate to the Event Hub Namespace created in Step 5
- Click + Event Hub
- Provide:
- Name:
treblle-events - Leave other settings as default
- Name:
- Click Create
Step 7: Configure Shared Access Policy
- In your Event Hub Namespace, navigate to Settings → Shared access policies
- Click + Add
- Configure:
- Policy name:
treblle-azure-policy - Permissions: Check both Send and Listen
- Policy name:
- Click Create
- Once created, click on the policy and copy the Primary Connection String - you’ll need this later
Step 8: Configure Azure API Management Logger
Obtain Access Token
First, get an Azure AD access token using one of these methods:
Using Azure CLI:
az login
az account get-access-token --resource https://management.azure.com/Using PowerShell:
Connect-AzAccount
$token = (Get-AzAccessToken).Token | ConvertFrom-SecureString -AsPlainText
echo $tokenCreate Logger via REST API
Use the following REST API call to create the logger:
URL Pattern:
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/loggers/{loggerId}?api-version=2024-05-01Example URL:
PUT https://management.azure.com/subscriptions/4c5f0195-b813-4fc4-819e-2d2d8f1cd2b6/resourceGroups/treblle-demo/providers/Microsoft.ApiManagement/service/treblle-api-azure/loggers/treblle-logger?api-version=2024-05-01Headers:
Authorization: Bearer {your-access-token}
Content-Type: application/jsonRequest Body:
{
"properties": {
"loggerType": "azureEventHub",
"description": "Treblle Azure logger for API monitoring",
"credentials": {
"name": "treblle-events",
"connectionString": "Endpoint=sb://treblle-eventhub-ns.servicebus.windows.net/;SharedAccessKeyName=treblle-azure-policy;SharedAccessKey=your-access-key"
}
}
}Caution
Important: Replace the following values:
{subscriptionId}: Your Azure subscription ID{resourceGroupName}: Your resource group name{serviceName}: Your APIM service name{loggerId}: Logger identifier (e.g.,treblle-logger)name: Your Event Hub nameconnectionString: The primary connection string from Step 7
Step 9: Verify Logger Creation
- Navigate to your Event Hub Namespace
- Go to Activity log
- You should see a log entry: “Add logger or update logger”
Step 10: Configure API Policies
You can apply the Treblle policy at different levels depending on your monitoring needs:
Policy Configuration Levels
Policy Level
Scope and Use Case
Global Level
Monitors all APIs in your APIM instance - Best for organization-wide visibility
API Level
Monitors a specific API - Best for selective monitoring
Operation Level
Monitors specific API operations - Best for granular control
Option A: Apply Policy at Global Level
Use this approach to monitor all APIs in your APIM instance automatically.
- Navigate to APIs in your APIM service
- Select All APIs from the API list
- Go to Inbound processing → Code view
- Add the policy content from the repository: Policy-Content.xml
- Update the logger name to match your created logger (
treblle-logger) - Click Save
Note
When applied at the global level, the policy will automatically monitor all existing and future APIs in your APIM instance. This is the recommended approach for comprehensive monitoring.
Option B: Apply Policy at API Level
Use this approach to monitor specific APIs individually.
- Navigate to your specific API in APIM
- Go to Design tab → Inbound processing → Code view
- Add the policy content from the repository: Policy-Content.xml
- Update the logger name to match your created logger (
treblle-logger) - Click Save
Create and Activate Revision (For API-Level Configuration)
If you applied the policy at the API level, you need to create and activate a revision:
- Go to Revisions tab in your API
- Click + Add revision
- Add your policy changes
- Click Create
- Set the new revision as current
Tip
For global-level policies, revision management is not required as the policy is applied at the instance level.
Step 11: Deploy Azure Function App
Create Function App
az functionapp create \
--resource-group <resource-group> \
--consumption-plan-location <region> \
--runtime java \
--runtime-version 17 \
--functions-version 4 \
--name <function-app-name> \
--storage-account <storage-account> \
--os-type WindowsDeploy Function Code
Using VS Code:
- Install Azure Functions extension
- Open the cloned folder
- Press
F1→ “Azure Functions: Deploy to Function App” - Select your function app
Using Azure CLI:
func azure functionapp publish <function-app-name> --javaConfigure Application Settings
Set the following environment variables in your Function App:
Setting
Configuration Details
AzureWebJobsStorage
Storage account connection string - Example: DefaultEndpointsProtocol=https;AccountName=...
eventhubconnection
Event Hub connection string from Step 7 - Example: Endpoint=sb://namespace.servicebus.windows.net/;...
eventhub
Event Hub name - Example: treblle-events
consumergroup
Event Hub consumer group - Default: $Default
TREBLLE_SDK_TOKEN
Your Treblle SDK Token - Example: your-sdk-token
TREBLLE_API_KEY
Your Treblle API key - Example: your-api-key
ADDITIONAL_MASK_KEYWORDS
Additional fields to mask (comma-separated) - Example: Ocp-Apim-Subscription-Key,Authorization
Step 12: Verify Integration
- Navigate to your deployed Function App
- Go to Functions → EventHubReceiver
- You should see APIs being discovered by the Treblle Azure policy
- Visit your Treblle platform → Workspace
- Verify that all APIs are appearing in your Treblle dashboard
Configuration Parameters
Parameter
Configuration Details
TREBLLE_SDK_TOKEN
Your Treblle SDK Token (required) - Example: your-sdk-token
TREBLLE_API_KEY
Your Treblle API key (required) - Example: tre_sk_...
eventhub
Event Hub name - Default: treblle-events
consumergroup
Event Hub consumer group - Default: $Default
ADDITIONAL_MASK_KEYWORDS
Fields to mask (comma-separated) - Example: Authorization,ApiKey
How It Works
Integration Flow
The Treblle Azure integration uses an event-driven architecture:
- Request Capture: APIM policies capture API requests and responses
- Event Publishing: Data is published to Azure Event Hub
- Event Processing: Azure Function processes events from Event Hub
- Data Transformation: Function formats data for Treblle API
- Monitoring: Processed data is sent to Treblle platform
Policy Configuration
The integration uses APIM policies at three levels:
- Global Level: Monitors all APIs in the APIM instance
- API Level: Monitors specific APIs only
- Operation Level: Monitors individual API operations
Performance Optimizations
- Asynchronous Processing: Event Hub enables non-blocking API monitoring
- Batch Processing: Function app processes events in batches for efficiency
- Retry Logic: Built-in retry mechanism for failed Treblle API calls
- Memory Optimization: Function configured for optimal memory usage
Debugging Steps
- Check Function App Status:
az functionapp show --name <function-app-name> --resource-group <resource-group>- View Event Hub Metrics:
az eventhubs eventhub show --resource-group <resource-group> --namespace-name <namespace> --name <eventhub>- Check APIM Logger Configuration:
az apim logger show --service-name <apim-service> --resource-group <resource-group> --logger-id <logger-id>- Manual Function Test: Use the Azure Portal to trigger the function manually and check execution results.
Tip
The Treblle Azure API Gateway integration provides comprehensive, real-time API monitoring for your Azure infrastructure. With event-driven architecture and serverless components, you can gain complete visibility into your API landscape while maintaining cost efficiency and performance.