Skip to content

Commit

Permalink
Update Azure.Core READMES (Azure#9871)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym authored Feb 10, 2020
1 parent 0647c15 commit 31bb08e
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 57 deletions.
1 change: 0 additions & 1 deletion eng/.docsettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ known_content_issues:
- ['sdk/alertsmanagement/Microsoft.Azure.Management.AlertsManagement/README.md','#5499']
- ['sdk/appconfiguration/README.md','azure-sdk-tools/issues/42']
- ['sdk/appconfiguration/Azure.Data.AppConfiguration/tests/Readme.md','#5499']
- ['sdk/core/Azure.Core/README.md','#5499']
- ['sdk/storage/README.md','azure-sdk-tools/issues/42']
- ['sdk/cognitiveservices/Language.TextAnalytics/src/README.md','#5499']
- ['sdk/cognitiveservices/Personalizer/src/README.md','#5499']
Expand Down
53 changes: 40 additions & 13 deletions sdk/core/Azure.Core/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Azure.Core shared library for .NET
# Azure Core shared client library for .NET

Azure.Core provides shared primitives, abstractions, and helpers for modern .NET Azure SDK client libraries.
These libraries follow the [Azure SDK Design Guidelines for .NET](https://azuresdkspecs.z5.web.core.windows.net/DotNetSpec.html)
Expand All @@ -8,24 +8,29 @@ A more complete list of client libraries using Azure.Core can be found [here](ht
Azure.Core allows client libraries to expose common functionality in a consistent fashion,
so that once you learn how to use these APIs in one client library, you will know how to use them in other client libraries.

The main shared concepts of Azure.Core (and so Azure SDK libraries using Azure.Core) include:

- Configuring service clients, e.g. configuring retries, logging.
- Accessing HTTP response details.
- Calling long-running operations (LROs).
- Paging and asynchronous streams (```AsyncPageable<T>```)
- Exceptions for reporting errors from service requests in a consistent fashion.
- Abstractions for representing Azure SDK credentials.
[Source code][source] | [Package (NuGet)][package] | [API reference documentation][docs]

Below, you will find sections explaining these shared concepts in more detail.
## Getting started

## Installing
Typically, you will not need to install Azure.Core;
it will be installed for you when you install one of the client libraries using it.
In case you want to install it explicitly (to implement your own client library, for example),
you can find the NuGet package [here](https://www.nuget.org/packages/Azure.Core).

## Usage Scenarios and Samples
## Key concepts

The main shared concepts of Azure.Core (and so Azure SDK libraries using Azure.Core) include:

- Configuring service clients, e.g. configuring retries, logging (`ClientOptions`).
- Accessing HTTP response details (`Response`, `Response<T>`).
- Calling long-running operations (`Operation<T>`).
- Paging and asynchronous streams (```AsyncPageable<T>```).
- Exceptions for reporting errors from service requests in a consistent fashion. (`RequestFailedException`).
- Abstractions for representing Azure SDK credentials. (`TokenCredentials`).

Below, you will find sections explaining these shared concepts in more detail.

## Examples

**NOTE:** Samples in this file apply only to packages that follow [Azure SDK Design Guidelines](https://azure.github.io/azure-sdk/dotnet_introduction.html). Names of such packages usually start with `Azure`.

Expand Down Expand Up @@ -105,10 +110,12 @@ To create an Azure SDK log listener that outputs messages to console use `AzureE
using AzureEventSourceListener listener = AzureEventSourceListener.CreateConsoleLogger();
```

More on logging in [configuration samples](samples/Configuration.md)
More on logging in [diagnostics samples](samples/Diagnostics.md)

### Reporting Errors ```RequestFailedException```

When a service call fails `Azure.RequestFailedException` would get thrown. The exception type provides a Status property with an HTTP status code an an ErrorCode property with a service-specific error code.

```C# Snippet:RequestFailedException
try
{
Expand Down Expand Up @@ -196,4 +203,24 @@ KeyVaultSecret secret = client.GetSecret("Name");

More on mocking in [mocking samples](samples/Mocking.md)

## Troubleshooting

Three main ways of troubleshooting failures are [inspecting exceptions](samples/Response.md#Enabling exceptions), enabling [logging](samples/Diagnostics.md#Logging), and [distributed tracing](samples/Diagnostics.md#Distributed-tracing)

## Next steps

Explore and install [available Azure SDK libraries](https://azure.github.io/azure-sdk/releases/latest/dotnet.html).

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Fcore%2FAzure.Core%2FREADME.png)

[source]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/core/Azure.Core/src
[package]: https://www.nuget.org/packages/Azure.Core/
[docs]: https://docs.microsoft.com/en-us/dotnet/api/overview/azure/core/client
42 changes: 0 additions & 42 deletions sdk/core/Azure.Core/samples/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,3 @@ SecretClientOptions options = new SecretClientOptions
Transport = new HttpClientTransport(client)
};
```

## Enabling content logging

By default only URI and headers are logged to enable content logging set the `Diagnostics.IsLoggingContentEnabled` client option:

```C# Snippet:LoggingContent
SecretClientOptions options = new SecretClientOptions()
{
Diagnostics =
{
IsLoggingContentEnabled = true
}
};
```

## Logging redacted headers and query parameters

Some sensetive headers and query parameters are not logged by default and are displayed as `REDACTED`, to include them in logs use the `Diagnostics.LoggedHeaderNames` and `Diagnostics.LoggedQueryParameters` client options.

```C# Snippet:LoggingRedactedHeader
SecretClientOptions options = new SecretClientOptions()
{
Diagnostics =
{
LoggedHeaderNames = { "x-ms-request-id" },
LoggedQueryParameters = { "api-version" }
}
};
```

You can also disable redaction completely by adding a `"*"` to collections mentioned above.

```C# Snippet:LoggingRedactedHeaderAll
SecretClientOptions options = new SecretClientOptions()
{
Diagnostics =
{
LoggedHeaderNames = { "*" },
LoggedQueryParameters = { "*" }
}
};
```
90 changes: 90 additions & 0 deletions sdk/core/Azure.Core/samples/Diagnostics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Azure SDK diagnostics

**NOTE:** Samples in this file apply only to packages that follow [Azure SDK Design Guidelines](https://azure.github.io/azure-sdk/dotnet_introduction.html). Names of such packages usually start with `Azure`.

## Logging

Azure SDKs produce various log messages that include information about:
1. Requests and reponses
2. Authentication attempts
3. Retries

The simplest way to see the logs is to enable the console logging.

```C# Snippet:ConsoleLogging
// Setup a listener to monitor logged events.
using AzureEventSourceListener listener = AzureEventSourceListener.CreateConsoleLogger();
```

### Enabling content logging

By default only URI and headers are logged to enable content logging set the `Diagnostics.IsLoggingContentEnabled` client option:

```C# Snippet:LoggingContent
SecretClientOptions options = new SecretClientOptions()
{
Diagnostics =
{
IsLoggingContentEnabled = true
}
};
```

### Logging redacted headers and query parameters

Some sensitive headers and query parameters are not logged by default and are displayed as "REDACTED", to include them in logs use the `Diagnostics.LoggedHeaderNames` and `Diagnostics.LoggedQueryParameters` client options.

```C# Snippet:LoggingRedactedHeader
SecretClientOptions options = new SecretClientOptions()
{
Diagnostics =
{
LoggedHeaderNames = { "x-ms-request-id" },
LoggedQueryParameters = { "api-version" }
}
};
```

You can also disable redaction completely by adding a `"*"` to collections mentioned above.

```C# Snippet:LoggingRedactedHeaderAll
SecretClientOptions options = new SecretClientOptions()
{
Diagnostics =
{
LoggedHeaderNames = { "*" },
LoggedQueryParameters = { "*" }
}
};
```

### ASP.NET Core applications

If your are using Azure SDK libraries in ASP.NET Core application consider using the `Microsoft.Extensions.Azure` package that provides integration with `Microsoft.Extensions.Logging` library. See [Microsoft.Extensions.Azure readme](../../Microsoft.Extensions.Azure/README.md) for more details.


### Custom logging callback

The `AzureEventSourceListener` class can also be used with a custom callback that allows log messages to be written to destination of your choice.

```C# Snippet:LoggingCallback
using AzureEventSourceListener listener = new AzureEventSourceListener(
(e, message) => Console.WriteLine($"{DateTime.Now} {message}"),
level: EventLevel.Verbose);
```

## Distributed tracing

Azure SDKs are instrumented for distributed tracing using ApplicationsInsights or OpenTelemetry.

### ApplicationInsights with Azure Monitor

Application Insights, a feature of Azure Monitor, is an extensible Application Performance Management (APM) service for developers and DevOps professionals. Use it to monitor your live applications. It will automatically detect performance anomalies, and includes powerful analytics tools to help you diagnose issues and to understand what users actually do with your app

If you application already uses ApplicationInsights, automatic collection of Azure SDK traces is supported since version `2.12.0`.

To setup ApplicationInsights tracking for your application follow the [Start Monitoring Application](https://docs.microsoft.com/en-us/azure/azure-monitor/learn/dotnetcore-quick-start) guide.

### OpenTelemetry with Azure Monitor, Zipkin and others

Follow the [OpenTelemetry configuration guide](https://github.com/open-telemetry/opentelemetry-dotnet#configuration-with-microsoftextensionsdependencyinjection) to configure collecting distribute tracing event collection using the OpenTelemetry library.
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/samples/Response.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ foreach (SecretProperties secretProperties in response)

## Handling exceptions

When request fails the `RequestFailedException` is thrown by client methods. The exception exposes HTTP status code as the `Status` property and service specific `ErrorCode`.
When a service call fails `Azure.RequestFailedException` would get thrown. The exception type provides a Status property with an HTTP status code an an ErrorCode property with a service-specific error code.

```C# Snippet:RequestFailedException
try
Expand Down
11 changes: 11 additions & 0 deletions sdk/core/Azure.Core/tests/samples/LoggingSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics.Tracing;
using System.Net.Http;
using Azure.Core.Diagnostics;
using Azure.Core.Pipeline;
Expand All @@ -21,6 +22,16 @@ public void Logging()
#endregion
}

[Test]
public void LoggingCallback()
{
#region Snippet:LoggingCallback
using AzureEventSourceListener listener = new AzureEventSourceListener(
(e, message) => Console.WriteLine($"{DateTime.Now} {message}"),
level: EventLevel.Verbose);
#endregion
}

[Test]
public static void LoggingContent()
{
Expand Down

0 comments on commit 31bb08e

Please sign in to comment.