|
| 1 | +# Troubleshooting Azure Event Hubs module issues |
| 2 | + |
| 3 | +This troubleshooting guide contains instructions to diagnose frequently encountered issues while using the Azure Event Hubs module for Go. |
| 4 | + |
| 5 | +## Table of contents |
| 6 | + |
| 7 | +- [General Troubleshooting](#general-troubleshooting) |
| 8 | + - [Error Handling](#error-handling) |
| 9 | + - [Logging](#logging) |
| 10 | +- [Common Error Scenarios](#common-error-scenarios) |
| 11 | + - [Unauthorized Access Errors](#unauthorized-access-errors) |
| 12 | + - [Connection Lost Errors](#connection-lost-errors) |
| 13 | + - [Ownership Lost Errors](#ownership-lost-errors) |
| 14 | + - [Performance Considerations](#performance-considerations) |
| 15 | +- [Connectivity Issues](#connectivity-issues) |
| 16 | + - [Enterprise Environments and Firewalls](#enterprise-environments-and-firewalls) |
| 17 | +- [Advanced Troubleshooting](#advanced-troubleshooting) |
| 18 | + - [Logs to collect](#logs-to-collect) |
| 19 | + - [Interpreting Logs](#interpreting-logs) |
| 20 | + - [Additional Resources](#additional-resources) |
| 21 | + - [Filing GitHub Issues](#filing-github-issues) |
| 22 | + |
| 23 | +## General Troubleshooting |
| 24 | + |
| 25 | +### Error Handling |
| 26 | + |
| 27 | +azeventhubs can return two types of errors: `azeventhubs.Error`, which contains a code you can use programatically, and `error`s which only contain an error message. |
| 28 | + |
| 29 | +Here's an example of how to check the `Code` from an `azeventhubs.Error`: |
| 30 | + |
| 31 | +```go |
| 32 | +if err != nil { |
| 33 | + var azehErr *azeventhubs.Error |
| 34 | + |
| 35 | + if errors.As(err, &azehErr) { |
| 36 | + switch azehErr.Code { |
| 37 | + case azeventhubs.ErrorCodeUnauthorizedAccess: |
| 38 | + // Handle authentication errors |
| 39 | + case azeventhubs.ErrorCodeConnectionLost: |
| 40 | + // This error is only returned if all configured retries have been exhausted. |
| 41 | + // An example of configuring retries can be found here: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventhubs/v2#example-NewConsumerClient-ConfiguringRetries |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + // Handle other error types |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +### Logging |
| 50 | + |
| 51 | +Event Hubs uses the classification-based logging implementation in `azcore`. You can enable logging for all Azure SDK modules by setting the environment variable `AZURE_SDK_GO_LOGGING` to `all`. |
| 52 | + |
| 53 | +For more fine-grained control, use the `azcore/log` package to enable specific log events: |
| 54 | + |
| 55 | +```go |
| 56 | +import ( |
| 57 | + "fmt" |
| 58 | + azlog "github.com/Azure/azure-sdk-for-go/sdk/azcore/log" |
| 59 | + "github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventhubs/v2" |
| 60 | +) |
| 61 | + |
| 62 | +// Print log output to stdout |
| 63 | +azlog.SetListener(func(event azlog.Event, s string) { |
| 64 | + fmt.Printf("[%s] %s\n", event, s) |
| 65 | +}) |
| 66 | + |
| 67 | +// Enable specific event types |
| 68 | +azlog.SetEvents( |
| 69 | + azeventhubs.EventConn, // Connection-related events |
| 70 | + azeventhubs.EventAuth, // Authentication events |
| 71 | + azeventhubs.EventProducer, // Producer operations |
| 72 | + azeventhubs.EventConsumer, // Consumer operations |
| 73 | +) |
| 74 | +``` |
| 75 | + |
| 76 | +## Common Error Scenarios |
| 77 | + |
| 78 | +### Unauthorized Access Errors |
| 79 | + |
| 80 | +If you receive an `ErrorCodeUnauthorizedAccess` error, it means the credentials provided are not valid for use with a particular entity, or they have expired. |
| 81 | + |
| 82 | +**Common causes and solutions:** |
| 83 | + |
| 84 | +- **Expired credentials**: If using SAS tokens, they expire after a certain duration. Generate a new token or use a credential that automatically refreshes, like one of the TokenCredential types from the [Azure Identity module][azidentity_tokencredentials]. |
| 85 | +- **Missing permissions**: Ensure the identity you're using has the correct role assigned from the [built-in roles for Azure Event Hubs](https://learn.microsoft.com/azure/event-hubs/authenticate-application#built-in-roles-for-azure-event-hubs). |
| 86 | +- **Incorrect entity name**: Verify that the Event Hub name, consumer group, or namespace name is spelled correctly. |
| 87 | + |
| 88 | +For more help with troubleshooting authentication errors when using Azure Identity, see the Azure Identity client library [troubleshooting guide][azidentity_troubleshooting]. |
| 89 | + |
| 90 | +### Connection Lost Errors |
| 91 | + |
| 92 | +An `azeventhubs.ErrorCodeConnectionLost` error indicates that the connection was lost and all retry attempts failed. This typically reflects an extended outage or connection disruption. |
| 93 | + |
| 94 | +**Common causes and solutions:** |
| 95 | + |
| 96 | +- **Network instability**: Check your network connection and try again after ensuring stability. |
| 97 | +- **Service outage**: Check the [Azure status page](https://status.azure.com) for any ongoing Event Hubs outages. |
| 98 | +- **Firewall or proxy issues**: Ensure firewall rules aren't blocking the connection. |
| 99 | + |
| 100 | +### Ownership Lost Errors |
| 101 | + |
| 102 | +An `azeventhubs.ErrorCodeOwnershipLost` error occurs when a partition that you were reading from was opened by another link with a higher epoch/owner level. |
| 103 | + |
| 104 | +* If you're using the azeventhubs.Processor, you will occasionally see this error when the individual Processors are allocating partition ownerships. This is expected, and the Processors will handle the error, internally. |
| 105 | +* If you're NOT using the Processor, this indicates you have two PartitionClient instances, both of which are using the same consumer group, opening the same partition, but with different owner levels. |
| 106 | + |
| 107 | +### Performance Considerations |
| 108 | + |
| 109 | +**If the processor can't keep up with event flow:** |
| 110 | + |
| 111 | +1. **Increase processor instances**: Add more Processor instances to distribute the load. The number of Processor instances cannot exceed the number of partitions for your Event Hub. |
| 112 | +2. **Increase Event Hubs partitions**: Consider creating an Event Hub with more partitions, to allow for more parallel consumers. NOTE: requires a new Event Hub. |
| 113 | +3. **Call `ProcessorPartitionClient.UpdateCheckpoint` less often**: some alternate strategies: |
| 114 | + - Call only after a requisite number of events has been received |
| 115 | + - Call only after a certain amount of time has expired. |
| 116 | + |
| 117 | +## Connectivity Issues |
| 118 | + |
| 119 | +### Enterprise Environments and Firewalls |
| 120 | + |
| 121 | +In corporate networks with strict firewall rules, you may encounter connectivity issues when connecting to Event Hubs. |
| 122 | + |
| 123 | +**Common solutions:** |
| 124 | + |
| 125 | +1. **Allow the necessary endpoints**: See [Event Hubs FAQ: "What ports do I need to open on the firewall?"][eventhubs_faq_ports]. |
| 126 | +2. **Use a proxy**: If you require a proxy to connect to Azure resources you can configure your client to use it: [Example using a proxy and/or Websockets][example_proxy_websockets] |
| 127 | +3. **Use Websockets**: If you can only connect to Azure resources using HTTPs (443) you can configure your client to use Websockets. See this example for how to enable websockets with Event Hubs: [Example using a proxy and/or Websockets][example_proxy_websockets]. |
| 128 | +4. **Configure network security rules**: If using Azure VNet integration, configure service endpoints or private endpoints |
| 129 | + |
| 130 | +## Advanced Troubleshooting |
| 131 | + |
| 132 | +### Logs to collect |
| 133 | + |
| 134 | +When troubleshooting issues with Event Hubs that you need to escalate to support or report in GitHub issues, collect the following logs: |
| 135 | + |
| 136 | +1. **Enable debug logging**: To enable logs, see [logging](#logging). |
| 137 | +2. **Timeframe**: Capture logs from at least 5 minutes before until 5 minutes after the issue occurs |
| 138 | +3. **Include timestamps**: Ensure your logging setup includes timestamps. By default `AZURE_SDK_GO_LOGGING` logging includes timestamps. |
| 139 | + |
| 140 | +### Interpreting Logs |
| 141 | + |
| 142 | +When analyzing Event Hubs logs: |
| 143 | + |
| 144 | +1. **Connection errors**: Look for AMQP connection and link errors in `EventConn` logs |
| 145 | +2. **Authentication failures**: Check `EventAuth` logs for credential or authorization failures |
| 146 | +3. **Producer errors**: `EventProducer` logs show message send operations and errors |
| 147 | +4. **Consumer errors**: `EventConsumer` logs show message receive operations and partition ownership changes |
| 148 | +5. **Load balancing**: Look for ownership claims and changes in `EventConsumer` logs |
| 149 | + |
| 150 | +### Additional Resources |
| 151 | + |
| 152 | +- [Event Hubs Documentation](https://learn.microsoft.com/azure/event-hubs/) |
| 153 | +- [Event Hubs Pricing](https://azure.microsoft.com/pricing/details/event-hubs/) |
| 154 | +- [Event Hubs Quotas](https://learn.microsoft.com/azure/event-hubs/event-hubs-quotas) |
| 155 | +- [Event Hubs FAQ](https://learn.microsoft.com/azure/event-hubs/event-hubs-faq) |
| 156 | + |
| 157 | +### Filing GitHub Issues |
| 158 | + |
| 159 | +To file an issue in Github, use this [link](https://github.com/Azure/azure-sdk-for-go/issues/new/choose) and include the following information: |
| 160 | + |
| 161 | +1. **Event Hub details**: |
| 162 | + - How many partitions? |
| 163 | + - What tier (Standard/Premium/Dedicated)? |
| 164 | + |
| 165 | +2. **Client environment**: |
| 166 | + - Machine specifications |
| 167 | + - Number of client instances running |
| 168 | + - Go version |
| 169 | + |
| 170 | +3. **Message patterns**: |
| 171 | + - Average message size |
| 172 | + - Throughput (messages per second) |
| 173 | + - Whether traffic is consistent or bursty |
| 174 | + |
| 175 | +4. **Reproduction steps**: |
| 176 | + - A minimal code example that reproduces the issue |
| 177 | + - Steps to reproduce the problem |
| 178 | + |
| 179 | +5. **Logs**: |
| 180 | + - Include diagnostic loogs from before, during and after the failure. For instructions on enabling logging see the [Logging](#logs-to-collect) section above. |
| 181 | + - **NOTE**: the information in Github issues and logs are publicly viewable. Please keep this in mind when posting any information. |
| 182 | + |
| 183 | +<!-- LINKS --> |
| 184 | +[azidentity_troubleshooting]: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/azidentity/TROUBLESHOOTING.md |
| 185 | +[amqp_errors]: https://learn.microsoft.com/azure/event-hubs/event-hubs-amqp-troubleshoot |
| 186 | +[azidentity_tokencredentials]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity#readme-credential-chains |
| 187 | +[eventhubs_faq_ports]: https://learn.microsoft.com/azure/event-hubs/event-hubs-faq#what-ports-do-i-need-to-open-on-the-firewall |
| 188 | +[example_proxy_websockets]: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/messaging/azeventhubs/example_websockets_and_proxies_test.go |
0 commit comments