Skip to content

Commit 1547c7f

Browse files
committed
draft complete
1 parent 2b31e87 commit 1547c7f

File tree

1 file changed

+116
-26
lines changed

1 file changed

+116
-26
lines changed

articles/api-management/api-management-howto-log-event-hubs.md

Lines changed: 116 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ author: dlepow
77

88
ms.service: api-management
99
ms.topic: how-to
10-
ms.date: 12/20/2022
10+
ms.date: 01/18/2023
1111
ms.author: danlep
1212

1313
---
1414
# How to log events to Azure Event Hubs in Azure API Management
15-
Azure Event Hubs is a highly scalable data ingress service that can ingest millions of events per second so that you can process and analyze the massive amounts of data produced by your connected devices and applications. Event Hubs acts as the "front door" for an event pipeline, and once data is collected into an event hub, it can be transformed and stored using any real-time analytics provider or batching/storage adapters. Event Hubs decouples the production of a stream of events from the consumption of those events, so that event consumers can access the events on their own schedule.
1615

1716
This article describes how to log API Management events using Azure Event Hubs.
1817

18+
Azure Event Hubs is a highly scalable data ingress service that can ingest millions of events per second so that you can process and analyze the massive amounts of data produced by your connected devices and applications. Event Hubs acts as the "front door" for an event pipeline, and once data is collected into an event hub, it can be transformed and stored using any real-time analytics provider or batching/storage adapters. Event Hubs decouples the production of a stream of events from the consumption of those events, so that event consumers can access the events on their own schedule.
19+
1920
## Prerequisites
2021

2122
* An API Management service instance. If you don't have one, see [Create an API Management service instance](get-started-create-service-instance.md).
@@ -25,7 +26,7 @@ This article describes how to log API Management events using Azure Event Hubs.
2526
2627
## Configure access to the event hub
2728

28-
To log events to the event hub, you need to configure credentials for access from API Management. API Management supports two access mechanisms:
29+
To log events to the event hub, you need to configure credentials for access from API Management. API Management supports either of the two following access mechanisms:
2930

3031
* An event hub connection string
3132
* A managed identity for your API Management instance.
@@ -51,7 +52,7 @@ To create an Event Hubs connection string, see [Get an Event Hubs connection str
5152
## Create an API Management logger
5253
The next step is to configure a [logger](/rest/api/apimanagement/current-ga/logger) in your API Management service so that it can log events to the event hub.
5354

54-
You can create and manage API Management loggers using the [API Management REST API](/rest/api/apimanagement/current-ga/logger/create-or-update) directly or using tools including [Azure PowerShell](/powershell/module/az.apimanagement/new-azapimanagementlogger), a Bicep template, or an Azure Resource Management template.
55+
Create and manage API Management loggers by using the [API Management REST API](/rest/api/apimanagement/current-preview/logger/create-or-update) directly or by using tools including [Azure PowerShell](/powershell/module/az.apimanagement/new-azapimanagementlogger), a Bicep template, or an Azure Resource Management template.
5556

5657
### Logger with connection string credentials
5758

@@ -66,28 +67,22 @@ $resourceGroupName = "myResourceGroup"
6667
6768
# Create logger
6869
$context = New-AzApiManagementContext -ResourceGroupName $resourceGroupName -ServiceName $apimServiceName
69-
New-AzApiManagementLogger -Context $context -LoggerId "ContosoLogger1" -Name "ApimEventHub" -ConnectionString "Endpoint=sb://ContosoEventHubs.servicebus.windows.net/;SharedAccessKeyName=SendKey;SharedAccessKey=<key>" -Description "Event hub logger with connection string"
70+
New-AzApiManagementLogger -Context $context -LoggerId "ContosoLogger1" -Name "ApimEventHub" -ConnectionString "Endpoint=sb://<EventHubsNamespace>.servicebus.windows.net/;SharedAccessKeyName=<KeyName>;SharedAccessKey=<key>" -Description "Event hub logger with connection string"
7071
```
7172

7273
#### [Bicep](#tab/bicep)
7374

74-
Include the following snippet in your Bicep template.
75+
Include a snippet similar to the following in your Bicep template.
7576

7677
```Bicep
77-
@description('The name of the API Management service instance.')
78-
param serviceName string
79-
80-
resource apimService 'Microsoft.ApiManagement/service@2022-04-01-preview' existing = {
81-
name: serviceName
82-
8378
resource ehLoggerWithConnectionString 'Microsoft.ApiManagement/service/loggers@2022-04-01-preview' = {
8479
name: 'ContosoLogger1'
85-
parent: apimService
80+
parent: '<APIManagementInstanceName>'
8681
properties: {
8782
loggerType: 'azureEventHub'
88-
description: 'Event hub logger with connection string'
83+
description: 'Event hub logger with system-assigned managed identity'
8984
credentials: {
90-
connectionString: 'Endpoint=sb://ContosoEventHubs.servicebus.windows.net/;SharedAccessKeyName=SendKey;SharedAccessKey=<key>'
85+
connectionString: 'Endpoint=sb://<EventHubsNamespace>.servicebus.windows.net/;SharedAccessKeyName=<KeyName>;SharedAccessKey=<key>'
9186
name: 'ApimEventHub'
9287
}
9388
}
@@ -96,35 +91,131 @@ resource ehLoggerWithConnectionString 'Microsoft.ApiManagement/service/loggers@2
9691

9792
#### [ARM](#tab/arm)
9893

99-
Include the following JSON snippet in your Azure Resource Manager template.
94+
Include a JSON snippet similar to the following in your Azure Resource Manager template.
10095

10196
```JSON
10297
{
10398
"type": "Microsoft.ApiManagement/service/loggers",
10499
"apiVersion": "2022-04-01-preview",
105100
"name": "ContosoLogger1",
106101
"properties": {
102+
"loggerType": "azureEventHub",
103+
"description": "Event hub logger with system-assigned managed identity",
104+
"resourceId": "<EventHubsResourceID>"
107105
"credentials": {
108-
"connectionString": "Endpoint=sb://ContosoEventHubs.servicebus.windows.net/;SharedAccessKeyName=SendKey;SharedAccessKey=<key>",
109-
"name": "ApimEventHub"
106+
"connectionString": "Endpoint=sb://ContosoEventHubs.servicebus.windows.net/;SharedAccessKeyName=<KeyName>;SharedAccessKey=<key>",
107+
"name": "ApimEventHub"
110108
},
111-
"description": "Event hub logger with connection string",
112-
"loggerType": "azureEventHub",
113-
"resourceId": "string"
114109
}
115110
}
116111
```
117112
---
118113

119114
### Logger with system-assigned managed identity credentials
120115

116+
See [Configure API Management managed identity](#configure-event-hub-connection-string).
117+
118+
#### [PowerShell](#tab/PowerShell)
119+
120+
Use the API Management [REST API](/rest/api/apimanagement/current-preview/logger/create-or-update) or a Bicep or ARM template to configure a logger to an event hub with system-assigned managed identity credentials.
121+
122+
#### [Bicep](#tab/bicep)
123+
124+
Include a snippet similar to the following in your Bicep template.
125+
126+
```Bicep
127+
resource ehLoggerWithSystemAssignedIdentity 'Microsoft.ApiManagement/service/loggers@2022-04-01-preview' = {
128+
name: 'ContosoLogger1'
129+
parent: '<APIManagementInstanceName>'
130+
properties: {
131+
loggerType: 'azureEventHub'
132+
description: 'Event hub logger with system-assigned managed identity'
133+
credentials: {
134+
endpointAddress: 'https://<EventHubsNamespace>.servicebus.windows.net/<EventHubName>'
135+
identityClientId: 'systemAssigned'
136+
name: 'ApimEventHub'
137+
}
138+
}
139+
}
140+
```
141+
142+
#### [ARM](#tab/arm)
143+
144+
Include a JSON snippet similar to the following in your Azure Resource Manager template.
121145

146+
```JSON
147+
{
148+
"type": "Microsoft.ApiManagement/service/loggers",
149+
"apiVersion": "2022-04-01-preview",
150+
"name": "ContosoLogger1",
151+
"properties": {
152+
"loggerType": "azureEventHub",
153+
"description": "Event hub logger with system-assigned managed identity",
154+
"resourceId": "<EventHubsResourceID>",
155+
"credentials": {
156+
"endpointAddress": "https://<EventHubsNamespace>.servicebus.windows.net/<EventHubName>",
157+
"identityClientId": "SystemAssigned",
158+
"name": "ApimEventHub"
159+
},
160+
}
161+
}
162+
```
163+
---
122164
### Logger with user-assigned managed identity credentials
123165

166+
See [Configure API Management managed identity](#configure-event-hub-connection-string).
167+
168+
#### [PowerShell](#tab/PowerShell)
169+
170+
Use the API Management [REST API](/rest/api/apimanagement/current-preview/logger/create-or-update) or a Bicep or ARM template to configure a logger to an event hub with user-assigned managed identity credentials.
171+
172+
#### [Bicep](#tab/bicep)
173+
174+
Include a snippet similar the following in your Bicep template.
175+
176+
```Bicep
177+
178+
resource ehLoggerWithUserAssignedIdentity 'Microsoft.ApiManagement/service/loggers@2022-04-01-preview' = {
179+
name: 'ContosoLogger1'
180+
parent: '<APIManagementInstanceName>'
181+
properties: {
182+
loggerType: 'azureEventHub'
183+
description: 'Event hub logger with user-assigned managed identity'
184+
credentials: {
185+
endpointAddress: 'https://<EventHubsNamespace>.servicebus.windows.net/<EventHubName>'
186+
identityClientId: '<ClientID>'
187+
name: 'ApimEventHub'
188+
}
189+
}
190+
}
191+
```
192+
193+
#### [ARM](#tab/arm)
194+
195+
Include a JSON snippet similar to the following in your Azure Resource Manager template.
196+
197+
```JSON
198+
{
199+
"type": "Microsoft.ApiManagement/service/loggers",
200+
"apiVersion": "2022-04-01-preview",
201+
"name": "ContosoLogger1",
202+
"properties": {
203+
"loggerType": "azureEventHub",
204+
"description": "Event hub logger with user-assigned managed identity",
205+
"resourceId": "<EventHubsResourceID>",
206+
"credentials": {
207+
"endpointAddress": "https://<EventHubsNamespace>.servicebus.windows.net/<EventHubName>",
208+
"identityClientId": "<ClientID>",
209+
"name": "ApimEventHub"
210+
},
211+
}
212+
}
213+
```
214+
---
124215

125216
## Configure log-to-eventhub policy
126217

127-
Once your logger is configured in API Management, you can configure your [log-to-eventhub](api-management-advanced-policies.md#log-to-eventhub) policy to log the desired events. For example, use the `log-to-eventhub` policy in the inbound policy section to log requests, or in the outbound policy section to log responses.
218+
Once your logger is configured in API Management, you can configure your [log-to-eventhub](log-to-eventhub-policy.md) policy to log the desired events. For example, use the `log-to-eventhub` policy in the inbound policy section to log requests, or in the outbound policy section to log responses.
128219

129220
1. Browse to your API Management instance.
130221
1. Select **APIs**, and then select the API to which you want to add the policy. In this example, we're adding a policy to the **Echo API** in the **Unlimited** product.
@@ -151,7 +242,7 @@ Once your logger is configured in API Management, you can configure your [log-to
151242
1. Replace `logger-id` with the name of the logger that you created in the previous step.
152243
1. You can use any expression that returns a string as the value for the `log-to-eventhub` element. In this example, a string in JSON format containing the date and time, service name, request ID, request IP address, and operation name is logged.
153244

154-
1. Select **Save** to save the updated policy configuration. As soon as it is saved, the policy is active and events are logged to the designated event hub.
245+
1. Select **Save** to save the updated policy configuration. As soon as it's saved, the policy is active and events are logged to the designated event hub.
155246

156247
> [!NOTE]
157248
> The maximum supported message size that can be sent to an event hub from this API Management policy is 200 kilobytes (KB). If a message that is sent to an event hub is larger than 200 KB, it will be automatically truncated, and the truncated message will be transferred to the event hub.
@@ -171,7 +262,6 @@ You can preview the log in Event Hubs by using [Azure Stream Analytics queries](
171262
* [Receive messages with EventProcessorHost](../event-hubs/event-hubs-dotnet-standard-getstarted-send.md)
172263
* [Event Hubs programming guide](../event-hubs/event-hubs-programming-guide.md)
173264
* Learn more about API Management and Event Hubs integration
174-
* [Logger entity reference](/rest/api/apimanagement/current-ga/logger)
175-
* [log-to-eventhub policy reference](log-to-eventhub-policy.md)
176-
* [Monitor your APIs with Azure API Management, Event Hubs, and Moesif](api-management-log-to-eventhub-sample.md)
265+
* [Logger entity reference](/rest/api/apimanagement/current-preview/logger)
266+
* [log-to-eventhub](log-to-eventhub-policy.md) policy reference
177267
* Learn more about [integration with Azure Application Insights](api-management-howto-app-insights.md)

0 commit comments

Comments
 (0)