Skip to content

Commit

Permalink
Add blurb about dist tracing (#17059)
Browse files Browse the repository at this point in the history
- Addresses #16238
- Update LineCounter sample app to show usage of Event Grid
- Update LineCounter README to include a screenshot of Azure Monitor
- Update Distributed Tracing section in Diagnostics readme to link to LineCounter.
- Also add in DI extension methods.
  • Loading branch information
JoshLove-msft authored Nov 26, 2020
1 parent 2e4089b commit e4c4e7f
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 5 deletions.
11 changes: 9 additions & 2 deletions samples/linecounter/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Azure.Messaging.EventGrid;
using Azure.Messaging.EventHubs;
using Azure.Messaging.EventHubs.Producer;
using Azure.Storage.Blobs;
Expand All @@ -18,12 +19,18 @@ public class HomeController : Controller
private readonly ILogger<HomeController> _logger;
private readonly BlobContainerClient _blobContainerClient;
private readonly EventHubProducerClient _uploadsProducer;
private readonly EventGridPublisherClient _publisherClient;

public HomeController(ILogger<HomeController> logger, BlobServiceClient blobServiceClient, IAzureClientFactory<EventHubProducerClient> clientFactory)
public HomeController(
ILogger<HomeController> logger,
BlobServiceClient blobServiceClient,
IAzureClientFactory<EventHubProducerClient> clientFactory,
EventGridPublisherClient publisherClient)
{
_logger = logger;
_blobContainerClient = blobServiceClient.GetBlobContainerClient("uploads");
_uploadsProducer = clientFactory.CreateClient("Uploads");
_publisherClient = publisherClient;
}

public IActionResult Index()
Expand Down Expand Up @@ -60,7 +67,7 @@ public async Task<string> Status(string name)
{
var properties = await _blobContainerClient.GetBlobClient(name).GetPropertiesAsync();
properties.Value.Metadata.TryGetValue("whitespacecount", out var count);

await _publisherClient.SendEventsAsync(new CloudEvent[] { new CloudEvent("https://www.contoso.com/LineCounter", "LineCounter.Status.Viewed", name) });
return count ?? "-1";
}
}
Expand Down
3 changes: 3 additions & 0 deletions samples/linecounter/LineCounter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
<ItemGroup>
<Folder Include="Connected Services\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\sdk\eventgrid\Azure.Messaging.EventGrid\src\Azure.Messaging.EventGrid.csproj" />
</ItemGroup>
</Project>
16 changes: 13 additions & 3 deletions samples/linecounter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ products:
- azure
- azure-storage
- azure-event-hubs
- azure-event-grid
urlFragment: line-counter
name: LineCounter
description: Sample that illustrates using Storage and Event Hubs clients along with ASP.NET Core integration, distributed tracing and hosted services.
description: Sample that illustrates using Storage, Event Hubs, and Event Grid clients along with ASP.NET Core integration, distributed tracing and hosted services.
---

# LineCounter
This is a sample app that illustrates using Storage and Event Hubs clients along with ASP.NET Core integration, distributed tracing and hosted services.
This is a sample app that illustrates using Storage, Event Hubs, and Event Grid clients along with ASP.NET Core integration, distributed tracing and hosted services.
It allows users to upload a file to a blob, which triggers an Event Hubs event containing the file name.
The Event Hubs Processor receives the event, and then the app downloads the blob and counts the number of lines in the file.
The Event Hubs Processor receives the event, and then the app downloads the blob and counts the number of lines in the file. The app displays a link to a page containing the line count. When the link is clicked, a CloudEvent containing the name of the file is published using Event Grid.

# Configuration

Expand All @@ -32,6 +33,11 @@ To run the sample set the following configuration properties using manage user s
"Results": {
"connectionString": "...",
"eventHubName": "..."
},
"Notification": {
"endpoint": "...",
"credential": {
"key": "..."
}
}
```
Expand All @@ -45,3 +51,7 @@ To light up App Insights, add the InstrumentationKey key and value to the Applic
}
}
```

# Azure Monitor
You can view an end-to-end transaction in the portal by going to your App. Click on the Search icon, and then click See all data.
After selecting a grouped result, you will be able to see a timeline of the grouped requests: ![Monitor](assets/monitor.PNG).
1 change: 1 addition & 0 deletions samples/linecounter/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void ConfigureServices(IServiceCollection services)
builder.AddEventHubProducerClient(Configuration.GetSection("Uploads")).WithName("Uploads");

builder.AddEventHubProducerClient(Configuration.GetSection("Results")).WithName("Results");
builder.AddEventGridPublisherClient(Configuration.GetSection("Notification"));
});
services.AddApplicationInsightsTelemetry();
}
Expand Down
Binary file added samples/linecounter/assets/monitor.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions sdk/core/Azure.Core/samples/Diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ To setup ApplicationInsights tracking for your application follow the [Start Mon

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.

### Sample
To see an example of distributed tracing in action, take a look at our [sample app](https://github.com/Azure/azure-sdk-for-net/blob/master/samples/linecounter/README.md) that combines several Azure SDKs.

## Setting x-ms-client-request-id value sent with requests

By default x-ms-client-request-id header gets a unique value per client method call. If you would like to use a specific value for a set of requests use the `HttpPipeline.CreateClientRequestIdScope` method.
Expand Down
3 changes: 3 additions & 0 deletions sdk/eventgrid/Azure.Messaging.EventGrid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ foreach (EventGridEvent egEvent in egEvents)
### Setting up console logging
You can also easily [enable console logging](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagnostics.md#logging) if you want to dig deeper into the requests you're making against the service.

### Distributed Tracing
The Event Grid library supports distributing tracing out of the box. In order to adhere to the CloudEvents specification's [guidance](https://github.com/cloudevents/spec/blob/master/extensions/distributed-tracing.md) on distributing tracing, the library will set the `traceparent` and `tracestate` on the [ExtensionAttributes](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/eventgrid/Azure.Messaging.EventGrid/src/Customization/CloudEvent.cs#L126) of a `CloudEvent` when distributed tracing is enabled. To learn more about how to enable distributed tracing in your application, take a look at the Azure SDK [distributed tracing documentation](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagnostics.md#Distributed-tracing).

## Next steps

View more https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/eventgrid/Azure.Messaging.EventGrid/samples here for common usages of the Event Grid client library: [Event Grid Samples](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/eventgrid/Azure.Messaging.EventGrid/samples).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1341,3 +1341,12 @@ internal WebSlotSwapWithPreviewStartedEventData() { }
public string Verb { get { throw null; } }
}
}
namespace Microsoft.Extensions.Azure
{
public static partial class EventGridPublisherClientBuilderExtensions
{
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Messaging.EventGrid.EventGridPublisherClient, Azure.Messaging.EventGrid.EventGridPublisherClientOptions> AddEventGridPublisherClient<TBuilder>(this TBuilder builder, System.Uri endpoint, Azure.AzureKeyCredential credential) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilder { throw null; }
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Messaging.EventGrid.EventGridPublisherClient, Azure.Messaging.EventGrid.EventGridPublisherClientOptions> AddEventGridPublisherClient<TBuilder>(this TBuilder builder, System.Uri endpoint, Azure.Messaging.EventGrid.EventGridSharedAccessSignatureCredential credential) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilder { throw null; }
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Messaging.EventGrid.EventGridPublisherClient, Azure.Messaging.EventGrid.EventGridPublisherClientOptions> AddEventGridPublisherClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilderWithConfiguration<TConfiguration> { throw null; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure;
using Azure.Core.Extensions;
using Azure.Messaging.EventGrid;

namespace Microsoft.Extensions.Azure
{
/// <summary>
/// The set of extensions to add the <see cref="EventGridPublisherClient"/> type to the clients builder.
/// </summary>
public static class EventGridPublisherClientBuilderExtensions
{
/// <summary>
/// Registers a <see cref="EventGridPublisherClient "/> instance with the provided <see cref="Uri"/> and <see cref="AzureKeyCredential"/>./>.
/// </summary>
public static IAzureClientBuilder<EventGridPublisherClient, EventGridPublisherClientOptions> AddEventGridPublisherClient<TBuilder>(
this TBuilder builder,
Uri endpoint,
AzureKeyCredential credential)
where TBuilder : IAzureClientFactoryBuilder =>
builder.RegisterClientFactory<EventGridPublisherClient, EventGridPublisherClientOptions>(options => new EventGridPublisherClient(endpoint, credential, options));

/// <summary>
/// Registers a <see cref="EventGridPublisherClient "/> instance with the provided <see cref="Uri"/> and <see cref="EventGridSharedAccessSignatureCredential"/>./>.
/// </summary>
public static IAzureClientBuilder<EventGridPublisherClient, EventGridPublisherClientOptions> AddEventGridPublisherClient<TBuilder>(
this TBuilder builder,
Uri endpoint,
EventGridSharedAccessSignatureCredential credential)
where TBuilder : IAzureClientFactoryBuilder =>
builder.RegisterClientFactory<EventGridPublisherClient, EventGridPublisherClientOptions>(options => new EventGridPublisherClient(endpoint, credential, options));

/// <summary>
/// Registers a <see cref="EventGridPublisherClient"/> instance with connection options loaded from the provided <paramref name="configuration"/> instance.
/// </summary>
public static IAzureClientBuilder<EventGridPublisherClient, EventGridPublisherClientOptions> AddEventGridPublisherClient<TBuilder, TConfiguration>(
this TBuilder builder,
TConfiguration configuration)
where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration> =>
builder.RegisterClientFactory<EventGridPublisherClient, EventGridPublisherClientOptions>(configuration);
}
}

0 comments on commit e4c4e7f

Please sign in to comment.