Skip to content

Commit

Permalink
feat: add eventhubs request tracking (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnmoreels authored Sep 9, 2022
1 parent b75dcf1 commit acfaf3e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,25 @@ public async Task RouteMessageAsync(
MessageCorrelationInfo correlationInfo,
CancellationToken cancellationToken)
{
bool isSuccessful = false;
using (var measurement = DurationMeasurement.Start())
{
string messageBody = message.Data.ToString();
await base.RouteMessageAsync(messageBody, messageContext, correlationInfo, cancellationToken);

// TODO: Log EventHubs request.
try
{
string messageBody = message.Data.ToString();
await base.RouteMessageAsync(messageBody, messageContext, correlationInfo, cancellationToken);
isSuccessful = true;
}
finally
{
Logger.LogEventHubsRequest(
messageContext.EventHubsNamespace,
messageContext.ConsumerGroup,
messageContext.EventHubsName,
operationName: null,
isSuccessful,
measurement);
}
}
}

Expand All @@ -127,17 +140,41 @@ public async Task RouteMessageAsync(
/// Thrown when the <paramref name="message"/>, <paramref name="messageContext"/>, or <paramref name="correlationInfo"/> is <c>null</c>.
/// </exception>
/// <exception cref="InvalidOperationException">Thrown when no message handlers or none matching message handlers are found to process the message.</exception>
public override Task RouteMessageAsync<TMessageContext>(
public override async Task RouteMessageAsync<TMessageContext>(
string message,
TMessageContext messageContext,
MessageCorrelationInfo correlationInfo,
CancellationToken cancellationToken)
{
bool isSuccessful = false;
using (var measurement = DurationMeasurement.Start())
{
return base.RouteMessageAsync(message, messageContext, correlationInfo, cancellationToken);

// TODO: Log EventHubs request.
try
{
await base.RouteMessageAsync(message, messageContext, correlationInfo, cancellationToken);
isSuccessful = true;
}
finally
{
string eventHubsNamespace = "<not-available>";
string consumerGroup = "<not-available>";
string eventHubsName = "<not-available>";

if (messageContext is AzureEventHubsMessageContext context)
{
eventHubsNamespace = context.EventHubsNamespace;
consumerGroup = context.ConsumerGroup;
eventHubsName = context.EventHubsName;
}

Logger.LogEventHubsRequest(
eventHubsNamespace,
consumerGroup,
eventHubsName,
operationName: null,
isSuccessful,
measurement);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<PackageReference Include="Serilog" Version="2.9.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Arcus.Observability.Telemetry.Core" Version="[2.5.0,3.0.0)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Arcus.Messaging.Abstractions\Arcus.Messaging.Abstractions.csproj" />
<ProjectReference Include="..\Arcus.Messaging.ServiceBus.Core\Arcus.Messaging.ServiceBus.Core.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Arcus.Observability.Correlation" Version="[2.5.0,3.0.0)" />
<PackageReference Include="Arcus.Observability.Telemetry.Core" Version="[2.5.0,3.0.0)" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Enrichers" Version="[2.5.0,3.0.0)" />
<PackageReference Include="Arcus.Observability.Correlation" Version="[2.6.0,3.0.0)" />
<PackageReference Include="Arcus.Observability.Telemetry.Core" Version="[2.6.0,3.0.0)" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Enrichers" Version="[2.6.0,3.0.0)" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Enrichers" Version="[2.5.0,3.0.0)" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Enrichers" Version="[2.6.0,3.0.0)" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

Expand Down

0 comments on commit acfaf3e

Please sign in to comment.