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

Adding ExceptionSummarization readme #4610

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.Extensions.Diagnostics.ExceptionSummarization;
/// An exception summary represents a low-cardinality version of an exception's information, suitable for such
/// cases.
///
/// The <see cref="ExceptionSummary.Description"/> property never include sensitive information.
/// The <see cref="ExceptionSummary.Description"/> property never includes sensitive information.
/// But the <see cref="ExceptionSummary.AdditionalDetails"/> property might contain sensitive information and should thus not be used in telemetry.
/// </remarks>
public readonly struct ExceptionSummary : IEquatable<ExceptionSummary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
README
# Microsoft.Extensions.Diagnostics.ExceptionSummarization

This provides the ability to extract essential information from well-known exception types and return a single string that can be used to create low-cardinality diagnostic messages for use in telemetry.

## Install the package

From the command-line:

```dotnetcli
dotnet add package Microsoft.Extensions.Diagnostics.ExceptionSummarization
```

Or directly in the C# project file:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be VB or F#

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have this pre-defined for all readmes. Let's do a separate global change once we agree on this, but keep it consistent for now a least.


```xml
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Diagnostics.ExceptionSummarization" Version="[CURRENTVERSION]" />
</ItemGroup>
```

## Usage Example

### Registering Services

The services can be registered using the following methods:

```csharp
public static IServiceCollection AddExceptionSummarizer(this IServiceCollection services);
public static IServiceCollection AddExceptionSummarizer(this IServiceCollection services, Action<IExceptionSummarizationBuilder> configure);
```

For example:

```csharp
services.AddExceptionSummarizer();
```

The package comes with a predefined `IExceptionSummaryProvider` implementation which will work with common
sebastienros marked this conversation as resolved.
Show resolved Hide resolved
exceptions that might be sent during a web request. Here is how to register it:

```csharp
using Microsoft.Extensions.Diagnostics.ExceptionSummarization;

services.AddExceptionSummarizer(b => b.AddHttpProvider());
```

### Consuming Services

Once registered, the `IExceptionSummarizer` class can be resolved. For example:

```csharp
using Microsoft.Extensions.Diagnostics.ExceptionSummarization;

var summarizer = services.BuildServiceProvider().GetRequiredService<IExceptionSummarizer>();

try
{
throw new SocketException((int)SocketError.NetworkDown);
}
catch (Exception e)
{
ExceptionSummary summary = summarizer.Summarize(e);

Console.WriteLine(summary.Description); // writes NetworkDown
}
```

The `ExceptionSummary.Description` property never includes sensitive information and can be safely used.
As opposed to `ExceptionSummary.AdditionalDetails` which can contain sensitive information that should not be stored and can only be used for debugging purpose.

## Custom exception summarization

Custom implementations of the `IExceptionSummaryProvider` interface can be used to provide a summary for any type of exception.

## Feedback & Contributing

We welcome feedback and contributions in [our GitHub repo](https://github.com/dotnet/extensions).