generated from arcus-azure/arcus.github.template
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature - add Azure Event Hubs dependency tracking (#98)
* Feature - add Azure Event Hubs dependency tracking * pr-fix: update with correct signature * pr-sug: use 'namespaceName' io 'accountName'
- Loading branch information
1 parent
b09673e
commit e45381d
Showing
4 changed files
with
199 additions
and
0 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
59 changes: 59 additions & 0 deletions
59
...Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsTests.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,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.ApplicationInsights; | ||
using Microsoft.Azure.ApplicationInsights.Models; | ||
using Microsoft.Extensions.Logging; | ||
using Serilog; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using ILogger = Microsoft.Extensions.Logging.ILogger; | ||
|
||
namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights | ||
{ | ||
public class EventHubsTests : ApplicationInsightsSinkTests | ||
{ | ||
public EventHubsTests(ITestOutputHelper outputWriter) : base(outputWriter) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task LogEventHubsDependency_SinksToApplicationInsights_ResultsIEventHubsDependencyTelemetry() | ||
{ | ||
// Arrange | ||
string componentName = BogusGenerator.Commerce.ProductName(); | ||
string eventHubName = BogusGenerator.Commerce.ProductName(); | ||
string namespaceName = BogusGenerator.Finance.AccountName(); | ||
using (ILoggerFactory loggerFactory = CreateLoggerFactory(config => config.Enrich.WithComponentName(componentName))) | ||
{ | ||
ILogger logger = loggerFactory.CreateLogger<ApplicationInsightsSinkTests>(); | ||
|
||
bool isSuccessful = BogusGenerator.PickRandom(true, false); | ||
DateTimeOffset startTime = BogusGenerator.Date.RecentOffset(days: 0); | ||
TimeSpan duration = BogusGenerator.Date.Timespan(); | ||
Dictionary<string, object> telemetryContext = CreateTestTelemetryContext(); | ||
|
||
// Act | ||
logger.LogEventHubsDependency(namespaceName, eventHubName, isSuccessful, startTime, duration, telemetryContext); | ||
} | ||
|
||
// Assert | ||
using (ApplicationInsightsDataClient client = CreateApplicationInsightsClient()) | ||
{ | ||
await RetryAssertUntilTelemetryShouldBeAvailableAsync(async () => | ||
{ | ||
EventsResults<EventsDependencyResult> results = await client.GetDependencyEventsAsync(); | ||
Assert.NotEmpty(results.Value); | ||
Assert.Contains(results.Value, result => | ||
{ | ||
return result.Dependency.Type == "Azure Event Hubs" | ||
&& result.Dependency.Target == eventHubName | ||
&& result.Dependency.Data == namespaceName | ||
&& result.Cloud.RoleName == componentName; | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
} | ||
} |
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