Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Hubs Client] Event Source and README Updates #12214

Merged
merged 1 commit into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sdk/eventhub/Azure.Messaging.EventHubs.Processor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ The Event Processor client library is a companion to the Azure Event Hubs client

- **Azure Storage account with blob storage:** To persist checkpoints as blobs in Azure Storage, you'll need to have an Azure Storage account with blobs available. If you are not familiar with Azure Storage accounts, you may wish to follow the step-by-step guide for [creating a storage account using the Azure portal](https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json&tabs=azure-portal). There, you can also find detailed instructions for using the Azure CLI, Azure PowerShell, or Azure Resource Manager (ARM) templates to create storage accounts.

- **C# 8.0:** The Azure Event Hubs client library makes use of new features that were introduced in C# 8.0. You can still use the library with older versions of C#, but will need to manage asynchronous enumerable and asynchronous disposable members manually rather than benefiting from the C# 8.0 syntax improvements.

In order to take advantage of the C# 8.0 syntax, you will need the the [.NET Core SDK](https://dotnet.microsoft.com/download) installed and your application will need to either [target .NET Core 3.0](https://docs.microsoft.com/dotnet/standard/frameworks#how-to-specify-target-frameworks) or [specify a language version](https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version#override-a-default) of 8.0 or higher. Visual Studio users wishing to take advantage of the C# 8.0 syntax will need to use Visual Studio 2019 or later. Visual Studio 2019, including the free Community edition, can be downloaded [here](https://visualstudio.microsoft.com).
- **C# 8.0:** The Azure Event Hubs client library makes use of new features that were introduced in C# 8.0. In order to take advantage of the C# 8.0 syntax, it is recommended that you compile using the [.NET Core SDK](https://dotnet.microsoft.com/download) 3.0 or higher with a [language version](https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version#override-a-default) of `latest`. It is also possible to compile with the .NET Core SDK 2.1.x using a language version of `preview`. Visual Studio users wishing to take advantage of the C# 8.0 syntax will need to use Visual Studio 2019 or later. Visual Studio 2019, including the free Community edition, can be downloaded [here](https://visualstudio.microsoft.com).

You can still use the library with previous C# language versions, but will need to manage asynchronous enumerable and asynchronous disposable members manually rather than benefiting from the new syntax. You may still target any framework version supported by your .NET Core SDK, including earlier versions of .NET Core or the .NET framework. For more information, see: [how to specify target frameworks](https://docs.microsoft.com/dotnet/standard/frameworks#how-to-specify-target-frameworks).

**Important Note:** In order to build or run the [examples](#examples) and the [samples](#next-steps) without modification, use of C# 8.0 is mandatory. You can still run the samples if you decide to tweak them for other language versions.

To quickly create the needed resources in Azure and to receive connection strings for them, you can deploy our sample template by clicking:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,25 @@ internal class BlobEventStoreEventSource : EventSource
/// use for logging.
/// </summary>
///
public static BlobEventStoreEventSource Log { get; } = new BlobEventStoreEventSource();
public static BlobEventStoreEventSource Log { get; } = new BlobEventStoreEventSource(EventSourceName);

/// <summary>
/// Prevents an instance of the <see cref="BlobEventStoreEventSource"/> class from being created
/// outside the scope of this library. Exposed for testing purposes only.
/// </summary>
///
internal BlobEventStoreEventSource() : base(EventSourceName, EventSourceSettings.Default, AzureEventSourceListener.TraitName, AzureEventSourceListener.TraitValue)
protected BlobEventStoreEventSource()
{
}

/// <summary>
/// Prevents an instance of the <see cref="BlobEventStoreEventSource"/> class from being created
/// outside the scope of this library. Exposed for testing purposes only.
/// </summary>
///
/// <param name="eventSourceName">The name to assign to the event source.</param>
///
private BlobEventStoreEventSource(string eventSourceName) : base(eventSourceName, EventSourceSettings.Default, AzureEventSourceListener.TraitName, AzureEventSourceListener.TraitValue)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,25 @@ internal class EventProcessorClientEventSource : EventSource
/// use for logging.
/// </summary>
///
public static EventProcessorClientEventSource Log { get; } = new EventProcessorClientEventSource();
public static EventProcessorClientEventSource Log { get; } = new EventProcessorClientEventSource(EventSourceName);

/// <summary>
/// Prevents an instance of the <see cref="EventProcessorClientEventSource"/> class from being created
/// outside the scope of this library. Exposed for testing purposes only.
/// </summary>
///
internal EventProcessorClientEventSource() : base(EventSourceName, EventSourceSettings.Default, AzureEventSourceListener.TraitName, AzureEventSourceListener.TraitValue)
protected EventProcessorClientEventSource() : base(EventSourceName, EventSourceSettings.Default, AzureEventSourceListener.TraitName, AzureEventSourceListener.TraitValue)
{
}

/// <summary>
/// Prevents an instance of the <see cref="EventProcessorClientEventSource"/> class from being created
/// outside the scope of this library. Exposed for testing purposes only.
/// </summary>
///
/// <param name="eventSourceName">The name to assign the event source.</param>
///
private EventProcessorClientEventSource(string eventSourceName) : base(eventSourceName, EventSourceSettings.Default, AzureEventSourceListener.TraitName, AzureEventSourceListener.TraitValue)
{
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/eventhub/Azure.Messaging.EventHubs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ The Azure Event Hubs client library allows for publishing and consuming of Azure

- **Event Hubs namespace with an Event Hub:** To interact with Azure Event Hubs, you'll also need to have a namespace and Event Hub available. If you are not familiar with creating Azure resources, you may wish to follow the step-by-step guide for [creating an Event Hub using the Azure portal](https://docs.microsoft.com/azure/event-hubs/event-hubs-create). There, you can also find detailed instructions for using the Azure CLI, Azure PowerShell, or Azure Resource Manager (ARM) templates to create an Event Hub.

- **C# 8.0:** The Azure Event Hubs client library makes use of new features that were introduced in C# 8.0. You can still use the library with older versions of C#, but will need to manage asynchronous enumerable and asynchronous disposable members manually rather than benefiting from the C# 8.0 syntax improvements.

In order to take advantage of the C# 8.0 syntax, you will need the the [.NET Core SDK](https://dotnet.microsoft.com/download) installed and your application will need to either [target .NET Core 3.0](https://docs.microsoft.com/dotnet/standard/frameworks#how-to-specify-target-frameworks) or [specify a language version](https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version#override-a-default) of 8.0 or higher. Visual Studio users wishing to take advantage of the C# 8.0 syntax will need to use Visual Studio 2019 or later. Visual Studio 2019, including the free Community edition, can be downloaded [here](https://visualstudio.microsoft.com).
- **C# 8.0:** The Azure Event Hubs client library makes use of new features that were introduced in C# 8.0. In order to take advantage of the C# 8.0 syntax, it is recommended that you compile using the [.NET Core SDK](https://dotnet.microsoft.com/download) 3.0 or higher with a [language version](https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version#override-a-default) of `latest`. It is also possible to compile with the .NET Core SDK 2.1.x using a language version of `preview`. Visual Studio users wishing to take advantage of the C# 8.0 syntax will need to use Visual Studio 2019 or later. Visual Studio 2019, including the free Community edition, can be downloaded [here](https://visualstudio.microsoft.com).

You can still use the library with previous C# language versions, but will need to manage asynchronous enumerable and asynchronous disposable members manually rather than benefiting from the new syntax. You may still target any framework version supported by your .NET Core SDK, including earlier versions of .NET Core or the .NET framework. For more information, see: [how to specify target frameworks](https://docs.microsoft.com/dotnet/standard/frameworks#how-to-specify-target-frameworks).

**Important Note:** In order to build or run the [examples](#examples) and the [samples](#next-steps) without modification, use of C# 8.0 is mandatory. You can still run the samples if you decide to tweak them for other language versions.

To quickly create the needed Event Hubs resources in Azure and to receive a connection string for them, you can deploy our sample template by clicking:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public override async Task CloseAsync(CancellationToken cancellationToken)
_closed = true;

var clientId = GetHashCode().ToString(CultureInfo.InvariantCulture);
var clientType = GetType();
var clientType = GetType().Name;

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public override async Task CloseAsync(CancellationToken cancellationToken)
_closed = true;

var clientId = GetHashCode().ToString(CultureInfo.InvariantCulture);
var clientType = GetType();
var clientType = GetType().Name;

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public override async Task CloseAsync(CancellationToken cancellationToken)
_closed = true;

var clientId = GetHashCode().ToString(CultureInfo.InvariantCulture);
var clientType = GetType();
var clientType = GetType().Name;

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ public virtual async Task CloseAsync(CancellationToken cancellationToken = defau
IsClosed = true;

var clientHash = GetHashCode().ToString(CultureInfo.InvariantCulture);
EventHubsEventSource.Log.ClientCloseStart(typeof(EventHubConsumerClient), EventHubName, clientHash);
EventHubsEventSource.Log.ClientCloseStart(nameof(EventHubConsumerClient), EventHubName, clientHash);

// Attempt to close the active transport consumers. In the event that an exception is encountered,
// it should not impact the attempt to close the connection, assuming ownership.
Expand All @@ -630,7 +630,7 @@ public virtual async Task CloseAsync(CancellationToken cancellationToken = defau
}
catch (Exception ex)
{
EventHubsEventSource.Log.ClientCloseError(typeof(EventHubConsumerClient), EventHubName, clientHash, ex.Message);
EventHubsEventSource.Log.ClientCloseError(nameof(EventHubConsumerClient), EventHubName, clientHash, ex.Message);
transportConsumerException = ex;
}

Expand All @@ -646,13 +646,13 @@ public virtual async Task CloseAsync(CancellationToken cancellationToken = defau
}
catch (Exception ex)
{
EventHubsEventSource.Log.ClientCloseError(typeof(EventHubConsumerClient), EventHubName, clientHash, ex.Message);
EventHubsEventSource.Log.ClientCloseError(nameof(EventHubConsumerClient), EventHubName, clientHash, ex.Message);
transportConsumerException = null;
throw;
}
finally
{
EventHubsEventSource.Log.ClientCloseComplete(typeof(EventHubConsumerClient), EventHubName, clientHash);
EventHubsEventSource.Log.ClientCloseComplete(nameof(EventHubConsumerClient), EventHubName, clientHash);
}

// If there was an active exception pending from closing the individual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,25 @@ internal class EventHubsEventSource : EventSource
/// use for logging.
/// </summary>
///
public static EventHubsEventSource Log { get; } = new EventHubsEventSource();
public static EventHubsEventSource Log { get; } = new EventHubsEventSource(EventSourceName);

/// <summary>
/// Prevents an instance of the <see cref="EventHubsEventSource"/> class from being created
/// outside the scope of the <see cref="Log" /> instance.
/// </summary>
///
protected EventHubsEventSource() : base(EventSourceName, EventSourceSettings.Default, AzureEventSourceListener.TraitName, AzureEventSourceListener.TraitValue)
protected EventHubsEventSource()
{
}

/// <summary>
/// Prevents an instance of the <see cref="EventHubsEventSource"/> class from being created
/// outside the scope of the <see cref="Log" /> instance.
/// </summary>
///
/// <param name="eventSourceName">The name to assign to the event source.</param>
///
private EventHubsEventSource(string eventSourceName) : base(eventSourceName, EventSourceSettings.Default, AzureEventSourceListener.TraitName, AzureEventSourceListener.TraitValue)
{
}

Expand Down Expand Up @@ -201,18 +212,18 @@ public virtual void EventReceiveError(string eventHubName,
/// <see cref="EventHubProducerClient" />, <see cref="EventHubConsumerClient" />, or <c>EventProcessorClient</c>.
/// </summary>
///
/// <param name="clientType">The type of client being closed.</param>
/// <param name="clientTypeName">The name of the type of client being closed.</param>
/// <param name="eventHubName">The name of the Event Hub associated with the client.</param>
/// <param name="clientId">An identifier to associate with the client.</param>
///
[Event(9, Level = EventLevel.Verbose, Message = "Closing an {0} (EventHub '{1}'; Identifier '{2}').")]
public virtual void ClientCloseStart(Type clientType,
public virtual void ClientCloseStart(string clientTypeName,
string eventHubName,
string clientId)
{
if (IsEnabled())
{
WriteEvent(9, clientType.Name, eventHubName ?? string.Empty, clientId ?? string.Empty);
WriteEvent(9, clientTypeName ?? string.Empty, eventHubName ?? string.Empty, clientId ?? string.Empty);
}
}

Expand All @@ -221,18 +232,18 @@ public virtual void ClientCloseStart(Type clientType,
/// <see cref="EventHubProducerClient" />, <see cref="EventHubConsumerClient" />, or <c>EventProcessorClient</c>.
/// </summary>
///
/// <param name="clientType">The type of client being closed.</param>
/// <param name="clientTypeName">The name of the type of client being closed.</param>
/// <param name="eventHubName">The name of the Event Hub associated with the client.</param>
/// <param name="clientId">An identifier to associate with the client.</param>
///
[Event(10, Level = EventLevel.Verbose, Message = "An {0} has been closed (EventHub '{1}'; Identifier '{2}').")]
public virtual void ClientCloseComplete(Type clientType,
public virtual void ClientCloseComplete(string clientTypeName,
string eventHubName,
string clientId)
{
if (IsEnabled())
{
WriteEvent(10, clientType.Name, eventHubName ?? string.Empty, clientId ?? string.Empty);
WriteEvent(10, clientTypeName ?? string.Empty, eventHubName ?? string.Empty, clientId ?? string.Empty);
}
}

Expand All @@ -241,20 +252,20 @@ public virtual void ClientCloseComplete(Type clientType,
/// <see cref="EventHubProducerClient" />, <see cref="EventHubConsumerClient" />, or <c>EventProcessorClient</c>.
/// </summary>
///
/// <param name="clientType">The type of client being closed.</param>
/// <param name="clientTypeName">The name of the type of client being closed.</param>
/// <param name="eventHubName">The name of the Event Hub associated with the client.</param>
/// <param name="clientId">An identifier to associate with the client.</param>
/// <param name="errorMessage">The message for the exception that occurred.</param>
///
[Event(11, Level = EventLevel.Error, Message = "An exception occurred while closing an {0} (EventHub '{1}'; Identifier '{2}'). Error Message: '{3}'")]
public virtual void ClientCloseError(Type clientType,
public virtual void ClientCloseError(string clientTypeName,
string eventHubName,
string clientId,
string errorMessage)
{
if (IsEnabled())
{
WriteEvent(11, clientType.Name, eventHubName ?? string.Empty, clientId ?? string.Empty, errorMessage ?? string.Empty);
WriteEvent(11, clientTypeName ?? string.Empty, eventHubName ?? string.Empty, clientId ?? string.Empty, errorMessage ?? string.Empty);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,20 @@ protected EventHubConnection()
public virtual async Task CloseAsync(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested<TaskCanceledException>();
EventHubsEventSource.Log.ClientCloseStart(typeof(EventHubConnection), EventHubName, FullyQualifiedNamespace);
EventHubsEventSource.Log.ClientCloseStart(nameof(EventHubConnection), EventHubName, FullyQualifiedNamespace);

try
{
await InnerClient.CloseAsync(cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
EventHubsEventSource.Log.ClientCloseError(typeof(EventHubConnection), EventHubName, FullyQualifiedNamespace, ex.Message);
EventHubsEventSource.Log.ClientCloseError(nameof(EventHubConnection), EventHubName, FullyQualifiedNamespace, ex.Message);
throw;
}
finally
{
EventHubsEventSource.Log.ClientCloseComplete(typeof(EventHubConnection), EventHubName, FullyQualifiedNamespace);
EventHubsEventSource.Log.ClientCloseComplete(nameof(EventHubConnection), EventHubName, FullyQualifiedNamespace);
}
}

Expand Down
Loading