| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Diagnostics.Tracing; |
| | 5 | | using Azure.Core.Diagnostics; |
| | 6 | |
|
| | 7 | | namespace Azure.Messaging.EventHubs.Processor.Diagnostics |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Serves as an ETW event source for logging of information about |
| | 11 | | /// Event Processor client. |
| | 12 | | /// </summary> |
| | 13 | | /// |
| | 14 | | /// <remarks> |
| | 15 | | /// When defining Start/Stop tasks, it is highly recommended that the |
| | 16 | | /// the StopEvent.Id must be exactly StartEvent.Id + 1. |
| | 17 | | /// </remarks> |
| | 18 | | /// |
| | 19 | | [EventSource(Name = EventSourceName)] |
| | 20 | | internal class EventProcessorClientEventSource : EventSource |
| | 21 | | { |
| | 22 | | /// <summary>The name to use for the event source.</summary> |
| | 23 | | private const string EventSourceName = "Azure-Messaging-EventHubs-Processor-EventProcessorClient"; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// Provides a singleton instance of the event source for callers to |
| | 27 | | /// use for logging. |
| | 28 | | /// </summary> |
| | 29 | | /// |
| 134 | 30 | | public static EventProcessorClientEventSource Log { get; } = new EventProcessorClientEventSource(EventSourceName |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Prevents an instance of the <see cref="EventProcessorClientEventSource"/> class from being created |
| | 34 | | /// outside the scope of this library. Exposed for testing purposes only. |
| | 35 | | /// </summary> |
| | 36 | | /// |
| 10 | 37 | | protected EventProcessorClientEventSource() : base(EventSourceName, EventSourceSettings.Default, AzureEventSourc |
| | 38 | | { |
| 10 | 39 | | } |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Prevents an instance of the <see cref="EventProcessorClientEventSource"/> class from being created |
| | 43 | | /// outside the scope of this library. Exposed for testing purposes only. |
| | 44 | | /// </summary> |
| | 45 | | /// |
| | 46 | | /// <param name="eventSourceName">The name to assign the event source.</param> |
| | 47 | | /// |
| 2 | 48 | | private EventProcessorClientEventSource(string eventSourceName) : base(eventSourceName, EventSourceSettings.Defa |
| | 49 | | { |
| 2 | 50 | | } |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Indicates that an <see cref="EventProcessorClient" /> has begin processing a batch of events for a partiti |
| | 54 | | /// </summary> |
| | 55 | | /// |
| | 56 | | /// <param name="partitionId">The identifier of the Event Hub partition whose processing is taking place.</param |
| | 57 | | /// <param name="identifier">A unique name used to identify the event processor.</param> |
| | 58 | | /// <param name="eventHubName">The name of the Event Hub that the processor is associated with.</param> |
| | 59 | | /// <param name="consumerGroup">The name of the consumer group that the processor is associated with.</param> |
| | 60 | | /// |
| | 61 | | [Event(20, Level = EventLevel.Verbose, Message = "Starting to process a batch of events for partition '{0}' by p |
| | 62 | | public virtual void EventBatchProcessingStart(string partitionId, |
| | 63 | | string identifier, |
| | 64 | | string eventHubName, |
| | 65 | | string consumerGroup) |
| | 66 | | { |
| 8 | 67 | | if (IsEnabled()) |
| | 68 | | { |
| 0 | 69 | | WriteEvent(20, partitionId ?? string.Empty, identifier ?? string.Empty, eventHubName ?? string.Empty, co |
| | 70 | | } |
| 8 | 71 | | } |
| | 72 | |
|
| | 73 | | /// <summary> |
| | 74 | | /// Indicates that an <see cref="EventProcessorClient" /> instance has experienced an exception while processi |
| | 75 | | /// </summary> |
| | 76 | | /// |
| | 77 | | /// <param name="partitionId">The identifier of the Event Hub partition whose processing is taking place.</param |
| | 78 | | /// <param name="identifier">A unique name used to identify the event processor.</param> |
| | 79 | | /// <param name="eventHubName">The name of the Event Hub that the processor is associated with.</param> |
| | 80 | | /// <param name="consumerGroup">The name of the consumer group that the processor is associated with.</param> |
| | 81 | | /// |
| | 82 | | [Event(21, Level = EventLevel.Verbose, Message = "Completed processing a batch of events for partition '{0}' by |
| | 83 | | public virtual void EventBatchProcessingComplete(string partitionId, |
| | 84 | | string identifier, |
| | 85 | | string eventHubName, |
| | 86 | | string consumerGroup) |
| | 87 | | { |
| 8 | 88 | | if (IsEnabled()) |
| | 89 | | { |
| 0 | 90 | | WriteEvent(21, partitionId ?? string.Empty, identifier ?? string.Empty, eventHubName ?? string.Empty, co |
| | 91 | | } |
| 8 | 92 | | } |
| | 93 | |
|
| | 94 | | /// <summary> |
| | 95 | | /// Indicates that an <see cref="EventProcessorClient" /> has completed processing for a batch of events. |
| | 96 | | /// </summary> |
| | 97 | | /// |
| | 98 | | /// <param name="partitionId">The identifier of the Event Hub partition whose processing is taking place.</param |
| | 99 | | /// <param name="identifier">A unique name used to identify the event processor.</param> |
| | 100 | | /// <param name="eventHubName">The name of the Event Hub that the processor is associated with.</param> |
| | 101 | | /// <param name="consumerGroup">The name of the consumer group that the processor is associated with.</param> |
| | 102 | | /// <param name="errorMessage">The message for the exception that occurred.</param> |
| | 103 | | /// |
| | 104 | | [Event(22, Level = EventLevel.Error, Message = "An exception occurred while processing events for partition '{0} |
| | 105 | | public virtual void EventBatchProcessingError(string partitionId, |
| | 106 | | string identifier, |
| | 107 | | string eventHubName, |
| | 108 | | string consumerGroup, |
| | 109 | | string errorMessage) |
| | 110 | | { |
| 8 | 111 | | if (IsEnabled()) |
| | 112 | | { |
| 0 | 113 | | WriteEvent(22, partitionId ?? string.Empty, identifier ?? string.Empty, eventHubName ?? string.Empty, co |
| | 114 | | } |
| 8 | 115 | | } |
| | 116 | |
|
| | 117 | | /// <summary> |
| | 118 | | /// Indicates that process of updating the checkpoint in the chosen storage service has started. |
| | 119 | | /// </summary> |
| | 120 | | /// |
| | 121 | | /// <param name="partitionId">The identifier of the Event Hub partition whose processing is taking place.</param |
| | 122 | | /// <param name="identifier">A unique name used to identify the event processor.</param> |
| | 123 | | /// <param name="eventHubName">The name of the Event Hub that the processor is associated with.</param> |
| | 124 | | /// <param name="consumerGroup">The name of the consumer group that the processor is associated with.</param> |
| | 125 | | /// |
| | 126 | | [Event(23, Level = EventLevel.Verbose, Message = "Starting to perform a checkpoint update for partition '{0}' by |
| | 127 | | public virtual void UpdateCheckpointStart(string partitionId, |
| | 128 | | string identifier, |
| | 129 | | string eventHubName, |
| | 130 | | string consumerGroup) |
| | 131 | | { |
| 6 | 132 | | if (IsEnabled()) |
| | 133 | | { |
| 0 | 134 | | WriteEvent(23, partitionId ?? string.Empty, identifier ?? string.Empty, eventHubName ?? string.Empty, co |
| | 135 | | } |
| 6 | 136 | | } |
| | 137 | |
|
| | 138 | | /// <summary> |
| | 139 | | /// Indicates that process of updating the checkpoint in the chosen storage service has completed. |
| | 140 | | /// </summary> |
| | 141 | | /// |
| | 142 | | /// <param name="partitionId">The identifier of the Event Hub partition whose processing is taking place.</param |
| | 143 | | /// <param name="identifier">A unique name used to identify the event processor.</param> |
| | 144 | | /// <param name="eventHubName">The name of the Event Hub that the processor is associated with.</param> |
| | 145 | | /// <param name="consumerGroup">The name of the consumer group that the processor is associated with.</param> |
| | 146 | | /// |
| | 147 | | [Event(24, Level = EventLevel.Verbose, Message = "Completed performing a checkpoint update for partition '{0}' b |
| | 148 | | public virtual void UpdateCheckpointComplete(string partitionId, |
| | 149 | | string identifier, |
| | 150 | | string eventHubName, |
| | 151 | | string consumerGroup) |
| | 152 | | { |
| 6 | 153 | | if (IsEnabled()) |
| | 154 | | { |
| 0 | 155 | | WriteEvent(24, partitionId ?? string.Empty, identifier ?? string.Empty, eventHubName ?? string.Empty, co |
| | 156 | | } |
| 6 | 157 | | } |
| | 158 | |
|
| | 159 | | /// <summary> |
| | 160 | | /// Indicates that the process of updating the checkpoint in the chosen storage service has experienced an exc |
| | 161 | | /// </summary> |
| | 162 | | /// |
| | 163 | | /// <param name="partitionId">The identifier of the Event Hub partition whose processing is taking place.</param |
| | 164 | | /// <param name="identifier">A unique name used to identify the event processor.</param> |
| | 165 | | /// <param name="eventHubName">The name of the Event Hub that the processor is associated with.</param> |
| | 166 | | /// <param name="consumerGroup">The name of the consumer group that the processor is associated with.</param> |
| | 167 | | /// <param name="errorMessage">The message for the exception that occurred.</param> |
| | 168 | | /// |
| | 169 | | [Event(25, Level = EventLevel.Error, Message = "An exception occurred while attempting to perform a checkpoint u |
| | 170 | | public virtual void UpdateCheckpointError(string partitionId, |
| | 171 | | string identifier, |
| | 172 | | string eventHubName, |
| | 173 | | string consumerGroup, |
| | 174 | | string errorMessage) |
| | 175 | | { |
| 0 | 176 | | if (IsEnabled()) |
| | 177 | | { |
| 0 | 178 | | WriteEvent(25, partitionId ?? string.Empty, identifier ?? string.Empty, eventHubName ?? string.Empty, co |
| | 179 | | } |
| 0 | 180 | | } |
| | 181 | | } |
| | 182 | | } |