generated from arcus-azure/arcus.github.template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix - include correlation information when tracking exceptions (#133)
* Fix - include correlation information when tracking exceptions * pr-test: add integration test to verify if the unhandled exception includes tracking correlation information * pr-fix:use API key to connect to application insights * pr-sug: assert on operation ID in application insights specific operation ID
- Loading branch information
1 parent
05f1808
commit 1b93c04
Showing
9 changed files
with
310 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Arcus.Messaging.Tests.Integration/Fixture/ApplicationInsightsConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using GuardNet; | ||
|
||
namespace Arcus.Messaging.Tests.Integration.Fixture | ||
{ | ||
/// <summary> | ||
/// Represents an application configuration section related to information regarding Azure Application Insights. | ||
/// </summary> | ||
public class ApplicationInsightsConfig | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ApplicationInsightsConfig"/> class. | ||
/// </summary> | ||
/// <param name="instrumentationKey">The instrumentation key of the Azure Application Insights resource.</param> | ||
/// <param name="applicationId">The application ID that has API access to the Azure Application Insights resource.</param> | ||
/// <param name="apiKey">The application API key that has API access to the Azure Application Insights resource.</param> | ||
/// <exception cref="System.ArgumentException">Thrown when the <paramref name="instrumentationKey"/> or <paramref name="apiKey"/> or <paramref name="apiKey"/> is blank.</exception> | ||
public ApplicationInsightsConfig(string instrumentationKey, string applicationId, string apiKey) | ||
{ | ||
Guard.NotNullOrWhitespace(instrumentationKey, nameof(instrumentationKey), "Requires a non-blank Application Insights instrumentation key"); | ||
Guard.NotNullOrWhitespace(apiKey, nameof(apiKey), "Requires a non-blank Application Insights application application ID"); | ||
Guard.NotNullOrWhitespace(apiKey, nameof(apiKey), "Requires a non-blank Application Insights application API key"); | ||
|
||
InstrumentationKey = instrumentationKey; | ||
ApplicationId = applicationId; | ||
ApiKey = apiKey; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the instrumentation key to connect to the Application Insights resource. | ||
/// </summary> | ||
public string InstrumentationKey { get; } | ||
|
||
/// <summary> | ||
/// Gets the application ID which has API access to the Application Insights resource. | ||
/// </summary> | ||
public string ApplicationId { get; } | ||
|
||
/// <summary> | ||
/// Gets the application API key which has API access to the Application Insights resource. | ||
/// </summary> | ||
public string ApiKey { get; } | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
....Messaging.Tests.Integration/Fixture/ServiceBusQueueTrackCorrelationOnExceptionProgram.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using Arcus.EventGrid.Publishing; | ||
using Arcus.Messaging.Tests.Core.Messages.v1; | ||
using Arcus.Messaging.Tests.Workers.MessageHandlers; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Serilog; | ||
using Serilog.Configuration; | ||
using Serilog.Events; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Arcus.Messaging.Tests.Workers.ServiceBus | ||
{ | ||
public class ServiceBusQueueTrackCorrelationOnExceptionProgram | ||
{ | ||
public static void main(string[] args) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.WriteTo.Console() | ||
.CreateLogger(); | ||
|
||
try | ||
{ | ||
CreateHostBuilder(args) | ||
.Build() | ||
.Run(); | ||
} | ||
catch (Exception exception) | ||
{ | ||
Log.Fatal(exception, "Host terminated unexpectedly"); | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureAppConfiguration(configuration => | ||
{ | ||
configuration.AddCommandLine(args); | ||
configuration.AddEnvironmentVariables(); | ||
}) | ||
.UseSerilog(UpdateLoggerConfiguration) | ||
.ConfigureServices((hostContext, services) => | ||
{ | ||
services.AddServiceBusQueueMessagePump(configuration => configuration["ARCUS_SERVICEBUS_CONNECTIONSTRING"]) | ||
.WithServiceBusMessageHandler<OrdersSabotageAzureServiceBusMessageHandler, Order>(); | ||
|
||
services.AddTcpHealthProbes("ARCUS_HEALTH_PORT", builder => builder.AddCheck("sample", () => HealthCheckResult.Healthy())); | ||
}); | ||
|
||
private static void UpdateLoggerConfiguration( | ||
HostBuilderContext hostContext, | ||
LoggerConfiguration currentLoggerConfiguration) | ||
{ | ||
var instrumentationKey = hostContext.Configuration.GetValue<string>("APPLICATIONINSIGHTS_INSTRUMENTATIONKEY"); | ||
|
||
currentLoggerConfiguration | ||
.MinimumLevel.Debug() | ||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) | ||
.Enrich.FromLogContext() | ||
.Enrich.WithVersion() | ||
.Enrich.WithComponentName("Service Bus Queue Worker") | ||
.WriteTo.Console() | ||
.WriteTo.AzureApplicationInsights(instrumentationKey); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.