Azure API Gateway
Treblle’s Azure API Gateway integration provides real-time monitoring of your Azure API Management APIs through a serverless Event Hub and Azure Functions architecture.
This integration captures API requests, responses, and metadata without requiring code changes to your existing APIs.
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 API
This 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.gitcd treblle-azure
Step 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 loginaz account get-access-token --resource https://management.azure.com/
Using PowerShell:
Connect-AzAccount$token = (Get-AzAccessToken).Token | ConvertFrom-SecureString -AsPlainTextecho $token
Create 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-01
Example 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-01
Headers:
Authorization: Bearer {your-access-token}Content-Type: application/json
Request 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" } }}
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
Apply Policy to API
- Navigate to your 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
)
Policy Configuration Options
- API Level: Applies to specific API
- Global Level: Applies to all APIs
- Operation Level: Applies to specific operations
Create and Activate Revision
- Go to Revisions tab in your API
- Click + Add revision
- Add your policy changes
- Click Create
- Set the new revision as current
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 Windows
Deploy Function Code
Using VS Code:
- Install Azure Functions extension
- Open the cloned project folder
- Press
F1
→ “Azure Functions: Deploy to Function App” - Select your function app
Using Azure CLI:
func azure functionapp publish <function-app-name> --java
Configure Application Settings
Set the following environment variables in your Function App:
Setting | Description | Example |
---|---|---|
AzureWebJobsStorage | Storage account connection string | DefaultEndpointsProtocol=https;AccountName=... |
eventhubconnection | Event Hub connection string from Step 7 | Endpoint=sb://namespace.servicebus.windows.net/;... |
eventhub | Event Hub name | treblle-events |
consumergroup | Event Hub consumer group | $Default |
TREBLLE_PROJECT_ID | Your Treblle project ID | your-project-id |
TREBLLE_API_KEY | Your Treblle API key | your-api-key |
ADDITIONAL_MASK_KEYWORDS | Additional fields to mask (comma-separated) | 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 | Description | Default | Example |
---|---|---|---|
TREBLLE_PROJECT_ID | Your Treblle project ID (required) | None | your-project-id |
TREBLLE_API_KEY | Your Treblle API key (required) | None | tre_sk_... |
eventhub | Event Hub name | treblle-events | my-eventhub |
consumergroup | Event Hub consumer group | $Default | treblle-group |
ADDITIONAL_MASK_KEYWORDS | Fields to mask (comma-separated) | None | 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.
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.